Search in sources :

Example 91 with XmlSchemaComplexType

use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.

the class ReflectionServiceFactoryBean method createWrappedMessageSchema.

private void createWrappedMessageSchema(ServiceInfo serviceInfo, AbstractMessageContainer wrappedMessage, AbstractMessageContainer unwrappedMessage, SchemaInfo info, QName wrapperName) {
    XmlSchema schema = info.getSchema();
    // the cached schema will be no good
    info.setElement(null);
    XmlSchemaElement el = new XmlSchemaElement(schema, true);
    el.setName(wrapperName.getLocalPart());
    wrappedMessage.getFirstMessagePart().setXmlSchema(el);
    boolean anonymousType = isAnonymousWrapperTypes();
    XmlSchemaComplexType ct = new XmlSchemaComplexType(schema, /*CXF-6783: don't create anonymous top-level types*/
    !anonymousType);
    if (!anonymousType) {
        ct.setName(wrapperName.getLocalPart());
        el.setSchemaTypeName(wrapperName);
    }
    el.setSchemaType(ct);
    XmlSchemaSequence seq = new XmlSchemaSequence();
    ct.setParticle(seq);
    for (MessagePartInfo mpi : unwrappedMessage.getMessageParts()) {
        el = new XmlSchemaElement(schema, Boolean.TRUE.equals(mpi.getProperty(HEADER)));
        Map<Class<?>, Boolean> jaxbAnnoMap = getJaxbAnnoMap(mpi);
        if (mpi.isElement()) {
            addImport(schema, mpi.getElementQName().getNamespaceURI());
            XmlSchemaUtils.setElementRefName(el, mpi.getElementQName());
        } else {
            // We hope that we can't have parts that different only in namespace.
            el.setName(mpi.getName().getLocalPart());
            if (mpi.getTypeQName() != null && !jaxbAnnoMap.containsKey(XmlList.class)) {
                el.setSchemaTypeName(mpi.getTypeQName());
                addImport(schema, mpi.getTypeQName().getNamespaceURI());
            }
            el.setSchemaType((XmlSchemaType) mpi.getXmlSchema());
            if (schema.getElementFormDefault().equals(XmlSchemaForm.UNQUALIFIED)) {
                mpi.setConcreteName(new QName(null, mpi.getName().getLocalPart()));
            } else {
                mpi.setConcreteName(mpi.getName());
            }
        }
        if (!Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
            boolean wasType = !mpi.isElement();
            if (wasType) {
                QName concreteName = mpi.getConcreteName();
                mpi.setElement(true);
                mpi.setElementQName(el.getQName());
                mpi.setConcreteName(concreteName);
            }
            addMimeType(el, getMethodParameterAnnotations(mpi));
            Annotation[] methodAnnotations = getMethodAnnotations(mpi);
            if (methodAnnotations != null) {
                addMimeType(el, methodAnnotations);
            }
            long min = getWrapperPartMinOccurs(mpi);
            long max = getWrapperPartMaxOccurs(mpi);
            boolean nillable = isWrapperPartNillable(mpi);
            Boolean qualified = isWrapperPartQualified(mpi);
            if (qualified == null) {
                qualified = this.isQualifyWrapperSchema();
            }
            if (qualified && StringUtils.isEmpty(mpi.getConcreteName().getNamespaceURI())) {
                QName newName = new QName(wrapperName.getNamespaceURI(), mpi.getConcreteName().getLocalPart());
                mpi.setElement(true);
                mpi.setElementQName(newName);
                mpi.setConcreteName(newName);
                el.setName(newName.getLocalPart());
                el.setForm(XmlSchemaForm.QUALIFIED);
            }
            if (Collection.class.isAssignableFrom(mpi.getTypeClass()) && mpi.getTypeClass().isInterface()) {
                Type type = (Type) mpi.getProperty(GENERIC_TYPE);
                if (!(type instanceof java.lang.reflect.ParameterizedType) && el.getSchemaTypeName() == null && el.getSchemaType() == null) {
                    max = Long.MAX_VALUE;
                    el.setSchemaTypeName(Constants.XSD_ANYTYPE);
                }
            }
            el.setMinOccurs(min);
            el.setMaxOccurs(max);
            if (nillable) {
                el.setNillable(nillable);
            }
            seq.getItems().add(el);
            mpi.setXmlSchema(el);
        }
        if (Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
            QName qn = (QName) mpi.getProperty(ELEMENT_NAME);
            el.setName(qn.getLocalPart());
            SchemaInfo headerSchemaInfo = getOrCreateSchema(serviceInfo, qn.getNamespaceURI(), getQualifyWrapperSchema());
            if (!isExistSchemaElement(headerSchemaInfo.getSchema(), qn)) {
                headerSchemaInfo.getSchema().getItems().add(el);
            }
        }
    }
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Annotation(java.lang.annotation.Annotation) ParameterizedType(java.lang.reflect.ParameterizedType) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) GenericArrayType(java.lang.reflect.GenericArrayType) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) Type(java.lang.reflect.Type) XmlMimeType(javax.xml.bind.annotation.XmlMimeType) ParameterizedType(java.lang.reflect.ParameterizedType) XmlSchema(org.apache.ws.commons.schema.XmlSchema) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) Collection(java.util.Collection) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 92 with XmlSchemaComplexType

use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.

the class ExceptionVisitor method visit.

public void visit(AST node) {
    // <exception_dcl> ::= "exception" <identifier> "{" <member>* "}"
    // <member> ::= <type_spec> <declarators> ";"
    // <type_spec> visited by TypesVisitor
    // Following should be visited by a separate visitor
    // <declarators> ::= <declarator> { "," <declarator> }*
    // <declarator> ::= <simple_declarator>
    // | <complex_declarator>
    // <simple_declarator> ::= <identifier>
    // <complex_declarator> ::= <array_declarator>
    // <array_declarator> ::= <identifier> <fixed_array_size>+
    // <fixed_array_size> ::= "[" <positive_int_const> "]"
    AST identifierNode = node.getFirstChild();
    Scope exceptionScope = new Scope(getScope(), identifierNode);
    // xmlschema:exception
    Scope scopedName = new Scope(getScope(), identifierNode);
    String exceptionName = mapper.mapToQName(scopedName);
    XmlSchemaElement element = new XmlSchemaElement(schema, true);
    element.setName(mapper.mapToQName(scopedName));
    String exceptionTypeName = exceptionName + TYPE_SUFFIX;
    XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema, true);
    complexType.setName(exceptionTypeName);
    // complexType.setQName(new QName(schema.getTargetNamespace(), exceptionTypeName));
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    complexType.setParticle(sequence);
    element.setSchemaTypeName(complexType.getQName());
    // corba:exception
    org.apache.cxf.binding.corba.wsdl.Exception exception = new org.apache.cxf.binding.corba.wsdl.Exception();
    exception.setQName(new QName(typeMap.getTargetNamespace(), exceptionName));
    exception.setType(complexType.getQName());
    exception.setRepositoryID(scopedName.toIDLRepositoryID());
    // exception members
    AST memberTypeNode = identifierNode.getNextSibling();
    while (memberTypeNode != null) {
        AST memberNode = TypesUtils.getCorbaTypeNameNode(memberTypeNode);
        TypesVisitor visitor = new TypesVisitor(exceptionScope, definition, schema, wsdlVisitor, null);
        visitor.visit(memberTypeNode);
        XmlSchemaType stype = visitor.getSchemaType();
        CorbaType ctype = visitor.getCorbaType();
        Scope fullyQualifiedName = visitor.getFullyQualifiedName();
        // needed for anonymous arrays in exceptions
        if (ArrayVisitor.accept(memberNode)) {
            Scope anonScope = new Scope(exceptionScope, TypesUtils.getCorbaTypeNameNode(memberTypeNode));
            ArrayVisitor arrayVisitor = new ArrayVisitor(anonScope, definition, schema, wsdlVisitor, null, fullyQualifiedName);
            arrayVisitor.setSchemaType(stype);
            arrayVisitor.setCorbaType(ctype);
            arrayVisitor.visit(memberNode);
            stype = arrayVisitor.getSchemaType();
            ctype = arrayVisitor.getCorbaType();
        }
        XmlSchemaElement member = createElementType(memberNode, stype, fullyQualifiedName);
        sequence.getItems().add(member);
        MemberType memberType = createMemberType(memberNode, ctype, fullyQualifiedName);
        exception.getMember().add(memberType);
        memberTypeNode = memberNode.getNextSibling();
    }
    // add exception to corba typemap
    typeMap.getStructOrExceptionOrUnion().add(exception);
    setSchemaType(complexType);
    setCorbaType(exception);
    createFaultMessage(element.getQName());
}
Also used : AST(antlr.collections.AST) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 93 with XmlSchemaComplexType

use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.

the class OperationVisitor method generateWrapper.

/*-
     * Build the Wrapped Document Style wrapping elements
     * i.e. <xs:element name="...">
     *       <xs:complexType>
     *        <xs:sequence>
     *         ...
     *        </xs:sequence>
     *       </xs:complexType>
     *      </xs:element>
     */
private XmlSchemaElement generateWrapper(QName el, XmlSchemaSequence wrappingSequence) {
    XmlSchemaComplexType schemaComplexType = new XmlSchemaComplexType(schema, false);
    schemaComplexType.setParticle(wrappingSequence);
    XmlSchemaElement wrappingSchemaElement = new XmlSchemaElement(schema, true);
    wrappingSchemaElement.setName(el.getLocalPart());
    wrappingSchemaElement.setSchemaType(schemaComplexType);
    return wrappingSchemaElement;
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 94 with XmlSchemaComplexType

use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.

the class ArrayVisitor method generateSchemaArray.

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;
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 95 with XmlSchemaComplexType

use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.

the class AttributeVisitor method generateWrappedDocElement.

/**
 * 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;
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Aggregations

XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)136 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)101 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)71 QName (javax.xml.namespace.QName)59 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)33 XmlSchema (org.apache.ws.commons.schema.XmlSchema)32 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)31 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)23 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)20 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)18 Test (org.junit.Test)18 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)16 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)15 ArrayList (java.util.ArrayList)13 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)12 XmlSchemaSequenceMember (org.apache.ws.commons.schema.XmlSchemaSequenceMember)12 XmlSchemaSimpleContentExtension (org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension)12 XmlSchemaComplexContentRestriction (org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction)8 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)8 ParameterInfo (org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo)8