Search in sources :

Example 16 with XmlSchemaParticle

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

use of org.apache.ws.commons.schema.XmlSchemaParticle in project hale by halestudio.

the class XmlSchemaReader method createProperties.

/**
 * Create the properties for the given complex type
 *
 * @param typeDef the definition of the declaring type
 * @param item the complex type item
 * @param schemaLocation the schema location
 * @param schemaNamespace the scheme namspace
 */
private void createProperties(XmlTypeDefinition typeDef, XmlSchemaComplexType item, String schemaLocation, String schemaNamespace) {
    // item:
    // <complexType ...>
    XmlSchemaContentModel model = item.getContentModel();
    if (model != null) {
        XmlSchemaContent content = model.getContent();
        if (content instanceof XmlSchemaComplexContentExtension) {
            // <complexContent>
            // <extension base="...">
            XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension) content;
            // particle (e.g. sequence)
            if (extension.getParticle() != null) {
                XmlSchemaParticle particle = extension.getParticle();
                createPropertiesFromParticle(typeDef, particle, schemaLocation, schemaNamespace, false);
            }
            // attributes
            XmlSchemaObjectCollection attributeCollection = extension.getAttributes();
            if (attributeCollection != null) {
                createAttributesFromCollection(attributeCollection, typeDef, null, schemaLocation, schemaNamespace);
            }
            // complex content does not have a value
            // (only if it is mixed, which can override this setting)
            typeDef.setConstraintIfNotSet(HasValueFlag.DISABLED);
        // </extension>
        // </complexContent>
        } else if (content instanceof XmlSchemaComplexContentRestriction) {
            // <complexContent>
            // <restriction base="...">
            XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) content;
            // particle (e.g. sequence)
            if (restriction.getParticle() != null) {
                XmlSchemaParticle particle = restriction.getParticle();
                createPropertiesFromParticle(typeDef, particle, schemaLocation, schemaNamespace, false);
            }
            // attributes
            XmlSchemaObjectCollection attributeCollection = restriction.getAttributes();
            if (attributeCollection != null) {
                createAttributesFromCollection(attributeCollection, typeDef, null, schemaLocation, schemaNamespace);
            }
            // complex content does not have a value
            // (only if it is mixed, which can override this setting)
            typeDef.setConstraintIfNotSet(HasValueFlag.DISABLED);
        // </restriction>
        // </complexContent>
        } else if (content instanceof XmlSchemaSimpleContentExtension) {
            // <simpleContent>
            // <extension base="...">
            XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension) content;
            // attributes
            XmlSchemaObjectCollection attributeCollection = extension.getAttributes();
            if (attributeCollection != null) {
                createAttributesFromCollection(attributeCollection, typeDef, null, schemaLocation, schemaNamespace);
            }
        // </extension>
        // </simpleContent>
        } else if (content instanceof XmlSchemaSimpleContentRestriction) {
            // <simpleContent>
            // <restriction base="...">
            XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) content;
            // attributes
            XmlSchemaObjectCollection attributeCollection = restriction.getAttributes();
            if (attributeCollection != null) {
                createAttributesFromCollection(attributeCollection, typeDef, null, schemaLocation, schemaNamespace);
            }
        // </restriction>
        // </simpleContent>
        }
    } else {
        // no complex content (instead e.g. <sequence>)
        XmlSchemaComplexType complexType = item;
        // particle (e.g. sequence)
        if (item.getParticle() != null) {
            XmlSchemaParticle particle = complexType.getParticle();
            createPropertiesFromParticle(typeDef, particle, schemaLocation, schemaNamespace, false);
        }
        // attributes
        XmlSchemaObjectCollection attributeCollection = complexType.getAttributes();
        if (attributeCollection != null) {
            createAttributesFromCollection(attributeCollection, typeDef, null, schemaLocation, schemaNamespace);
        }
    }
// </complexType>
}
Also used : XmlSchemaComplexContentExtension(org.apache.ws.commons.schema.XmlSchemaComplexContentExtension) XmlSchemaSimpleContentExtension(org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension) XmlSchemaContent(org.apache.ws.commons.schema.XmlSchemaContent) XmlSchemaComplexContentRestriction(org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction) XmlSchemaContentModel(org.apache.ws.commons.schema.XmlSchemaContentModel) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection) XmlSchemaSimpleContentRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction)

Example 18 with XmlSchemaParticle

use of org.apache.ws.commons.schema.XmlSchemaParticle in project cxf by apache.

the class SchemaCollection method addCrossImports.

private void addCrossImports(XmlSchema schema, XmlSchemaContentModel contentModel) {
    if (contentModel == null) {
        return;
    }
    XmlSchemaContent content = contentModel.getContent();
    if (content == null) {
        return;
    }
    if (content instanceof XmlSchemaComplexContentExtension) {
        XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension) content;
        XmlSchemaUtils.addImportIfNeeded(schema, extension.getBaseTypeName());
        addCrossImportsAttributeList(schema, extension.getAttributes());
        XmlSchemaParticle particle = extension.getParticle();
        if (particle instanceof XmlSchemaSequence) {
            addCrossImports(schema, (XmlSchemaSequence) particle);
        } else if (particle instanceof XmlSchemaChoice) {
            addCrossImports(schema, (XmlSchemaChoice) particle);
        } else if (particle instanceof XmlSchemaAll) {
            addCrossImports(schema, (XmlSchemaAll) particle);
        }
    } else if (content instanceof XmlSchemaComplexContentRestriction) {
        XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) content;
        XmlSchemaUtils.addImportIfNeeded(schema, restriction.getBaseTypeName());
        addCrossImportsAttributeList(schema, restriction.getAttributes());
    } else if (content instanceof XmlSchemaSimpleContentExtension) {
        XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension) content;
        XmlSchemaUtils.addImportIfNeeded(schema, extension.getBaseTypeName());
        addCrossImportsAttributeList(schema, extension.getAttributes());
    } else if (content instanceof XmlSchemaSimpleContentRestriction) {
        XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) content;
        XmlSchemaUtils.addImportIfNeeded(schema, restriction.getBaseTypeName());
        addCrossImportsAttributeList(schema, restriction.getAttributes());
    }
}
Also used : XmlSchemaComplexContentExtension(org.apache.ws.commons.schema.XmlSchemaComplexContentExtension) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaSimpleContentExtension(org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension) XmlSchemaAll(org.apache.ws.commons.schema.XmlSchemaAll) XmlSchemaContent(org.apache.ws.commons.schema.XmlSchemaContent) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice) XmlSchemaComplexContentRestriction(org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaSimpleContentRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction)

Example 19 with XmlSchemaParticle

use of org.apache.ws.commons.schema.XmlSchemaParticle in project wso2-axis2-transports by wso2.

the class XMPPSender method getParameterListForOperation.

/**
 * Retrieves list of parameter names & their type for a given operation
 * @param operation
 */
private static String getParameterListForOperation(AxisOperation operation) {
    // Logic copied from BuilderUtil.buildsoapMessage(...)
    StringBuffer paramList = new StringBuffer();
    AxisMessage axisMessage = operation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    XmlSchemaElement xmlSchemaElement = axisMessage.getSchemaElement();
    if (xmlSchemaElement != null) {
        XmlSchemaType schemaType = xmlSchemaElement.getSchemaType();
        if (schemaType instanceof XmlSchemaComplexType) {
            XmlSchemaComplexType complexType = ((XmlSchemaComplexType) schemaType);
            XmlSchemaParticle particle = complexType.getParticle();
            if (particle instanceof XmlSchemaSequence || particle instanceof XmlSchemaAll) {
                XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) particle;
                Iterator iterator = xmlSchemaGroupBase.getItems().getIterator();
                while (iterator.hasNext()) {
                    XmlSchemaElement innerElement = (XmlSchemaElement) iterator.next();
                    QName qName = innerElement.getQName();
                    if (qName == null && innerElement.getSchemaTypeName().equals(org.apache.ws.commons.schema.constants.Constants.XSD_ANYTYPE)) {
                        break;
                    }
                    long minOccurs = innerElement.getMinOccurs();
                    boolean nillable = innerElement.isNillable();
                    String name = qName != null ? qName.getLocalPart() : innerElement.getName();
                    String type = innerElement.getSchemaTypeName().toString();
                    paramList.append("," + type + " " + name);
                }
            }
        }
    }
    // remove first ","
    String list = paramList.toString();
    return list.replaceFirst(",", "");
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaGroupBase(org.apache.ws.commons.schema.XmlSchemaGroupBase) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaAll(org.apache.ws.commons.schema.XmlSchemaAll) Iterator(java.util.Iterator) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) AxisMessage(org.apache.axis2.description.AxisMessage)

Example 20 with XmlSchemaParticle

use of org.apache.ws.commons.schema.XmlSchemaParticle in project cxf by apache.

the class CorbaHandlerUtils method getXmlSchemaSequenceElement.

public static XmlSchemaElement getXmlSchemaSequenceElement(XmlSchemaObject schemaType, ServiceInfo serviceInfo) {
    XmlSchemaObject stype = schemaType;
    XmlSchemaElement el = null;
    if (schemaType instanceof XmlSchemaElement) {
        stype = ((XmlSchemaElement) schemaType).getSchemaType();
        if (stype == null) {
            stype = CorbaUtils.getXmlSchemaType(serviceInfo, ((XmlSchemaElement) schemaType).getRef().getTargetQName());
        }
    }
    if (stype instanceof XmlSchemaComplexType) {
        // only one element inside the XmlSchemaComplexType
        XmlSchemaComplexType ctype = (XmlSchemaComplexType) stype;
        XmlSchemaParticle group = ctype.getParticle();
        /* This code seems to think that we're guaranteed a sequence here */
        XmlSchemaSequence seq = (XmlSchemaSequence) group;
        /* and an element in it, too */
        el = (XmlSchemaElement) seq.getItems().get(0);
    } else {
        el = (XmlSchemaElement) schemaType;
    }
    return el;
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle)

Aggregations

XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)26 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)15 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)13 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)12 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)11 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)11 XmlSchemaChoice (org.apache.ws.commons.schema.XmlSchemaChoice)10 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)10 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)8 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)7 XmlSchemaComplexContentRestriction (org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction)7 QName (javax.xml.namespace.QName)6 ParameterInfo (org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo)6 Iterator (java.util.Iterator)5 XmlSchemaAll (org.apache.ws.commons.schema.XmlSchemaAll)5 XmlSchemaAny (org.apache.ws.commons.schema.XmlSchemaAny)5 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)5 ArrayList (java.util.ArrayList)4 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)4 XmlSchemaContent (org.apache.ws.commons.schema.XmlSchemaContent)4