Search in sources :

Example 1 with XmlSchemaSequence

use of org.apache.ws.commons.schema.XmlSchemaSequence in project qi4j-sdk by Qi4j.

the class ValueCompositeCxfType method writeSchema.

@Override
public void writeSchema(XmlSchema root) {
    XmlSchemaComplexType complex = new XmlSchemaComplexType(root, true);
    complex.setName(getSchemaType().getLocalPart());
    root.getItems().add(complex);
    // No clue why this?
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    // No idea what this is for
    complex.setParticle(sequence);
    ValueDescriptor descriptor = module.valueDescriptor(getTypeClass().getName());
    for (PropertyDescriptor p : descriptor.state().properties()) {
        if (isValueComposite(p.type())) {
            XmlSchemaElement element = new XmlSchemaElement(root, false);
            element.setName(p.qualifiedName().name());
            // see below
            element.setNillable(p.metaInfo(Optional.class) != null);
            sequence.getItems().add(element);
            AegisType nested = getOrCreateAegisType(p.type(), root);
            element.setSchemaTypeName(nested.getSchemaType());
        } else if (isCollectionOrMap(p)) {
            XmlSchemaElement element = new XmlSchemaElement(root, false);
            element.setName(p.qualifiedName().name());
            // see below
            element.setNillable(p.metaInfo(Optional.class) != null);
            sequence.getItems().add(element);
            AegisType nested = getOrCreateAegisType(p.type(), root);
            element.setSchemaTypeName(nested.getSchemaType());
        } else {
            XmlSchemaAttribute attribute = new XmlSchemaAttribute(root, false);
            complex.getAttributes().add(attribute);
            attribute.setName(p.qualifiedName().name());
            AegisType nested = getTypeMapping().getType(p.type());
            attribute.setSchemaTypeName(nested.getSchemaType());
        }
        QName name = NamespaceUtil.convertJavaTypeToQName(p.type());
        String ns = name.getNamespaceURI();
        if (!ns.equals(root.getTargetNamespace())) {
            XmlSchemaUtils.addImportIfNeeded(root, ns);
        }
    }
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) Optional(org.qi4j.api.common.Optional) AegisType(org.apache.cxf.aegis.type.AegisType) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) ValueDescriptor(org.qi4j.api.value.ValueDescriptor) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute)

Example 2 with XmlSchemaSequence

use of org.apache.ws.commons.schema.XmlSchemaSequence in project ddf by codice.

the class FeatureMetacardTypeTest method testFeatureMetacardTypeComplexContentWithStringAndGmlProperties.

@Test
public void testFeatureMetacardTypeComplexContentWithStringAndGmlProperties() {
    XmlSchema schema = new XmlSchema();
    // Create the GML and String types
    XmlSchemaElement gmlElement = new XmlSchemaElement(schema, true);
    gmlElement.setSchemaType(new XmlSchemaComplexType(schema, false));
    gmlElement.setSchemaTypeName(new QName(Wfs20Constants.GML_3_2_NAMESPACE, GML));
    gmlElement.setName(ELEMENT_NAME_1);
    XmlSchemaElement stringElement = new XmlSchemaElement(schema, true);
    stringElement.setSchemaType(new XmlSchemaSimpleType(schema, false));
    stringElement.setSchemaTypeName(Constants.XSD_STRING);
    stringElement.setName(ELEMENT_NAME_2);
    // build the complex objects
    XmlSchemaElement complexElement = new XmlSchemaElement(schema, true);
    XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema, false);
    XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent();
    XmlSchemaComplexContentExtension contentExtension = new XmlSchemaComplexContentExtension();
    XmlSchemaSequence particle = new XmlSchemaSequence();
    particle.getItems().add(stringElement);
    contentExtension.setParticle(particle);
    complexContent.setContent(contentExtension);
    complexType.setContentModel(complexContent);
    complexElement.setSchemaType(complexType);
    complexElement.setSchemaTypeName(new QName("Complex"));
    schema.getElements().put(new QName(ELEMENT_NAME_2), complexElement);
    FeatureMetacardType featureMetacardType = new FeatureMetacardType(schema, FEATURE_TYPE, NON_QUERYABLE_PROPS, Wfs20Constants.GML_3_2_NAMESPACE);
    assertTrue(featureMetacardType.getTextualProperties().size() == 1);
    assertTrue(featureMetacardType.getGmlProperties().size() == 1);
    assertAttributeDescriptor(featureMetacardType, ELEMENT_NAME_2, BasicTypes.STRING_TYPE);
    assertAttributeDescriptor(featureMetacardType, ELEMENT_NAME_1, BasicTypes.GEO_TYPE);
}
Also used : XmlSchemaComplexContentExtension(org.apache.ws.commons.schema.XmlSchemaComplexContentExtension) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaComplexContent(org.apache.ws.commons.schema.XmlSchemaComplexContent) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) Test(org.junit.Test)

Example 3 with XmlSchemaSequence

use of org.apache.ws.commons.schema.XmlSchemaSequence in project ddf by codice.

the class FeatureMetacardType method processXmlSchemaParticle.

private void processXmlSchemaParticle(XmlSchemaParticle particle) {
    XmlSchemaSequence schemaSequence;
    if (particle instanceof XmlSchemaSequence) {
        schemaSequence = (XmlSchemaSequence) particle;
        List<XmlSchemaSequenceMember> schemaObjectCollection = schemaSequence.getItems();
        Iterator<XmlSchemaSequenceMember> iterator = schemaObjectCollection.iterator();
        while (iterator.hasNext()) {
            Object element = iterator.next();
            if (element instanceof XmlSchemaElement) {
                XmlSchemaElement innerElement = ((XmlSchemaElement) element);
                XmlSchemaType innerEleType = innerElement.getSchemaType();
                if (innerEleType instanceof XmlSchemaComplexType) {
                    processComplexType(innerElement);
                } else if (innerEleType instanceof XmlSchemaSimpleType) {
                    processSimpleType(innerElement);
                } else if (innerEleType == null) {
                    // Check if this is the GML location Property
                    processGmlType(innerElement);
                }
            }
        }
    }
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 4 with XmlSchemaSequence

use of org.apache.ws.commons.schema.XmlSchemaSequence in project tdi-studio-se by Talend.

the class ComponentBuilderTest method testBuildParameterFromTypes.

@Test
public void testBuildParameterFromTypes() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, WSDLException {
    ParameterInfo parameter = new ParameterInfo();
    String name = "parameter";
    String nameSpace = "http://parameter";
    parameter.setName(name);
    parameter.setNameSpace(nameSpace);
    ComponentBuilder cb = new ComponentBuilder();
    Field field = cb.getClass().getDeclaredField("allXmlSchemaType");
    field.setAccessible(true);
    List<XmlSchemaType> allXmlSchemaType = (List<XmlSchemaType>) field.get(cb);
    XmlSchema first = new XmlSchema();
    first.setId("first");
    XmlSchemaSimpleType xsst = new XmlSchemaSimpleType(first);
    xsst.setId("first");
    xsst.setName("first");
    xsst.setSourceURI("http://first");
    XmlSchema two = new XmlSchema();
    two.setId("two");
    two.setTargetNamespace(nameSpace);
    String nameSpaceTwo = "http://parameter";
    XmlSchemaComplexType xsc = new XmlSchemaComplexType(two);
    XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
    xmlSchemaSequence.setId("sequence");
    XmlSchemaElement xmlSchemaElement = new XmlSchemaElement();
    xmlSchemaElement.setSourceURI(nameSpaceTwo);
    xmlSchemaElement.setQName(new QName(nameSpaceTwo, "parameter"));
    xmlSchemaElement.setName(name);
    xmlSchemaSequence.getItems().add(xmlSchemaElement);
    xsc.setParticle(xmlSchemaSequence);
    xsc.setId("two");
    xsc.setName("parameter");
    XmlSchemaComplexContent contentModel = new XmlSchemaComplexContent();
    XmlSchemaComplexContentExtension xmlSchemaContent = new XmlSchemaComplexContentExtension();
    xmlSchemaContent.setId("two");
    xmlSchemaContent.setBaseTypeName(new QName(nameSpace, "two"));
    xmlSchemaContent.setSourceURI(nameSpaceTwo);
    contentModel.setSourceURI(nameSpace);
    contentModel.setContent(xmlSchemaContent);
    xsc.setContentModel(contentModel);
    allXmlSchemaType.add(xsst);
    allXmlSchemaType.add(xsc);
    Method m = cb.getClass().getDeclaredMethod("buileParameterFromTypes", new Class[] { String.class, String.class, ParameterInfo.class, int.class });
    m.setAccessible(true);
    m.invoke(cb, nameSpace, name, parameter, 5);
    ParameterInfo parameterInfo = parameter.getParameterInfos().get(0);
    Assert.assertNotNull(parameterInfo);
    Assert.assertEquals(nameSpace, parameterInfo.getNameSpace());
}
Also used : XmlSchemaComplexContentExtension(org.apache.ws.commons.schema.XmlSchemaComplexContentExtension) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) ParameterInfo(org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo) Method(java.lang.reflect.Method) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaComplexContent(org.apache.ws.commons.schema.XmlSchemaComplexContent) Field(java.lang.reflect.Field) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) List(java.util.List) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) ComponentBuilder(org.talend.designer.webservice.ws.wsdlutil.ComponentBuilder) Test(org.junit.Test)

Example 5 with XmlSchemaSequence

use of org.apache.ws.commons.schema.XmlSchemaSequence in project tomee by apache.

the class CommonsSchemaInfoBuilder method extractSoapArrayComponentType.

/**
     * Extract the nested component type of an Array from the XML Schema Type.
     *
     * @return the QName of the nested component type or null if the schema type can not be determined
     * @throws org.apache.openejb.OpenEJBException if the XML Schema Type can not represent an Array @param complexType
     */
private static QName extractSoapArrayComponentType(XmlSchemaComplexType complexType) {
    // Soap arrays are based on complex content restriction
    if (!isSoapArray(complexType)) {
        return null;
    }
    XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) complexType.getContentModel().getContent();
    //First, handle case that looks like this:
    // <complexType name="ArrayOfstring">
    //     <complexContent>
    //         <restriction base="soapenc:Array">
    //             <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
    //         </restriction>
    //     </complexContent>
    // </complexType>
    XmlSchemaObjectCollection attributes = restriction.getAttributes();
    for (Iterator iterator = attributes.getIterator(); iterator.hasNext(); ) {
        Object item = iterator.next();
        if (item instanceof XmlSchemaAttribute) {
            XmlSchemaAttribute attribute = (XmlSchemaAttribute) item;
            if (attribute.getRefName().equals(SOAP_ARRAY_TYPE)) {
                for (Attr attr : attribute.getUnhandledAttributes()) {
                    QName attQName = new QName(attr.getNamespaceURI(), attr.getLocalName());
                    if (WSDL_ARRAY_TYPE.equals(attQName)) {
                        // value is a namespace prefixed xsd type
                        String value = attr.getValue();
                        // extract local part
                        int pos = value.lastIndexOf(":");
                        QName componentType;
                        if (pos < 0) {
                            componentType = new QName("", value);
                        } else {
                            String localPart = value.substring(pos + 1);
                            // resolve the namespace prefix
                            String prefix = value.substring(0, pos);
                            String namespace = getNamespaceForPrefix(prefix, attr.getOwnerElement());
                            componentType = new QName(namespace, localPart);
                        }
                        log.debug("determined component type from element type");
                        return componentType;
                    }
                }
            }
        }
    }
    // If that didn't work, try to handle case like this:
    // <complexType name="ArrayOfstring1">
    //     <complexContent>
    //         <restriction base="soapenc:Array">
    //             <sequence>
    //                 <element name="string1" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
    //             </sequence>
    //         </restriction>
    //     </complexContent>
    // </complexType>
    XmlSchemaParticle particle = restriction.getParticle();
    if (particle instanceof XmlSchemaSequence) {
        XmlSchemaSequence sequence = (XmlSchemaSequence) particle;
        if (sequence.getItems().getCount() != 1) {
            throw new IllegalArgumentException("more than one element inside array definition: " + complexType);
        }
        XmlSchemaObject item = sequence.getItems().getItem(0);
        if (item instanceof XmlSchemaElement) {
            XmlSchemaElement element = (XmlSchemaElement) item;
            QName componentType = element.getSchemaTypeName();
            log.debug("determined component type from element type");
            return componentType;
        }
    }
    return null;
}
Also used : QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) Attr(org.w3c.dom.Attr) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) Iterator(java.util.Iterator) XmlSchemaComplexContentRestriction(org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection)

Aggregations

XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)6 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)6 QName (javax.xml.namespace.QName)5 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)5 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)4 XmlSchema (org.apache.ws.commons.schema.XmlSchema)3 XmlSchemaComplexContent (org.apache.ws.commons.schema.XmlSchemaComplexContent)3 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)3 Test (org.junit.Test)3 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)2 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)2 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 List (java.util.List)1 AegisType (org.apache.cxf.aegis.type.AegisType)1 XmlSchemaComplexContentRestriction (org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction)1 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)1 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)1