Search in sources :

Example 26 with XmlSchemaComplexType

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

the class ImportRepairTest method createDerivedType1.

private XmlSchemaComplexContentExtension createDerivedType1(XmlSchema importingSchema) {
    XmlSchemaComplexType derivedType1 = new XmlSchemaComplexType(importingSchema, true);
    derivedType1.setName("derivedExtension");
    XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
    extension.setBaseTypeName(new QName(BASE_TYPE_SCHEMA1, "baseType1"));
    XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent();
    complexContent.setContent(extension);
    derivedType1.setContentModel(complexContent);
    return extension;
}
Also used : XmlSchemaComplexContentExtension(org.apache.ws.commons.schema.XmlSchemaComplexContentExtension) QName(javax.xml.namespace.QName) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaComplexContent(org.apache.ws.commons.schema.XmlSchemaComplexContent)

Example 27 with XmlSchemaComplexType

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

the class ServiceModelUtil method getOperationInputPartNames.

public static List<String> getOperationInputPartNames(OperationInfo operation) {
    List<String> names = new ArrayList<>();
    List<MessagePartInfo> parts = operation.getInput().getMessageParts();
    if (parts == null || parts.isEmpty()) {
        return names;
    }
    for (MessagePartInfo part : parts) {
        XmlSchemaAnnotated schema = part.getXmlSchema();
        if (schema instanceof XmlSchemaElement && ((XmlSchemaElement) schema).getSchemaType() instanceof XmlSchemaComplexType) {
            XmlSchemaElement element = (XmlSchemaElement) schema;
            XmlSchemaComplexType cplxType = (XmlSchemaComplexType) element.getSchemaType();
            XmlSchemaSequence seq = (XmlSchemaSequence) cplxType.getParticle();
            if (seq == null || seq.getItems() == null) {
                return names;
            }
            for (int i = 0; i < seq.getItems().size(); i++) {
                XmlSchemaElement elChild = (XmlSchemaElement) seq.getItems().get(i);
                names.add(elChild.getName());
            }
        } else {
            names.add(part.getConcreteName().getLocalPart());
        }
    }
    return names;
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) ArrayList(java.util.ArrayList) XmlSchemaAnnotated(org.apache.ws.commons.schema.XmlSchemaAnnotated) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 28 with XmlSchemaComplexType

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

the class JAXBSchemaInitializer method buildExceptionType.

private void buildExceptionType(MessagePartInfo part, Class<?> cls) {
    SchemaInfo schemaInfo = null;
    for (SchemaInfo s : serviceInfo.getSchemas()) {
        if (s.getNamespaceURI().equals(part.getElementQName().getNamespaceURI())) {
            schemaInfo = s;
            break;
        }
    }
    XmlAccessorOrder xmlAccessorOrder = cls.getAnnotation(XmlAccessorOrder.class);
    XmlType xmlTypeAnno = cls.getAnnotation(XmlType.class);
    String[] propertyOrder = null;
    boolean respectXmlTypeNS = false;
    XmlSchema faultBeanSchema = null;
    if (xmlTypeAnno != null && !StringUtils.isEmpty(xmlTypeAnno.namespace()) && !xmlTypeAnno.namespace().equals(part.getElementQName().getNamespaceURI())) {
        respectXmlTypeNS = true;
        NamespaceMap nsMap = new NamespaceMap();
        nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, xmlTypeAnno.namespace());
        nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
        SchemaInfo faultBeanSchemaInfo = createSchemaIfNeeded(xmlTypeAnno.namespace(), nsMap);
        faultBeanSchema = faultBeanSchemaInfo.getSchema();
    }
    if (xmlTypeAnno != null && xmlTypeAnno.propOrder().length > 0) {
        propertyOrder = xmlTypeAnno.propOrder();
    // TODO: handle @XmlAccessOrder
    }
    XmlSchema schema = null;
    if (schemaInfo == null) {
        NamespaceMap nsMap = new NamespaceMap();
        nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, part.getElementQName().getNamespaceURI());
        nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
        schemaInfo = createSchemaIfNeeded(part.getElementQName().getNamespaceURI(), nsMap);
    }
    schema = schemaInfo.getSchema();
    // Before updating everything, make sure we haven't added this
    // type yet.  Multiple methods that throw the same exception
    // types will cause duplicates.
    String faultTypeName = xmlTypeAnno != null && !StringUtils.isEmpty(xmlTypeAnno.name()) ? xmlTypeAnno.name() : part.getElementQName().getLocalPart();
    XmlSchemaType existingType = schema.getTypeByName(faultTypeName);
    if (existingType != null) {
        return;
    }
    XmlSchemaElement el = new XmlSchemaElement(schema, true);
    el.setName(part.getElementQName().getLocalPart());
    part.setXmlSchema(el);
    schemaInfo.setElement(null);
    if (respectXmlTypeNS) {
        // create complexType in the new created schema for xmlType
        schema = faultBeanSchema;
    }
    XmlSchemaComplexType ct = new XmlSchemaComplexType(schema, true);
    ct.setName(faultTypeName);
    el.setSchemaTypeName(ct.getQName());
    XmlSchemaSequence seq = new XmlSchemaSequence();
    ct.setParticle(seq);
    String namespace = part.getElementQName().getNamespaceURI();
    XmlAccessType accessType = Utils.getXmlAccessType(cls);
    // 
    for (Field f : Utils.getFields(cls, accessType)) {
        // map field
        Type type = Utils.getFieldType(f);
        // generic return type.
        if ((type == null) && (f.getGenericType() instanceof ParameterizedType)) {
            type = f.getGenericType();
        }
        if (generateGenericType(type)) {
            buildGenericElements(schema, seq, f);
        } else {
            JAXBBeanInfo beanInfo = getBeanInfo(type);
            if (beanInfo != null) {
                XmlElement xmlElementAnno = f.getAnnotation(XmlElement.class);
                addElement(schema, seq, beanInfo, new QName(namespace, f.getName()), isArray(type), xmlElementAnno);
            }
        }
    }
    for (Method m : Utils.getGetters(cls, accessType)) {
        // map method
        Type type = Utils.getMethodReturnType(m);
        // generic return type.
        if ((type == null) && (m.getGenericReturnType() instanceof ParameterizedType)) {
            type = m.getGenericReturnType();
        }
        if (generateGenericType(type)) {
            buildGenericElements(schema, seq, m, type);
        } else {
            JAXBBeanInfo beanInfo = getBeanInfo(type);
            if (beanInfo != null) {
                int idx = m.getName().startsWith("get") ? 3 : 2;
                String name = m.getName().substring(idx);
                name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
                XmlElement xmlElementAnno = m.getAnnotation(XmlElement.class);
                addElement(schema, seq, beanInfo, new QName(namespace, name), isArray(type), xmlElementAnno);
            }
        }
    }
    // Create element in xsd:sequence for Exception.class
    if (Exception.class.isAssignableFrom(cls)) {
        addExceptionMessage(cls, schema, seq);
    }
    if (propertyOrder != null) {
        if (propertyOrder.length == seq.getItems().size()) {
            sortItems(seq, propertyOrder);
        } else if (propertyOrder.length > 1 || (propertyOrder.length == 1 && !propertyOrder[0].isEmpty())) {
            LOG.log(Level.WARNING, "propOrder in @XmlType doesn't define all schema elements :" + Arrays.toString(propertyOrder));
        }
    }
    if (xmlAccessorOrder != null && xmlAccessorOrder.value().equals(XmlAccessOrder.ALPHABETICAL) && propertyOrder == null) {
        sort(seq);
    }
    schemas.addCrossImports();
    part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION", Boolean.TRUE);
}
Also used : XmlAccessorOrder(javax.xml.bind.annotation.XmlAccessorOrder) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) Method(java.lang.reflect.Method) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlType(javax.xml.bind.annotation.XmlType) ParameterizedType(java.lang.reflect.ParameterizedType) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) Field(java.lang.reflect.Field) GenericArrayType(java.lang.reflect.GenericArrayType) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlAccessType(javax.xml.bind.annotation.XmlAccessType) Type(java.lang.reflect.Type) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlType(javax.xml.bind.annotation.XmlType) ParameterizedType(java.lang.reflect.ParameterizedType) XmlSchema(org.apache.ws.commons.schema.XmlSchema) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap) JAXBBeanInfo(org.apache.cxf.common.jaxb.JAXBBeanInfo) XmlElement(javax.xml.bind.annotation.XmlElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlAccessType(javax.xml.bind.annotation.XmlAccessType) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 29 with XmlSchemaComplexType

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

the class JAXBSchemaInitializer method buildGenericElements.

private void buildGenericElements(XmlSchema schema, XmlSchemaSequence seq, Method m, Type type) {
    String rawType = ((ParameterizedType) type).getRawType().toString();
    String typeName = StringUtils.uncapitalize(rawType.substring(rawType.lastIndexOf(".") + 1));
    XmlSchemaComplexType generics = (XmlSchemaComplexType) schema.getTypeByName(typeName);
    if (generics == null) {
        generics = new XmlSchemaComplexType(schema, true);
        generics.setName(typeName);
    }
    Class<?> genericsClass = m.getReturnType();
    buildGenericSeq(schema, generics, genericsClass);
    int idx = m.getName().startsWith("get") ? 3 : 2;
    String name = m.getName().substring(idx);
    name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
    XmlSchemaElement newel = new XmlSchemaElement(schema, false);
    newel.setName(name);
    newel.setSchemaTypeName(generics.getQName());
    newel.setMinOccurs(0);
    if (!seq.getItems().contains(newel)) {
        seq.getItems().add(newel);
    }
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 30 with XmlSchemaComplexType

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

the class BeanType method writeSchema.

@Override
public void writeSchema(XmlSchema root) {
    BeanTypeInfo inf = getTypeInfo();
    XmlSchemaComplexType complex = new XmlSchemaComplexType(root, true);
    complex.setName(getSchemaType().getLocalPart());
    AegisType sooperType = getSuperType();
    /*
         * See Java Virtual Machine specification:
         * http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75734
         */
    if (((inf.getTypeClass().getModifiers() & Modifier.ABSTRACT) != 0) && !inf.getTypeClass().isInterface()) {
        complex.setAbstract(true);
    }
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    /*
         * Decide if we're going to extend another type. If we are going to defer, then make sure that we
         * extend the type for our superclass.
         */
    boolean isExtension = inf.isExtension();
    if (isExtension && sooperType != null) {
        // if sooperType is null, things are confused.
        XmlSchemaComplexContent content = new XmlSchemaComplexContent();
        complex.setContentModel(content);
        XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
        content.setContent(extension);
        extension.setBaseTypeName(sooperType.getSchemaType());
        extension.setParticle(sequence);
    } else {
        complex.setParticle(sequence);
    }
    boolean needXmime = false;
    boolean needUtilityTypes = false;
    // Write out schema for elements
    for (QName name : inf.getElements()) {
        if (isInheritedProperty(inf, name)) {
            continue;
        }
        XmlSchemaElement element = new XmlSchemaElement(root, false);
        element.setName(name.getLocalPart());
        sequence.getItems().add(element);
        AegisType type = getType(inf, name);
        if (type.isFlatArray()) {
            // ok, we need some tricks here
            element.setMinOccurs(type.getMinOccurs());
            element.setMaxOccurs(type.getMaxOccurs());
            // for now, assume ArrayType. Look at lists or more general solutions later.
            ArrayType aType = (ArrayType) type;
            type = aType.getComponentType();
            element.setNillable(type.isNillable());
        } else {
            if (AbstractTypeCreator.HTTP_CXF_APACHE_ORG_ARRAYS.equals(type.getSchemaType().getNamespaceURI())) {
                XmlSchemaUtils.addImportIfNeeded(root, AbstractTypeCreator.HTTP_CXF_APACHE_ORG_ARRAYS);
            }
        }
        writeTypeReference(name, element, type, root);
        needXmime |= type.usesXmime();
        needUtilityTypes |= type.usesUtilityTypes();
    }
    if (needXmime) {
        addXmimeToSchema(root);
    }
    if (needUtilityTypes) {
        AegisContext.addUtilityTypesToSchema(root);
    }
    /**
     * if future proof then add <xsd:any/> element
     */
    if (inf.isExtensibleElements()) {
        XmlSchemaAny any = new XmlSchemaAny();
        any.setMinOccurs(0);
        any.setMaxOccurs(Long.MAX_VALUE);
        sequence.getItems().add(any);
    }
    // Write out schema for attributes
    for (QName name : inf.getAttributes()) {
        if (isInheritedProperty(inf, name)) {
            continue;
        }
        XmlSchemaAttribute attribute = new XmlSchemaAttribute(root, false);
        complex.getAttributes().add(attribute);
        attribute.setName(name.getLocalPart());
        AegisType type = getType(inf, name);
        attribute.setSchemaTypeName(type.getSchemaType());
        String ns = name.getNamespaceURI();
        if (!ns.equals(root.getTargetNamespace())) {
            XmlSchemaUtils.addImportIfNeeded(root, ns);
        }
    }
    /**
     * If extensible attributes then add <xsd:anyAttribute/>
     */
    if (inf.isExtensibleAttributes()) {
        complex.setAnyAttribute(new XmlSchemaAnyAttribute());
    }
}
Also used : XmlSchemaComplexContentExtension(org.apache.ws.commons.schema.XmlSchemaComplexContentExtension) AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaAny(org.apache.ws.commons.schema.XmlSchemaAny) XmlSchemaComplexContent(org.apache.ws.commons.schema.XmlSchemaComplexContent) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaAnyAttribute(org.apache.ws.commons.schema.XmlSchemaAnyAttribute)

Aggregations

XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)88 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)60 QName (javax.xml.namespace.QName)45 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)38 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)25 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)25 XmlSchema (org.apache.ws.commons.schema.XmlSchema)24 Test (org.junit.Test)18 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)13 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)12 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)12 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)11 XmlSchemaSequenceMember (org.apache.ws.commons.schema.XmlSchemaSequenceMember)11 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)10 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)8 ParameterInfo (org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo)8 ArrayList (java.util.ArrayList)7 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)7 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)7 XmlSchemaComplexContentRestriction (org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction)6