Search in sources :

Example 21 with XmlSchemaSimpleType

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

the class ComponentBuilder method buildParameterFromElements.

private void buildParameterFromElements(String partElement, ParameterInfo parameterRoot, int ioOrRecursion) {
    // XmlSchemaObjectTable elements = xmlSchema.getElements();
    if (ioOrRecursion < 3) {
        parametersName.clear();
        parametersName.add(parameterRoot.getName());
    } else if (ioOrRecursion == 3) {
        parametersName.add(parameterRoot.getName());
    }
    Iterator elementsItr = allXmlSchemaElement.iterator();
    if (partElement != null) {
        while (elementsItr.hasNext()) {
            XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) elementsItr.next();
            if (partElement.equals(xmlSchemaElement.getName())) {
                // parameter.setName(partName);
                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 xmlSchemaObjectCollection = xmlSchemaGroupBase.getItems();
                            if (xmlSchemaObjectCollection != null) {
                                buildParameterFromCollection(xmlSchemaObjectCollection, parameterRoot, ioOrRecursion);
                            }
                        } else if (xmlSchemaElement.getSchemaTypeName() != null) {
                            String paraTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
                            String paraTypeNamespace = xmlSchemaElement.getSchemaTypeName().getNamespaceURI();
                            if (paraTypeName != null) {
                                parameterRoot.setType(paraTypeName);
                                buileParameterFromTypes(paraTypeNamespace, paraTypeName, parameterRoot, ioOrRecursion);
                            }
                        }
                    } else if (xmlSchemaElement.getSchemaType() instanceof XmlSchemaSimpleType) {
                        XmlSchemaSimpleType xmlSchemaSimpleType = (XmlSchemaSimpleType) xmlSchemaElement.getSchemaType();
                        String typeName = xmlSchemaSimpleType.getName();
                        if (typeName != null && typeName.equals("anyType")) {
                            ParameterInfo parameterSon = new ParameterInfo();
                            parameterSon.setName("anyType");
                            parameterSon.setParent(parameterRoot);
                            parameterRoot.getParameterInfos().add(parameterSon);
                        }
                        parameterRoot.setType(typeName);
                    }
                } else if (xmlSchemaElement.getSchemaTypeName() != null) {
                    String paraTypeName = xmlSchemaElement.getSchemaTypeName().getLocalPart();
                    String paraTypeNamespace = xmlSchemaElement.getSchemaTypeName().getNamespaceURI();
                    if (paraTypeName != null) {
                        parameterRoot.setType(paraTypeName);
                        buileParameterFromTypes(paraTypeNamespace, paraTypeName, parameterRoot, ioOrRecursion);
                    }
                }
            }
        }
    }
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) Iterator(java.util.Iterator) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) ParameterInfo(org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo) XmlSchemaGroupBase(org.apache.ws.commons.schema.XmlSchemaGroupBase) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection)

Example 22 with XmlSchemaSimpleType

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

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

the class AllTypeDialog method buileParameterFromTypes.

private void buileParameterFromTypes(String paraType, ParameterInfo parameter) {
    for (int i = 0; i < allXmlSchemaType.size(); i++) {
        XmlSchemaType type = allXmlSchemaType.get(i);
        String typeName = type.getName();
        if (paraType.equals(typeName)) {
            if (type instanceof XmlSchemaComplexType) {
                XmlSchemaComplexType xmlSchemaComplexType = (XmlSchemaComplexType) type;
                XmlSchemaParticle xmlSchemaParticle = xmlSchemaComplexType.getParticle();
                XmlSchemaObjectCollection xmlSchemaObjectCollection = null;
                if (xmlSchemaParticle == null && xmlSchemaComplexType.getContentModel() != null) {
                    Object obj = xmlSchemaComplexType.getContentModel().getContent();
                    if (obj instanceof XmlSchemaComplexContentExtension) {
                        XmlSchemaComplexContentExtension xscce = (XmlSchemaComplexContentExtension) obj;
                        if (xscce.getBaseTypeName() != null) {
                            buileParameterFromTypes(xscce.getBaseTypeName().getLocalPart(), parameter);
                        }
                        if (xscce != null) {
                            xmlSchemaParticle = xscce.getParticle();
                        }
                        if (xmlSchemaParticle instanceof XmlSchemaGroupBase) {
                            XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaParticle;
                            xmlSchemaObjectCollection = xmlSchemaGroupBase.getItems();
                        }
                    } else if (obj instanceof XmlSchemaComplexContentRestriction) {
                        XmlSchemaComplexContentRestriction xsccr = (XmlSchemaComplexContentRestriction) obj;
                        xmlSchemaObjectCollection = xsccr.getAttributes();
                    }
                } else if (xmlSchemaParticle instanceof XmlSchemaGroupBase) {
                    XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaParticle;
                    xmlSchemaObjectCollection = xmlSchemaGroupBase.getItems();
                }
                if (xmlSchemaObjectCollection != null && xmlSchemaObjectCollection.getCount() > 0) {
                    buildParameterFromCollection(xmlSchemaObjectCollection, parameter);
                }
            } else if (type instanceof XmlSchemaSimpleType) {
            }
            break;
        }
    }
}
Also used : XmlSchemaComplexContentExtension(org.apache.ws.commons.schema.XmlSchemaComplexContentExtension) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaComplexContentRestriction(org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaGroupBase(org.apache.ws.commons.schema.XmlSchemaGroupBase) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection)

Example 24 with XmlSchemaSimpleType

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

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

the class CommonsSchemaInfoBuilder method createXmlTypeInfo.

public static XmlTypeInfo createXmlTypeInfo(QName qname, XmlSchemaType type) {
    if (qname == null)
        throw new NullPointerException("qname is null");
    if (type == null)
        throw new NullPointerException("type is null");
    XmlTypeInfo typeInfo = new XmlTypeInfo();
    typeInfo.qname = qname;
    typeInfo.anonymous = qname.getLocalPart().indexOf('>') >= 0;
    if (type instanceof XmlSchemaSimpleType) {
        XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
        XmlSchemaSimpleTypeContent content = simpleType.getContent();
        if (content instanceof XmlSchemaSimpleTypeList) {
            XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList) content;
            typeInfo.simpleBaseType = list.getItemType().getQName();
            // this is a list
            typeInfo.listType = true;
        } else if (content instanceof XmlSchemaSimpleTypeRestriction) {
            XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
            typeInfo.simpleBaseType = restriction.getBaseTypeName();
            // is this an enumeration?
            for (Iterator iterator = restriction.getFacets().getIterator(); iterator.hasNext(); ) {
                if (iterator.next() instanceof XmlSchemaEnumerationFacet) {
                    typeInfo.enumType = true;
                    break;
                }
            }
        }
    } else if (type instanceof XmlSchemaComplexType) {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
        // SOAP array component type
        typeInfo.arrayComponentType = extractSoapArrayComponentType(complexType);
        // process attributes (skip soap arrays which have non-mappable attributes)
        if (!isSoapArray(complexType)) {
            XmlSchemaObjectCollection attributes = complexType.getAttributes();
            for (Iterator iterator = attributes.getIterator(); iterator.hasNext(); ) {
                Object item = iterator.next();
                if (item instanceof XmlSchemaAttribute) {
                    XmlSchemaAttribute attribute = (XmlSchemaAttribute) item;
                    Object old = typeInfo.attributes.put(attribute.getQName().getLocalPart(), attribute.getSchemaTypeName());
                    if (old != null) {
                        throw new IllegalArgumentException("Complain to your expert group member, spec does not support attributes with the same local name and differing namespaces: original: " + old + ", duplicate local name: " + attribute);
                    }
                }
            }
        }
    } else {
        log.warn("Unknown schema type class " + typeInfo.getClass().getName());
    }
    return typeInfo;
}
Also used : XmlSchemaSimpleTypeList(org.apache.ws.commons.schema.XmlSchemaSimpleTypeList) XmlSchemaSimpleTypeRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction) XmlSchemaSimpleTypeContent(org.apache.ws.commons.schema.XmlSchemaSimpleTypeContent) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) Iterator(java.util.Iterator) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaEnumerationFacet(org.apache.ws.commons.schema.XmlSchemaEnumerationFacet) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection)

Aggregations

XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)41 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)36 XmlSchema (org.apache.ws.commons.schema.XmlSchema)28 Test (org.junit.Test)27 QName (javax.xml.namespace.QName)26 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)26 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)16 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)9 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)8 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)8 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)7 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)7 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)6 ParameterInfo (org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo)6 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)4 Iterator (java.util.Iterator)4 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)4 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)4 ArrayList (java.util.ArrayList)3 XmlSchemaAny (org.apache.ws.commons.schema.XmlSchemaAny)3