Search in sources :

Example 81 with XmlSchemaType

use of org.apache.ws.commons.schema.XmlSchemaType 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)

Aggregations

XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)81 QName (javax.xml.namespace.QName)47 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)37 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)23 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)23 XmlSchema (org.apache.ws.commons.schema.XmlSchema)21 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)16 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)12 AST (antlr.collections.AST)8 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)8 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)7 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)6 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)5 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)5 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)5 ArrayList (java.util.ArrayList)4 CorbaTypeImpl (org.apache.cxf.binding.corba.wsdl.CorbaTypeImpl)4 Message (org.apache.cxf.common.i18n.Message)4 ParticleInfo (org.apache.cxf.javascript.ParticleInfo)4 XmlSchemaCollection (org.apache.ws.commons.schema.XmlSchemaCollection)4