Search in sources :

Example 1 with XmlSchemaAttribute

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

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

the class ComponentBuilder method buildParameterFromCollection.

private void buildParameterFromCollection(XmlSchemaObjectCollection xmlSchemaObjectCollection, ParameterInfo parameter, int ioOrRecursion) {
    // XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) xmlSchemaParticle;
    // XmlSchemaObjectCollection xmlSchemaObjectCollection = xmlSchemaSequence.getItems();
    int count = xmlSchemaObjectCollection.getCount();
    for (int j = 0; j < count; j++) {
        XmlSchemaObject xmlSchemaObject = xmlSchemaObjectCollection.getItem(j);
        if (xmlSchemaObject instanceof XmlSchemaGroupBase) {
            XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaObject;
            XmlSchemaObjectCollection items = xmlSchemaGroupBase.getItems();
            if (items != null) {
                buildParameterFromCollection(items, parameter, ioOrRecursion);
            }
        } else if (xmlSchemaObject instanceof XmlSchemaAny) {
            ParameterInfo parameterSon = new ParameterInfo();
            parameterSon.setName("_content_");
            parameterSon.setParent(parameter);
            parameter.getParameterInfos().add(parameterSon);
        } else if (xmlSchemaObject instanceof XmlSchemaElement) {
            XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) xmlSchemaObject;
            String elementName = xmlSchemaElement.getName();
            ParameterInfo parameterSon = new ParameterInfo();
            parameterSon.setName(elementName);
            parameterSon.setParent(parameter);
            if (((XmlSchemaElement) xmlSchemaObject).getQName() != null) {
                parameterSon.setNameSpace(((XmlSchemaElement) xmlSchemaObject).getQName().getNamespaceURI());
            }
            Long min = xmlSchemaElement.getMinOccurs();
            Long max = xmlSchemaElement.getMaxOccurs();
            if (max - min > 1) {
                parameterSon.setArraySize(-1);
                parameterSon.setIndex("*");
            }
            parameter.getParameterInfos().add(parameterSon);
            Boolean isHave = false;
            if (!parametersName.isEmpty() && parameterSon.getName() != null) {
                for (int p = 0; p < parametersName.size(); p++) {
                    if (parameterSon.getName().equals(parametersName.get(p))) {
                        isHave = true;
                    }
                }
            }
            // }
            if (xmlSchemaElement.getSchemaTypeName() != null) {
                String elementTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
                String elementTypeNamespace = xmlSchemaElement.getSchemaTypeName().getNamespaceURI();
                if (elementTypeName != null && elementTypeName.equals("anyType")) {
                    parameterSon.setName(xmlSchemaElement.getName() + ":anyType");
                }
                parameterSon.setType(elementTypeName);
                parameterSon.setNameSpace(xmlSchemaElement.getQName().getNamespaceURI());
                if (!isHave && !WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
                    buileParameterFromTypes(elementTypeNamespace, elementTypeName, parameterSon, ioOrRecursion);
                }
            } else if (xmlSchemaElement.getSchemaType() != null) {
                if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaComplexType) {
                    XmlSchemaComplexType xmlElementComplexType = (XmlSchemaComplexType) xmlSchemaElement.getSchemaType();
                    XmlSchemaParticle xmlSchemaParticle = xmlElementComplexType.getParticle();
                    if (xmlSchemaParticle instanceof XmlSchemaGroupBase) {
                        XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaParticle;
                        XmlSchemaObjectCollection childCollection = xmlSchemaGroupBase.getItems();
                        if (childCollection != null && !isHave) {
                            buildParameterFromCollection(childCollection, parameterSon, ioOrRecursion);
                        }
                    } else if (xmlSchemaElement.getSchemaTypeName() != null) {
                        String paraTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
                        String paraTypeNamespace = xmlSchemaElement.getSchemaTypeName().getNamespaceURI();
                        if (paraTypeName != null && !isHave) {
                            parameter.setType(paraTypeName);
                            buileParameterFromTypes(paraTypeNamespace, paraTypeName, parameterSon, ioOrRecursion);
                        }
                    }
                } else if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaSimpleType) {
                    XmlSchemaSimpleType xmlSchemaSimpleType = (XmlSchemaSimpleType) xmlSchemaElement.getSchemaType();
                    String typeName = xmlSchemaSimpleType.getName();
                    if (typeName != null && typeName.equals("anyType")) {
                        ParameterInfo pSon = new ParameterInfo();
                        pSon.setName("anyType");
                        pSon.setParent(parameter);
                        parameter.getParameterInfos().add(pSon);
                    }
                    parameter.setType(typeName);
                }
            } else if (xmlSchemaElement.getRefName() != null) {
                String elementTypeName = xmlSchemaElement.getRefName().getLocalPart();
                if (!isHave && !WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
                    buildParameterFromElements(elementTypeName, parameterSon, ioOrRecursion);
                }
            }
        } else if (xmlSchemaObject instanceof XmlSchemaAttribute) {
            XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute) xmlSchemaObject;
            String elementName = xmlSchemaAttribute.getName();
            ParameterInfo parameterSon = new ParameterInfo();
            parameterSon.setName(elementName);
            parameterSon.setParent(parameter);
            parameter.getParameterInfos().add(parameterSon);
            Boolean isHave = false;
            if (!parametersName.isEmpty() && parameterSon.getName() != null) {
                for (int p = 0; p < parametersName.size(); p++) {
                    if (parameterSon.getName().equals(parametersName.get(p))) {
                        isHave = true;
                    }
                }
            }
            if (xmlSchemaAttribute.getSchemaTypeName() != null) {
                String elementTypeName = xmlSchemaAttribute.getSchemaTypeName().getLocalPart();
                String elementTypeNamespace = xmlSchemaAttribute.getSchemaTypeName().getNamespaceURI();
                parameterSon.setType(elementTypeName);
                if (!isHave && !WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
                    buileParameterFromTypes(elementTypeNamespace, elementTypeName, parameterSon, ioOrRecursion);
                }
            } else if (xmlSchemaAttribute.getRefName() != null) {
                String refName = xmlSchemaAttribute.getRefName().getLocalPart();
                parameterSon.setType(refName);
                if (!isHave) {
                    buildParameterFromElements(refName, parameterSon, ioOrRecursion);
                }
            }
        }
    }
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaAny(org.apache.ws.commons.schema.XmlSchemaAny) ParameterInfo(org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo) XmlSchemaGroupBase(org.apache.ws.commons.schema.XmlSchemaGroupBase) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection)

Example 3 with XmlSchemaAttribute

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

the class AllTypeDialog method buildParameterFromCollection.

private void buildParameterFromCollection(XmlSchemaObjectCollection xmlSchemaObjectCollection, ParameterInfo parameter) {
    // XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) xmlSchemaParticle;
    // XmlSchemaObjectCollection xmlSchemaObjectCollection = xmlSchemaSequence.getItems();
    int count = xmlSchemaObjectCollection.getCount();
    for (int j = 0; j < count; j++) {
        XmlSchemaObject xmlSchemaObject = xmlSchemaObjectCollection.getItem(j);
        if (xmlSchemaObject instanceof XmlSchemaGroupBase) {
            XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaObject;
            XmlSchemaObjectCollection items = xmlSchemaGroupBase.getItems();
            if (items != null) {
                buildParameterFromCollection(items, parameter);
            }
        } else if (xmlSchemaObject instanceof XmlSchemaAny) {
            ParameterInfo parameterSon = new ParameterInfo();
            parameterSon.setName("_content_");
            parameterSon.setParent(parameter);
            parameter.getParameterInfos().add(parameterSon);
        } else if (xmlSchemaObject instanceof XmlSchemaElement) {
            XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) xmlSchemaObject;
            String elementName = xmlSchemaElement.getName();
            ParameterInfo parameterSon = new ParameterInfo();
            parameterSon.setName(elementName);
            parameterSon.setParent(parameter);
            Long min = xmlSchemaElement.getMinOccurs();
            Long max = xmlSchemaElement.getMaxOccurs();
            if (max - min > 1) {
                parameterSon.setArraySize(-1);
                parameterSon.setIndex("*");
            }
            parameter.getParameterInfos().add(parameterSon);
            if (xmlSchemaElement.getSchemaTypeName() != null) {
                String elementTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
                if (elementTypeName != null && elementTypeName.equals("anyType")) {
                    parameterSon.setName(xmlSchemaElement.getName() + ":anyType");
                }
                parameterSon.setType(elementTypeName);
                if (!WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
                    buileParameterFromTypes(elementTypeName, parameterSon);
                }
            } else if (xmlSchemaElement.getSchemaType() != null) {
                if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaComplexType) {
                    XmlSchemaComplexType xmlElementComplexType = (XmlSchemaComplexType) xmlSchemaElement.getSchemaType();
                    XmlSchemaParticle xmlSchemaParticle = xmlElementComplexType.getParticle();
                    if (xmlSchemaParticle instanceof XmlSchemaGroupBase) {
                        XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaParticle;
                        XmlSchemaObjectCollection childCollection = xmlSchemaGroupBase.getItems();
                        if (childCollection != null) {
                            buildParameterFromCollection(childCollection, parameterSon);
                        }
                    } else if (xmlSchemaElement.getSchemaTypeName() != null) {
                        String paraTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
                        if (paraTypeName != null) {
                            parameter.setType(paraTypeName);
                            buileParameterFromTypes(paraTypeName, parameterSon);
                        }
                    }
                } else if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaSimpleType) {
                    XmlSchemaSimpleType xmlSchemaSimpleType = (XmlSchemaSimpleType) xmlSchemaElement.getSchemaType();
                    String typeName = xmlSchemaSimpleType.getName();
                    if (typeName != null && typeName.equals("anyType")) {
                        ParameterInfo pSon = new ParameterInfo();
                        pSon.setName(xmlSchemaElement.getName() + "(anyType)");
                        pSon.setParent(parameter);
                        parameter.getParameterInfos().add(pSon);
                    }
                    parameter.setType(typeName);
                }
            } else if (xmlSchemaElement.getRefName() != null) {
                String elementTypeName = xmlSchemaElement.getRefName().getLocalPart();
                if (!WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
                    buildParameterFromElements(elementTypeName, parameterSon);
                }
            }
        } else if (xmlSchemaObject instanceof XmlSchemaAttribute) {
            XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute) xmlSchemaObject;
            String elementName = xmlSchemaAttribute.getName();
            ParameterInfo parameterSon = new ParameterInfo();
            parameterSon.setName(elementName);
            parameterSon.setParent(parameter);
            parameter.getParameterInfos().add(parameterSon);
            if (xmlSchemaAttribute.getSchemaTypeName() != null) {
                String elementTypeName = xmlSchemaAttribute.getSchemaTypeName().getLocalPart();
                parameterSon.setType(elementTypeName);
                if (!WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
                    buileParameterFromTypes(elementTypeName, parameterSon);
                }
            } else if (xmlSchemaAttribute.getRefName() != null) {
                String refName = xmlSchemaAttribute.getRefName().getLocalPart();
                parameterSon.setType(refName);
            }
        }
    }
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaAny(org.apache.ws.commons.schema.XmlSchemaAny) ParameterInfo(org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo) XmlSchemaGroupBase(org.apache.ws.commons.schema.XmlSchemaGroupBase) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection)

Example 4 with XmlSchemaAttribute

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

the class ComponentBuilder method buildParameterFromCollection2.

private void buildParameterFromCollection2(XmlSchemaObjectCollection xmlSchemaObjectCollection, ParameterInfo parameter, int ioOrRecursion) {
    // XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) xmlSchemaParticle;
    // XmlSchemaObjectCollection xmlSchemaObjectCollection = xmlSchemaSequence.getItems();
    int count = xmlSchemaObjectCollection.getCount();
    for (int j = 0; j < count; j++) {
        XmlSchemaObject xmlSchemaObject = xmlSchemaObjectCollection.getItem(j);
        if (xmlSchemaObject instanceof XmlSchemaGroupBase) {
            XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaObject;
            XmlSchemaObjectCollection items = xmlSchemaGroupBase.getItems();
            if (items != null) {
                buildParameterFromCollection(items, parameter, ioOrRecursion);
            }
        } else if (xmlSchemaObject instanceof XmlSchemaAny) {
            ParameterInfo parameterSon = new ParameterInfo();
            parameterSon.setName("_content_");
            parameterSon.setParent(parameter);
            parameter.getParameterInfos().add(parameterSon);
        } else if (xmlSchemaObject instanceof XmlSchemaElement) {
            XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) xmlSchemaObject;
            String elementName = xmlSchemaElement.getName();
            ParameterInfo parameterSon = new ParameterInfo();
            parameterSon.setName(elementName);
            parameterSon.setParent(parameter);
            Long min = xmlSchemaElement.getMinOccurs();
            Long max = xmlSchemaElement.getMaxOccurs();
            if (max - min > 1) {
                parameterSon.setArraySize(-1);
                parameterSon.setIndex("*");
            }
            parameter.getParameterInfos().add(parameterSon);
            Boolean isHave = false;
            if (!parametersName.isEmpty() && parameterSon.getName() != null) {
                for (int p = 0; p < parametersName.size(); p++) {
                    if (parameterSon.getName().equals(parametersName.get(p))) {
                        isHave = true;
                    }
                }
            }
            // }
            if (xmlSchemaElement.getSchemaTypeName() != null) {
                String elementTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
                parameterSon.setType(elementTypeName);
                if (!isHave && !WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
                    buileParameterFromTypes2(elementTypeName, parameterSon, ioOrRecursion);
                }
            } else if (xmlSchemaElement.getSchemaType() != null) {
                if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaComplexType) {
                    XmlSchemaComplexType xmlElementComplexType = (XmlSchemaComplexType) xmlSchemaElement.getSchemaType();
                    XmlSchemaParticle xmlSchemaParticle = xmlElementComplexType.getParticle();
                    if (xmlSchemaParticle instanceof XmlSchemaGroupBase) {
                        XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaParticle;
                        XmlSchemaObjectCollection childCollection = xmlSchemaGroupBase.getItems();
                        if (childCollection != null && !isHave) {
                            buildParameterFromCollection(childCollection, parameterSon, ioOrRecursion);
                        }
                    } else if (xmlSchemaElement.getSchemaTypeName() != null) {
                        String paraTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
                        String paraTypeNamespace = xmlSchemaElement.getSchemaTypeName().getNamespaceURI();
                        if (paraTypeName != null && !isHave) {
                            parameter.setType(paraTypeName);
                            buileParameterFromTypes(paraTypeNamespace, paraTypeName, parameterSon, ioOrRecursion);
                        }
                    }
                } else if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaSimpleType) {
                    XmlSchemaSimpleType xmlSchemaSimpleType = (XmlSchemaSimpleType) xmlSchemaElement.getSchemaType();
                    String typeName = xmlSchemaSimpleType.getName();
                    parameter.setType(typeName);
                }
            } else if (xmlSchemaElement.getRefName() != null) {
                String elementTypeName = xmlSchemaElement.getRefName().getLocalPart();
                if (!isHave && !WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
                    buildParameterFromElements(elementTypeName, parameterSon, ioOrRecursion);
                }
            }
        } else if (xmlSchemaObject instanceof XmlSchemaAttribute) {
            XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute) xmlSchemaObject;
            String elementName = xmlSchemaAttribute.getName();
            ParameterInfo parameterSon = new ParameterInfo();
            parameterSon.setName(elementName);
            parameterSon.setParent(parameter);
            parameter.getParameterInfos().add(parameterSon);
            Boolean isHave = false;
            if (!parametersName.isEmpty() && parameterSon.getName() != null) {
                for (int p = 0; p < parametersName.size(); p++) {
                    if (parameterSon.getName().equals(parametersName.get(p))) {
                        isHave = true;
                    }
                }
            }
            if (xmlSchemaAttribute.getSchemaTypeName() != null) {
                String elementTypeName = xmlSchemaAttribute.getSchemaTypeName().getLocalPart();
                String elementTypeNamespace = xmlSchemaAttribute.getSchemaTypeName().getNamespaceURI();
                parameterSon.setType(elementTypeName);
                if (!isHave && !WsdlTypeUtil.isJavaBasicType(elementTypeName)) {
                    buileParameterFromTypes(elementTypeNamespace, elementTypeName, parameterSon, ioOrRecursion);
                }
            } else if (xmlSchemaAttribute.getRefName() != null) {
                String refName = xmlSchemaAttribute.getRefName().getLocalPart();
                parameterSon.setType(refName);
                if (!isHave) {
                    buildParameterFromElements(refName, parameterSon, ioOrRecursion);
                }
            }
        }
    }
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaAny(org.apache.ws.commons.schema.XmlSchemaAny) ParameterInfo(org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo) XmlSchemaGroupBase(org.apache.ws.commons.schema.XmlSchemaGroupBase) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection)

Example 5 with XmlSchemaAttribute

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

XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)6 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)5 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)5 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)5 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)5 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)4 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)4 XmlSchemaAny (org.apache.ws.commons.schema.XmlSchemaAny)3 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)3 ParameterInfo (org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo)3 Iterator (java.util.Iterator)2 QName (javax.xml.namespace.QName)2 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)2 AegisType (org.apache.cxf.aegis.type.AegisType)1 XmlSchemaComplexContentRestriction (org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction)1 XmlSchemaEnumerationFacet (org.apache.ws.commons.schema.XmlSchemaEnumerationFacet)1 XmlSchemaSimpleTypeContent (org.apache.ws.commons.schema.XmlSchemaSimpleTypeContent)1 XmlSchemaSimpleTypeList (org.apache.ws.commons.schema.XmlSchemaSimpleTypeList)1 XmlSchemaSimpleTypeRestriction (org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction)1 Optional (org.qi4j.api.common.Optional)1