Search in sources :

Example 31 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 32 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 33 with XmlSchemaSimpleType

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

the class AllTypeDialog method initSimpleType.

private void initSimpleType() throws WSDLException, URISyntaxException {
    String url = URLValue;
    XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
    WSDLFactory wsdlFactory = WSDLFactory.newInstance();
    WSDLReader newWSDLReader = wsdlFactory.newWSDLReader();
    newWSDLReader.setFeature(com.ibm.wsdl.Constants.FEATURE_VERBOSE, false);
    URI wsdlURI = new URI(url);
    Definition definition = newWSDLReader.readWSDL(url);
    java.util.List<ExtensibilityElement> extensibilityElements = definition.getTypes().getExtensibilityElements();
    String tmpTNName = "";
    int tmpCount = 0;
    for (ExtensibilityElement el : extensibilityElements) {
        if (el instanceof Schema) {
            Schema schema = (Schema) el;
            // for bug 8674
            // set base uri for relative path in schemaLocation.
            schemaCollection.setBaseUri(schema.getDocumentBaseURI());
            if (schema.getElement().getAttributeNode("targetNamespace") == null) {
                tmpTNName = schema.getDocumentBaseURI() + "#type" + tmpCount;
                schemaCollection.read(schema.getElement(), tmpTNName);
                tmpCount++;
            } else {
                schemaCollection.read(schema.getElement());
            }
        }
    }
    Map namespaces = definition.getNamespaces();
    // System.out.println(namespaces);
    XmlSchema[] schemas = schemaCollection.getXmlSchemas();
    java.util.List<String> labelList = new ArrayList<String>();
    for (int i = 0; i < schemas.length; i++) {
        XmlSchema schema = schemas[i];
        XmlSchemaObjectTable types = schema.getSchemaTypes();
        Iterator it = types.getValues();
        while (it.hasNext()) {
            XmlSchemaType type = (XmlSchemaType) it.next();
            if (type instanceof XmlSchemaSimpleType) {
                XmlSchemaSimpleType t = (XmlSchemaSimpleType) type;
                String label = "simpletype:" + t.getName();
                if (!labelList.contains(label)) {
                    labelList.add(label);
                    labelAndNameSpaceMap.put(label, t.getQName().toString());
                }
            }
        }
    }
    allXMLSimpleTypeName = new String[labelList.size()];
    for (int i = 0; i < labelList.size(); i++) {
        allXMLSimpleTypeName[i] = labelList.get(i);
    }
}
Also used : XmlSchemaObjectTable(org.apache.ws.commons.schema.XmlSchemaObjectTable) XmlSchema(org.apache.ws.commons.schema.XmlSchema) Schema(javax.wsdl.extensions.schema.Schema) Definition(javax.wsdl.Definition) ArrayList(java.util.ArrayList) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) URI(java.net.URI) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) WSDLFactory(javax.wsdl.factory.WSDLFactory) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) WSDLReader(javax.wsdl.xml.WSDLReader)

Example 34 with XmlSchemaSimpleType

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

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

XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)60 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)44 QName (javax.xml.namespace.QName)38 XmlSchema (org.apache.ws.commons.schema.XmlSchema)31 Test (org.junit.Test)27 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)26 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)20 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)13 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)9 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)9 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)8 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)8 XmlSchemaSimpleTypeRestriction (org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction)8 ArrayList (java.util.ArrayList)6 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 List (java.util.List)4 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)4