Java Code Examples for org.apache.ws.commons.schema.XmlSchemaElement#setNillable()

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaElement#setNillable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExceptionVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private XmlSchemaElement createElementType(AST memberNode, XmlSchemaType stype,
                                           Scope fqName) {
    // xmlschema:member
    XmlSchemaElement member = new XmlSchemaElement(schema, false);
    String memberName = memberNode.toString();
    member.setName(memberName);
    if (stype != null) {
        member.setSchemaType(stype);
        member.setSchemaTypeName(stype.getQName());
        if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            member.setNillable(true);
        }
    } else {
        wsdlVisitor.getDeferredActions().
            add(fqName, new ExceptionDeferredAction(member));
    }
    return member;
}
 
Example 2
Source File: StructVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private XmlSchemaElement createXmlSchemaElement(AST memberNode,
                                                XmlSchemaType schemaType,
                                                Scope fqName) {
    // xmlschema:member
    XmlSchemaElement member = new XmlSchemaElement(schema, false);
    String memberName = memberNode.toString();
    member.setName(memberName);
    member.setSchemaType(schemaType);
    if (schemaType != null) {
        member.setSchemaTypeName(schemaType.getQName());
        if (schemaType.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            member.setNillable(true);
        }
    } else {
        wsdlVisitor.getDeferredActions().
            add(fqName, new StructDeferredAction(member));
    }
    return member;
}
 
Example 3
Source File: OperationVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private XmlSchemaElement addElement(XmlSchemaSequence schemaSequence,
                                    XmlSchemaType schemaType,
                                    Scope fqName,
                                    String name) {
    XmlSchemaElement element = new XmlSchemaElement(schema, false);
    element.setName(name);
    if (schemaType != null) {
        element.setSchemaTypeName(schemaType.getQName());
        if (schemaType.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            element.setNillable(true);
        }
    } else {
        wsdlVisitor.getDeferredActions().
            add(fqName, new OperationDeferredAction(element));
    }
    schemaSequence.getItems().add(element);

    return element;
}
 
Example 4
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void checkForElement(ServiceInfo serviceInfo, MessagePartInfo mpi) {
    SchemaInfo si = getOrCreateSchema(serviceInfo, mpi.getElementQName().getNamespaceURI(),
                                      getQualifyWrapperSchema());
    XmlSchemaElement e = si.getSchema().getElementByName(mpi.getElementQName().getLocalPart());
    if (e != null) {
        mpi.setXmlSchema(e);
        return;
    }
    XmlSchema schema = si.getSchema();
    si.setElement(null); //cached element is now invalid

    XmlSchemaElement el = new XmlSchemaElement(schema, true);
    el.setName(mpi.getElementQName().getLocalPart());
    el.setNillable(true);

    XmlSchemaType tp = (XmlSchemaType)mpi.getXmlSchema();
    if (tp == null) {
        throw new ServiceConstructionException(new Message("INTRACTABLE_PART", LOG,
                                                           mpi.getName(),
                                                           mpi.getMessageInfo().getName()));
    }
    el.setSchemaTypeName(tp.getQName());
    mpi.setXmlSchema(el);
}
 
Example 5
Source File: ArrayVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaComplexType generateSchemaArray(Scope scopedName, Long size,
                                                 XmlSchemaType type, Scope fQName) {
    XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema, true);
    complexType.setName(mapper.mapToQName(scopedName));

    XmlSchemaSequence sequence = new XmlSchemaSequence();

    XmlSchemaElement element = new XmlSchemaElement(schema, false);
    element.setMinOccurs(size);
    element.setMaxOccurs(size);
    element.setName(ELEMENT_NAME);
    if (type != null) {
        element.setSchemaTypeName(type.getQName());
        if (type.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            element.setNillable(true);
        }
    } else {
        ArrayDeferredAction arrayAction =
            new ArrayDeferredAction(element);
        wsdlVisitor.getDeferredActions().add(fQName, arrayAction);
    }

    sequence.getItems().add(element);

    complexType.setParticle(sequence);

    return complexType;
}
 
Example 6
Source File: SequenceVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaType generateSchemaType(XmlSchemaType stype, Scope scopedName,
                                         long bound, Scope fullyQualifiedName) {
    XmlSchemaComplexType ct = new XmlSchemaComplexType(schema, true);
    ct.setName(mapper.mapToQName(scopedName));
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    XmlSchemaElement el = new XmlSchemaElement(schema, false);
    el.setName(ELEMENT_NAME);
    el.setMinOccurs(0);
    if (bound != -1) {
        el.setMaxOccurs(bound);
    } else {
        el.setMaxOccurs(Long.MAX_VALUE);
    }
    if (stype != null) {
        el.setSchemaTypeName(stype.getQName());
        if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            el.setNillable(true);
        }
    } else {
        SequenceDeferredAction elementAction =
            new SequenceDeferredAction(el);
        wsdlVisitor.getDeferredActions().add(fullyQualifiedName, elementAction);
    }
    sequence.getItems().add(el);
    ct.setParticle(sequence);
    return ct;
}
 
Example 7
Source File: ParamDclVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaElement addElement(XmlSchemaSequence schemaSequence,
                                    XmlSchemaType schemaType,
                                    String name,
                                    Scope fullyQualifiedName) {
    XmlSchemaElement element = new XmlSchemaElement(schema, false);
    element.setName(name);
    if (schemaType == null) {
        ParamDeferredAction elementAction;
        if (mapper.isDefaultMapping()) {
            elementAction = new ParamDeferredAction(element);
        } else {
            elementAction = new ParamDeferredAction(element,
                                                    fullyQualifiedName.getParent(),
                                                    schema,
                                                    schemas,
                                                    manager,
                                                    mapper);
        }
        wsdlVisitor.getDeferredActions().add(fullyQualifiedName, elementAction);

        //ParamDeferredAction elementAction =
        //    new ParamDeferredAction(element);
        //wsdlVisitor.getDeferredActions().add(fullyQualifiedName, elementAction);
    } else {
        element.setSchemaTypeName(schemaType.getQName());
        if (schemaType.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            element.setNillable(true);
        }
    }
    schemaSequence.getItems().add(element);
    return element;
}
 
Example 8
Source File: BeanType.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void writeTypeReference(QName name, XmlSchemaElement element, AegisType type,
                                XmlSchema schemaRoot) {
    if (type.isAbstract()) {
        element.setName(name.getLocalPart());
        element.setSchemaTypeName(type.getSchemaType());
        XmlSchemaUtils.addImportIfNeeded(schemaRoot, type.getSchemaType().getNamespaceURI());

        /*
         * Here we have a semi-giant mess. If a parameter has a minOccurs > 1, it ends
         * up in the type info. However, it really got used in the array type.
         * All we really want to do here is manage 'optional' elements. If we
         * ever implement flat arrays, this will change. For now, we ignore
         * maxOccurs and we only look for 0's in the minOccurs.
         */
        long minOccurs = getTypeInfo().getMinOccurs(name);
        /* If it is 1, that's the default, and if it's greater than one, it means
         * that there is a real array at work here. So the only value we want to pay
         * attention to is 0.
         */
        if (minOccurs == 0) {
            element.setMinOccurs(minOccurs);
        }


        element.setNillable(getTypeInfo().isNillable(name));
    } else {
        element.getRef().setTargetQName(type.getSchemaType());
    }
}
 
Example 9
Source File: ArrayType.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void writeSchema(XmlSchema root) {

    if (isFlat()) {
        return; // there is no extra level of type.
    }
    if (hasDefinedArray(root)) {
        return;
    }

    XmlSchemaComplexType complex = new XmlSchemaComplexType(root, true);
    complex.setName(getSchemaType().getLocalPart());

    XmlSchemaSequence seq = new XmlSchemaSequence();
    complex.setParticle(seq);

    AegisType componentType = getComponentType();
    XmlSchemaElement element = new XmlSchemaElement(root, false);
    element.setName(componentType.getSchemaType().getLocalPart());
    element.setSchemaTypeName(componentType.getSchemaType());

    seq.getItems().add(element);

    if (componentType.isNillable()) {
        element.setNillable(true);
    }

    element.setMinOccurs(getMinOccurs());
    element.setMaxOccurs(getMaxOccurs());

}
 
Example 10
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaElement createXsElement(XmlSchema schema,
                                         MessagePartInfo part,
                                         QName typeName, SchemaInfo schemaInfo) {
    XmlSchemaElement el = new XmlSchemaElement(schema, true);
    el.setName(part.getElementQName().getLocalPart());
    el.setNillable(true);
    el.setSchemaTypeName(typeName);
    part.setXmlSchema(el);
    schemaInfo.setElement(null);
    return el;
}
 
Example 11
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void addElement(XmlSchema schema,
                          XmlSchemaSequence seq, JAXBBeanInfo beanInfo,
                          QName name, boolean isArray, XmlElement xmlElementAnno) {
    XmlSchemaElement el = new XmlSchemaElement(schema, false);
    if (isArray) {
        el.setMinOccurs(0);
        el.setMaxOccurs(Long.MAX_VALUE);
    } else {
        if (xmlElementAnno == null) {
            el.setMinOccurs(0);
            el.setNillable(false);
        } else {
            el.setNillable(xmlElementAnno.nillable());
            int minOccurs = xmlElementAnno.required() ? 1 : 0;
            el.setMinOccurs(minOccurs);
        }
    }

    if (beanInfo.isElement()) {
        QName ename = new QName(beanInfo.getElementNamespaceURI(null),
                               beanInfo.getElementLocalName(null));
        XmlSchemaElement el2 = schemas.getElementByQName(ename);
        el.setNillable(false);
        el.getRef().setTargetQName(el2.getQName());
    } else {
        if (xmlElementAnno != null && !StringUtils.isEmpty(xmlElementAnno.name())) {
            el.setName(xmlElementAnno.name());
        } else {
            el.setName(name.getLocalPart());
        }
        Iterator<QName> itr = beanInfo.getTypeNames().iterator();
        if (!itr.hasNext()) {
            return;
        }
        QName typeName = itr.next();
        el.setSchemaTypeName(typeName);
    }

    seq.getItems().add(el);
}
 
Example 12
Source File: AttributeVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
/** Generate a wrapped doc style XmlSchemaElement containing one element.
 *
 * I.e.: generateWrappedDocElement(null, "foo", "bar");
 * <xs:element name="foo">
 *   <xs:complexType>
 *     <xs:sequence>
 *     </xs:sequence>
 *   </xs:complexType>
 * </xs:element>
 *
 * i.e.: generateWrappedDocElement(type, "foo", "bar");
 * <xs:element name="foo">
 *   <xs:complexType>
 *     <xs:sequence>
 *       <xs:element name="bar" type="xs:short">
 *       </xs:element>
 *     </xs:sequence>
 *   </xs:complexType>
 * </xs:element>

 *
 * @param typeNode is the type of the element wrapped in the sequence, no element is created if null.
 * @param name is the name of the wrapping element.
 * @param paramName is the name of the  wrapping element.
 * @return the wrapping element.
 */
private XmlSchemaElement generateWrappedDocElement(AST typeNode, String name,
                                                   String paramName) {
    XmlSchemaElement element = new XmlSchemaElement(schema, false);
    if (typeNode != null) {
        ParamTypeSpecVisitor visitor = new ParamTypeSpecVisitor(getScope(),
                                                                definition,
                                                                schema,
                                                                wsdlVisitor);
        visitor.visit(typeNode);
        XmlSchemaType stype = visitor.getSchemaType();
        Scope fqName = visitor.getFullyQualifiedName();

        if (stype != null) {
            element.setSchemaTypeName(stype.getQName());
            if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
                element.setNillable(true);
            }
        } else {
            wsdlVisitor.getDeferredActions().
                add(fqName, new AttributeDeferredAction(element));
        }

        element.setName(paramName);
    }

    XmlSchemaSequence sequence = new XmlSchemaSequence();
    if (typeNode != null) {
        sequence.getItems().add(element);
    }

    XmlSchemaComplexType complex = new XmlSchemaComplexType(schema, false);
    complex.setParticle(sequence);

    QName qName = new QName(definition.getTargetNamespace(), name);

    XmlSchemaElement result = new XmlSchemaElement(schema, true);
    result.setSchemaType(complex);

    if (duplicateTypeTrackerMap.containsKey(qName.toString())) {
        result.setName(getScope().toString() + "." + name);
        qName = new QName(definition.getTargetNamespace(), getScope().toString() + "." + name);
    } else {
        result.setName(name);
    }

    duplicateTypeTrackerMap.put(qName.toString(), name);

    return result;
}
 
Example 13
Source File: UnionVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void processCaseNodes(AST caseNode,
                              Scope scope,
                              XmlSchemaChoice choice,
                              Union corbaUnion) {
    while (caseNode != null) {
        AST typeNode = null;
        AST nameNode = null;
        AST labelNode = null;

        // xmlschema:element
        XmlSchemaElement element = new XmlSchemaElement(schema, false);

        // corba:unionbranch
        Unionbranch unionBranch = new Unionbranch();

        if (caseNode.getType() == IDLTokenTypes.LITERAL_default) {
            // default:
            unionBranch.setDefault(true);

            typeNode = caseNode.getFirstChild();
            nameNode = typeNode.getNextSibling();
        } else {
            // case:
            createCase(caseNode, unionBranch);

            labelNode = caseNode.getFirstChild();
            if (labelNode.getType() == IDLTokenTypes.LITERAL_case) {
                labelNode = labelNode.getNextSibling();
            }

            typeNode = labelNode.getNextSibling();
            nameNode = typeNode.getNextSibling();
        }


        TypesVisitor visitor = new TypesVisitor(scope,
                                                definition,
                                                schema,
                                                wsdlVisitor,
                                                null);
        visitor.visit(typeNode);
        XmlSchemaType stype = visitor.getSchemaType();
        CorbaType ctype = visitor.getCorbaType();
        Scope fullyQualifiedName = visitor.getFullyQualifiedName();


        // needed for anonymous arrays in unions
        if (ArrayVisitor.accept(nameNode)) {
            Scope anonScope = new Scope(scope, TypesUtils.getCorbaTypeNameNode(nameNode));
            ArrayVisitor arrayVisitor = new ArrayVisitor(anonScope,
                                                         definition,
                                                         schema,
                                                         wsdlVisitor,
                                                         null,
                                                         fullyQualifiedName);
            arrayVisitor.setSchemaType(stype);
            arrayVisitor.setCorbaType(ctype);
            arrayVisitor.visit(nameNode);
            stype = arrayVisitor.getSchemaType();
            ctype = arrayVisitor.getCorbaType();
            fullyQualifiedName = visitor.getFullyQualifiedName();
        }


        // xmlschema:element
        element.setName(nameNode.toString());
        if (stype != null) {
            element.setSchemaTypeName(stype.getQName());
            if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
                element.setNillable(true);
            }
        } else {
            UnionDeferredAction elementAction =
                new UnionDeferredAction(element);
            wsdlVisitor.getDeferredActions().add(fullyQualifiedName, elementAction);
        }
        choice.getItems().add(element);


        // corba:unionbranch
        unionBranch.setName(nameNode.toString());
        if (ctype != null) {
            unionBranch.setIdltype(ctype.getQName());
        } else {
            // its type is forward declared.
            UnionDeferredAction unionBranchAction =
                new UnionDeferredAction(unionBranch);
            wsdlVisitor.getDeferredActions().add(fullyQualifiedName, unionBranchAction);
        }
        corbaUnion.getUnionbranch().add(unionBranch);

        caseNode = caseNode.getNextSibling();
    }
}
 
Example 14
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void createBareMessage(ServiceInfo serviceInfo, OperationInfo opInfo, boolean isOut) {

        MessageInfo message = isOut ? opInfo.getOutput() : opInfo.getInput();

        final List<MessagePartInfo> messageParts = message.getMessageParts();
        if (messageParts.isEmpty()) {
            return;
        }

        Method method = (Method)opInfo.getProperty(METHOD);
        int paraNumber = 0;
        for (MessagePartInfo mpi : messageParts) {
            SchemaInfo schemaInfo = null;
            XmlSchema schema = null;

            QName qname = (QName)mpi.getProperty(ELEMENT_NAME);
            if (messageParts.size() == 1 && qname == null) {
                qname = !isOut ? getInParameterName(opInfo, method, -1)
                        : getOutParameterName(opInfo, method, -1);

                if (qname.getLocalPart().startsWith("arg") || qname.getLocalPart().startsWith("return")) {
                    qname = isOut
                        ? new QName(qname.getNamespaceURI(), method.getName() + "Response") : new QName(qname
                            .getNamespaceURI(), method.getName());
                }
            } else if (isOut && messageParts.size() > 1 && qname == null) {
                while (!isOutParam(method, paraNumber)) {
                    paraNumber++;
                }
                qname = getOutParameterName(opInfo, method, paraNumber);
            } else if (qname == null) {
                qname = getInParameterName(opInfo, method, paraNumber);
            }

            for (SchemaInfo s : serviceInfo.getSchemas()) {
                if (s.getNamespaceURI().equals(qname.getNamespaceURI())) {
                    schemaInfo = s;
                    break;
                }
            }

            if (schemaInfo == null) {
                schemaInfo = getOrCreateSchema(serviceInfo, qname.getNamespaceURI(), true);
                schema = schemaInfo.getSchema();
            } else {
                schema = schemaInfo.getSchema();
                if (schema != null && schema.getElementByName(qname) != null) {
                    mpi.setElement(true);
                    mpi.setElementQName(qname);
                    mpi.setXmlSchema(schema.getElementByName(qname));
                    paraNumber++;
                    continue;
                }
            }

            schemaInfo.setElement(null); //cached element is now invalid
            XmlSchemaElement el = new XmlSchemaElement(schema, true);
            el.setName(qname.getLocalPart());
            el.setNillable(true);

            if (mpi.isElement()) {
                XmlSchemaElement oldEl = (XmlSchemaElement)mpi.getXmlSchema();
                if (null != oldEl && !oldEl.getQName().equals(qname)) {
                    el.setSchemaTypeName(oldEl.getSchemaTypeName());
                    el.setSchemaType(oldEl.getSchemaType());
                    if (oldEl.getSchemaTypeName() != null) {
                        addImport(schema, oldEl.getSchemaTypeName().getNamespaceURI());
                    }
                }
                mpi.setElement(true);
                mpi.setXmlSchema(el);
                mpi.setElementQName(qname);
                mpi.setConcreteName(qname);
                continue;
            }
            if (null == mpi.getTypeQName() && mpi.getXmlSchema() == null) {
                throw new ServiceConstructionException(new Message("UNMAPPABLE_PORT_TYPE", LOG,
                                                                   method.getDeclaringClass().getName(),
                                                                   method.getName(),
                                                                   mpi.getName()));
            }
            if (mpi.getTypeQName() != null) {
                el.setSchemaTypeName(mpi.getTypeQName());
            } else {
                el.setSchemaType((XmlSchemaType)mpi.getXmlSchema());
            }
            mpi.setXmlSchema(el);
            mpi.setConcreteName(qname);
            if (mpi.getTypeQName() != null) {
                addImport(schema, mpi.getTypeQName().getNamespaceURI());
            }

            mpi.setElement(true);
            mpi.setElementQName(qname);
            paraNumber++;
        }
    }