Search in sources :

Example 21 with XmlSchemaParticle

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

the class JavascriptUtils method getAll.

public static XmlSchemaAll getAll(XmlSchemaComplexType type) {
    XmlSchemaParticle particle = type.getParticle();
    XmlSchemaAll all = null;
    if (particle == null) {
        // a null pointer, and certainly an exception.
        return EMPTY_ALL;
    }
    try {
        all = (XmlSchemaAll) particle;
    } catch (ClassCastException cce) {
        unsupportedConstruct("NON_CHOICE_PARTICLE", type);
    }
    return all;
}
Also used : XmlSchemaAll(org.apache.ws.commons.schema.XmlSchemaAll) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle)

Example 22 with XmlSchemaParticle

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

the class JavascriptUtils method getContentSequence.

public static XmlSchemaSequence getContentSequence(XmlSchemaComplexType type) {
    XmlSchemaContentModel model = type.getContentModel();
    if (model == null) {
        return null;
    }
    XmlSchemaContent content = model.getContent();
    if (content == null) {
        return null;
    }
    if (!(content instanceof XmlSchemaComplexContentExtension)) {
        return null;
    }
    XmlSchemaComplexContentExtension ext = (XmlSchemaComplexContentExtension) content;
    XmlSchemaParticle particle = ext.getParticle();
    if (particle == null) {
        return null;
    }
    XmlSchemaSequence sequence = null;
    try {
        sequence = (XmlSchemaSequence) particle;
    } catch (ClassCastException cce) {
        unsupportedConstruct("NON_SEQUENCE_PARTICLE", type);
    }
    return sequence;
}
Also used : XmlSchemaComplexContentExtension(org.apache.ws.commons.schema.XmlSchemaComplexContentExtension) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaContent(org.apache.ws.commons.schema.XmlSchemaContent) XmlSchemaContentModel(org.apache.ws.commons.schema.XmlSchemaContentModel) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle)

Example 23 with XmlSchemaParticle

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

the class ParticleInfo method forLocalItem.

/**
 * Fill in an ElementInfo for an element or xs:any from a sequence.
 *
 * @param sequenceElement
 * @param currentSchema
 * @param schemaCollection
 * @param prefixAccumulator
 * @return
 */
public static ParticleInfo forLocalItem(XmlSchemaObject sequenceObject, XmlSchema currentSchema, SchemaCollection schemaCollection, NamespacePrefixAccumulator prefixAccumulator, QName contextName) {
    XmlSchemaParticle sequenceParticle = JavascriptUtils.getObjectParticle(sequenceObject, contextName, currentSchema);
    ParticleInfo elementInfo = new ParticleInfo();
    XmlSchemaParticle realParticle = sequenceParticle;
    elementInfo.setMinOccurs(sequenceParticle.getMinOccurs());
    elementInfo.setMaxOccurs(sequenceParticle.getMaxOccurs());
    if (sequenceParticle instanceof XmlSchemaElement) {
        XmlSchemaElement sequenceElement = (XmlSchemaElement) sequenceParticle;
        if (sequenceElement.getRef().getTargetQName() != null) {
            XmlSchemaElement refElement = sequenceElement.getRef().getTarget();
            if (refElement == null) {
                Message message = new Message("ELEMENT_DANGLING_REFERENCE", LOG, sequenceElement.getQName(), sequenceElement.getRef().getTargetQName());
                throw new UnsupportedConstruct(message.toString());
            }
            realParticle = refElement;
            elementInfo.global = true;
        }
        elementInfo.nillable = ((XmlSchemaElement) realParticle).isNillable();
    } else if (sequenceParticle instanceof XmlSchemaChoice) {
        XmlSchemaChoice choice = (XmlSchemaChoice) sequenceParticle;
        if (sequenceParticle.getMaxOccurs() > 1) {
            Message message = new Message("GROUP_ELEMENT_MULTI_OCCURS", LOG, sequenceParticle.getClass().getSimpleName());
            throw new UnsupportedConstruct(message.toString());
        }
        elementInfo.children = new LinkedList<>();
        List<XmlSchemaChoiceMember> items = choice.getItems();
        for (XmlSchemaChoiceMember item : items) {
            XmlSchemaObject schemaObject = JavascriptUtils.getObjectParticle((XmlSchemaObject) item, contextName, currentSchema);
            ParticleInfo childParticle = ParticleInfo.forLocalItem(schemaObject, currentSchema, schemaCollection, prefixAccumulator, contextName);
            if (childParticle.isAny()) {
                Message message = new Message("GROUP_ELEMENT_ANY", LOG, sequenceParticle.getClass().getSimpleName());
                throw new UnsupportedConstruct(message.toString());
            }
            childParticle.setMinOccurs(0);
            elementInfo.children.add(childParticle);
        }
    } else if (sequenceParticle instanceof XmlSchemaSequence) {
        XmlSchemaSequence nestedSequence = (XmlSchemaSequence) sequenceParticle;
        if (sequenceParticle.getMaxOccurs() > 1) {
            Message message = new Message("SEQUENCE_ELEMENT_MULTI_OCCURS", LOG, sequenceParticle.getClass().getSimpleName());
            throw new UnsupportedConstruct(message.toString());
        }
        elementInfo.children = new LinkedList<>();
        List<XmlSchemaSequenceMember> items = nestedSequence.getItems();
        for (XmlSchemaSequenceMember item : items) {
            XmlSchemaObject schemaObject = JavascriptUtils.getObjectParticle((XmlSchemaObject) item, contextName, currentSchema);
            ParticleInfo childParticle = ParticleInfo.forLocalItem(schemaObject, currentSchema, schemaCollection, prefixAccumulator, contextName);
            if (childParticle.isAny()) {
                Message message = new Message("SEQUENCE_ELEMENT_ANY", LOG, sequenceParticle.getClass().getSimpleName());
                throw new UnsupportedConstruct(message.toString());
            }
            if (sequenceParticle.getMinOccurs() == 0) {
                childParticle.setMinOccurs(0);
            }
            elementInfo.children.add(childParticle);
        }
    }
    factoryCommon(realParticle, currentSchema, schemaCollection, prefixAccumulator, elementInfo);
    elementInfo.particle = realParticle;
    return elementInfo;
}
Also used : Message(org.apache.cxf.common.i18n.Message) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) LinkedList(java.util.LinkedList) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaChoiceMember(org.apache.ws.commons.schema.XmlSchemaChoiceMember) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice) List(java.util.List) LinkedList(java.util.LinkedList)

Example 24 with XmlSchemaParticle

use of org.apache.ws.commons.schema.XmlSchemaParticle in project tomee 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 25 with XmlSchemaParticle

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

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