Search in sources :

Example 31 with XmlSchemaElement

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

the class CommonsSchemaInfoBuilder method getNestedElements.

private static List<XmlSchemaElement> getNestedElements(XmlSchemaComplexType complexType) {
    List<XmlSchemaElement> elements = new ArrayList<XmlSchemaElement>();
    XmlSchemaParticle particle = complexType.getParticle();
    if (particle instanceof XmlSchemaElement) {
        XmlSchemaElement element = (XmlSchemaElement) particle;
        elements.add(element);
    } else if (particle instanceof XmlSchemaGroupBase && !(particle instanceof XmlSchemaChoice)) {
        XmlSchemaGroupBase groupBase = (XmlSchemaGroupBase) particle;
        for (Iterator iterator = groupBase.getItems().getIterator(); iterator.hasNext(); ) {
            XmlSchemaParticle child = (XmlSchemaParticle) iterator.next();
            if (child instanceof XmlSchemaElement) {
                XmlSchemaElement element = (XmlSchemaElement) child;
                elements.add(element);
            }
        }
    } else {
    // ignore all other types... you can have these other types, but JAX-RPC doesn't support them
    }
    return elements;
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaGroupBase(org.apache.ws.commons.schema.XmlSchemaGroupBase)

Example 32 with XmlSchemaElement

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

Example 33 with XmlSchemaElement

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

the class CommonsSchemaInfoBuilder method addType.

private void addType(QName typeQName, XmlSchemaType type) {
    // skip built in xml schema types
    if (XML_SCHEMA_NS.equals(typeQName.getNamespaceURI())) {
        return;
    }
    XmlTypeInfo typeInfo = createXmlTypeInfo(typeQName, type);
    xmlTypes.put(typeQName, typeInfo);
    if (type instanceof XmlSchemaComplexType) {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
        // process elements nested inside of this element
        List<XmlSchemaElement> elements = getNestedElements(complexType);
        for (XmlSchemaElement element : elements) {
            addNestedElement(element, typeInfo);
        }
    }
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 34 with XmlSchemaElement

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

the class TestGenericFeatureConverter method buildElementMap.

private Map<QName, XmlSchemaElement> buildElementMap(XmlSchema schema) {
    Map<QName, XmlSchemaElement> elementMap = new HashMap<>();
    elementMap.put(new QName(ID_ELEMENT), buildSchemaElement(ID_ELEMENT, schema, Constants.XSD_LONG));
    elementMap.put(new QName(VERSION_ELEMENT), buildSchemaElement(VERSION_ELEMENT, schema, Constants.XSD_LONG));
    elementMap.put(new QName(END_DATE_ELEMENT), buildSchemaElement(END_DATE_ELEMENT, schema, Constants.XSD_DATETIME));
    elementMap.put(new QName(FILENAME_ELEMENT), buildSchemaElement(FILENAME_ELEMENT, schema, Constants.XSD_STRING));
    elementMap.put(new QName(HEIGHT_ELEMENT), buildSchemaElement(HEIGHT_ELEMENT, schema, Constants.XSD_LONG));
    elementMap.put(new QName(INDEX_ID_ELEMENT), buildSchemaElement(INDEX_ID_ELEMENT, schema, Constants.XSD_STRING));
    elementMap.put(new QName(OTHER_TAGS_XML_ELEMENT), buildSchemaElement(OTHER_TAGS_XML_ELEMENT, schema, Constants.XSD_STRING));
    elementMap.put(new QName(REPOSITORY_ID_ELEMENT), buildSchemaElement(REPOSITORY_ID_ELEMENT, schema, Constants.XSD_LONG));
    elementMap.put(new QName(START_DATE_ELEMENT), buildSchemaElement(START_DATE_ELEMENT, schema, Constants.XSD_DATETIME));
    elementMap.put(new QName(STYLE_ID_ELEMENT), buildSchemaElement(STYLE_ID_ELEMENT, schema, Constants.XSD_DECIMAL));
    elementMap.put(new QName(WIDTH_ELEMENT), buildSchemaElement(WIDTH_ELEMENT, schema, Constants.XSD_LONG));
    XmlSchemaElement gmlElement = new XmlSchemaElement(schema, true);
    gmlElement.setSchemaType(new XmlSchemaComplexType(schema, false));
    gmlElement.setSchemaTypeName(new QName(Wfs10Constants.GML_NAMESPACE, GML));
    gmlElement.setName(GROUND_GEOM_ELEMENT);
    elementMap.put(new QName(GROUND_GEOM_ELEMENT), gmlElement);
    return elementMap;
}
Also used : HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 35 with XmlSchemaElement

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

the class FeatureMetacardTypeTest method testfeatureMetacardTypeFindDateProperties.

@Test
public void testfeatureMetacardTypeFindDateProperties() {
    XmlSchema schema = new XmlSchema();
    XmlSchemaElement dateElement = new XmlSchemaElement(schema, true);
    dateElement.setSchemaType(new XmlSchemaSimpleType(schema, false));
    dateElement.setSchemaTypeName(Constants.XSD_DATE);
    dateElement.setName(ELEMENT_NAME_1);
    XmlSchemaElement dateTimeElement = new XmlSchemaElement(schema, true);
    dateTimeElement.setSchemaType(new XmlSchemaSimpleType(schema, false));
    dateTimeElement.setSchemaTypeName(Constants.XSD_DATETIME);
    dateTimeElement.setName(ELEMENT_NAME_2);
    schema.getElements().put(new QName(ELEMENT_NAME_1), dateElement);
    schema.getElements().put(new QName(ELEMENT_NAME_2), dateTimeElement);
    FeatureMetacardType featureMetacardType = new FeatureMetacardType(schema, FEATURE_TYPE, NON_QUERYABLE_PROPS, Wfs10Constants.GML_NAMESPACE);
    assertAttributeDescriptor(featureMetacardType, ELEMENT_NAME_1, BasicTypes.DATE_TYPE);
    assertAttributeDescriptor(featureMetacardType, ELEMENT_NAME_2, BasicTypes.DATE_TYPE);
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) QName(javax.xml.namespace.QName) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) Test(org.junit.Test)

Aggregations

XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)52 QName (javax.xml.namespace.QName)38 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)36 XmlSchema (org.apache.ws.commons.schema.XmlSchema)35 Test (org.junit.Test)33 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)32 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)23 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)7 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)6 Iterator (java.util.Iterator)6 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)6 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)6 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)6 ParameterInfo (org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo)6 ArrayList (java.util.ArrayList)5 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)5 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)4 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)4 HashMap (java.util.HashMap)3 XmlSchemaAny (org.apache.ws.commons.schema.XmlSchemaAny)3