Search in sources :

Example 6 with XmlSchemaParticle

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

the class WSDLToCorbaHelper method processOMGUnion.

private CorbaType processOMGUnion(XmlSchemaComplexType complex, QName defaultName) throws Exception {
    QName name;
    Union corbaUnion = null;
    QName schematypeName = checkPrefix(complex.getQName());
    if (schematypeName == null) {
        schematypeName = defaultName;
        name = createQNameCorbaNamespace(defaultName.getLocalPart() + "Type");
    } else {
        name = createQNameCorbaNamespace(schematypeName.getLocalPart());
    }
    corbaUnion = new Union();
    corbaUnion.setName(name.getLocalPart());
    corbaUnion.setQName(name);
    String id = REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION;
    corbaUnion.setRepositoryID(id);
    corbaUnion.setType(schematypeName);
    XmlSchemaSequence stype = (XmlSchemaSequence) complex.getParticle();
    Iterator<XmlSchemaSequenceMember> it = stype.getItems().iterator();
    XmlSchemaParticle st1 = (XmlSchemaParticle) it.next();
    XmlSchemaParticle st2 = (XmlSchemaParticle) it.next();
    XmlSchemaElement discEl = null;
    XmlSchemaChoice choice = null;
    if (st1 instanceof XmlSchemaElement) {
        discEl = (XmlSchemaElement) st1;
        choice = (XmlSchemaChoice) st2;
    } else {
        discEl = (XmlSchemaElement) st2;
        choice = (XmlSchemaChoice) st1;
    }
    CorbaType disctype = convertSchemaToCorbaType(discEl.getSchemaType(), discEl.getQName(), discEl.getSchemaType(), null, false);
    corbaUnion.setDiscriminator(disctype.getQName());
    List<MemberType> fields = processContainerAsMembers(choice, defaultName, schematypeName);
    List<String> caselist = new ArrayList<>();
    if (disctype instanceof Enum) {
        Enum corbaenum = (Enum) disctype;
        Iterator<Enumerator> iterator = corbaenum.getEnumerator().iterator();
        while (iterator.hasNext()) {
            Enumerator enumerator = iterator.next();
            caselist.add(enumerator.getValue());
        }
    } else if (SUPPORTEDDISTYPES.contains(disctype.getQName().getLocalPart())) {
        if (disctype.getQName().getLocalPart().equals("long") || disctype.getQName().getLocalPart().equals("short")) {
            for (int i = 0; i < fields.size(); i++) {
                caselist.add(Integer.toString(i));
            }
        } else if (disctype.getQName().getLocalPart().equals("char")) {
            for (int i = 0; i < fields.size(); i++) {
                caselist.add(Integer.toString(i));
            }
        } else if (disctype.getQName().getLocalPart().equals("char")) {
            for (int i = 0; i < fields.size(); i++) {
                caselist.add(Integer.toString(i));
            }
        } else if (disctype.getQName().getLocalPart().equals("boolean")) {
            if (fields.size() == 2) {
                caselist.add("TRUE");
                caselist.add("FALSE");
            } else if (fields.size() == 1) {
                caselist.add("TRUE");
            } else {
                String msg = "Discriminator Type doesnt match number of Choices in Union:" + name;
                LOG.log(Level.WARNING, msg);
            }
        }
    }
    WSDLTypes.processUnionBranches(corbaUnion, fields, caselist);
    return corbaUnion;
}
Also used : Enum(org.apache.cxf.binding.corba.wsdl.Enum) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) ArrayList(java.util.ArrayList) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) Union(org.apache.cxf.binding.corba.wsdl.Union) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) Enumerator(org.apache.cxf.binding.corba.wsdl.Enumerator) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice)

Example 7 with XmlSchemaParticle

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

the class WSDLToCorbaHelper method processContainerAsMembers.

protected List<MemberType> processContainerAsMembers(XmlSchemaParticle particle, QName defaultName, QName schemaTypeName) throws Exception {
    List<MemberType> members = new ArrayList<>();
    Iterator<? extends XmlSchemaObjectBase> iterL = null;
    if (particle instanceof XmlSchemaSequence) {
        XmlSchemaSequence scontainer = (XmlSchemaSequence) particle;
        iterL = scontainer.getItems().iterator();
    } else if (particle instanceof XmlSchemaChoice) {
        XmlSchemaChoice scontainer = (XmlSchemaChoice) particle;
        iterL = scontainer.getItems().iterator();
    } else if (particle instanceof XmlSchemaAll) {
        XmlSchemaAll acontainer = (XmlSchemaAll) particle;
        iterL = acontainer.getItems().iterator();
    } else {
        LOG.warning("Unknown particle type " + particle.getClass().getName());
        iterL = new ArrayList<XmlSchemaObjectBase>().iterator();
    }
    while (iterL.hasNext()) {
        XmlSchemaParticle container = (XmlSchemaParticle) iterL.next();
        if (container instanceof XmlSchemaSequence) {
            XmlSchemaSequence sequence = (XmlSchemaSequence) container;
            CorbaType memberType = processSequenceType(sequence, defaultName, schemaTypeName);
            QName typeName = memberType.getQName();
            if (memberType instanceof Struct && !isDuplicate(memberType)) {
                typeMappingType.getStructOrExceptionOrUnion().add(memberType);
            }
            MemberType member = new MemberType();
            member.setName(memberType.getName() + "_f");
            member.setIdltype(typeName);
            member.setAnonschematype(true);
            if (memberType.isSetQualified() && memberType.isQualified()) {
                member.setQualified(true);
            }
            members.add(member);
        } else if (container instanceof XmlSchemaChoice) {
            XmlSchemaChoice choice = (XmlSchemaChoice) container;
            MemberType member = processChoiceMember(choice, defaultName, schemaTypeName);
            member.setAnonschematype(true);
            members.add(member);
        } else if (container instanceof XmlSchemaAll) {
            XmlSchemaAll all = (XmlSchemaAll) container;
            MemberType member = processAllMember(all, defaultName, schemaTypeName);
            member.setAnonschematype(true);
            members.add(member);
        } else if (container instanceof XmlSchemaElement) {
            XmlSchemaElement element = (XmlSchemaElement) container;
            CorbaType corbatype = processLocalElement(defaultName, element, schemaTypeName.getNamespaceURI());
            QName elName = element.getQName();
            if (elName == null) {
                elName = element.getRef().getTargetQName();
            }
            if (corbatype != null) {
                MemberType member;
                String memberName = elName.getLocalPart();
                member = new MemberType();
                member.setName(memberName);
                member.setIdltype(corbatype.getQName());
                if (corbatype.isSetQualified() && corbatype.isQualified()) {
                    member.setQualified(true);
                }
                members.add(member);
            } else {
                LOG.log(Level.WARNING, "Unsupported Element Found in CORBA Binding Generation:" + elName);
            }
        }
    }
    return members;
}
Also used : QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) ArrayList(java.util.ArrayList) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) Struct(org.apache.cxf.binding.corba.wsdl.Struct) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) MemberType(org.apache.cxf.binding.corba.wsdl.MemberType) XmlSchemaAll(org.apache.ws.commons.schema.XmlSchemaAll) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice)

Example 8 with XmlSchemaParticle

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

the class WSDLTypes method isOMGUnion.

public static boolean isOMGUnion(XmlSchemaComplexType type) {
    boolean isUnion = false;
    if (type.getParticle() instanceof XmlSchemaSequence && type.getAttributes().isEmpty()) {
        XmlSchemaSequence stype = (XmlSchemaSequence) type.getParticle();
        if (stype.getItems().size() == 2) {
            XmlSchemaParticle st1 = (XmlSchemaParticle) stype.getItems().get(0);
            XmlSchemaParticle st2 = (XmlSchemaParticle) stype.getItems().get(1);
            XmlSchemaElement discEl = null;
            if (st1 instanceof XmlSchemaChoice && st2 instanceof XmlSchemaElement) {
                isUnion = true;
                discEl = (XmlSchemaElement) st2;
            } else if (st2 instanceof XmlSchemaChoice && st1 instanceof XmlSchemaElement) {
                isUnion = true;
                discEl = (XmlSchemaElement) st1;
            }
            if (isUnion && !"discriminator".equals(discEl.getQName().getLocalPart())) {
                isUnion = false;
            }
        }
    }
    return isUnion;
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle)

Example 9 with XmlSchemaParticle

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

the class XmlSchemaReader method createPropertiesFromParticle.

/**
 * Extracts attribute definitions from a {@link XmlSchemaParticle}.
 *
 * @param declaringGroup the definition of the declaring group
 * @param particle the particle
 * @param schemaLocation the schema location
 * @param schemaNamespace the schema namespace
 * @param forceGroup force creating a group (e.g. if the parent is a choice)
 */
private void createPropertiesFromParticle(DefinitionGroup declaringGroup, XmlSchemaParticle particle, String schemaLocation, String schemaNamespace, boolean forceGroup) {
    // particle:
    if (particle instanceof XmlSchemaSequence) {
        // <sequence>
        XmlSchemaSequence sequence = (XmlSchemaSequence) particle;
        // once will result in no group if not forced)
        if (forceGroup || sequence.getMinOccurs() != 1 || sequence.getMaxOccurs() != 1) {
            // create a sequence group
            QName sequenceName = createGroupName(declaringGroup, "sequence");
            DefaultGroupPropertyDefinition sequenceGroup = new DefaultGroupPropertyDefinition(sequenceName, declaringGroup, false);
            // set cardinality
            long max = (sequence.getMaxOccurs() == Long.MAX_VALUE) ? (Cardinality.UNBOUNDED) : (sequence.getMaxOccurs());
            sequenceGroup.setConstraint(Cardinality.get(sequence.getMinOccurs(), max));
            // set choice constraint (no choice)
            sequenceGroup.setConstraint(ChoiceFlag.DISABLED);
            // set metadata
            setMetadata(sequenceGroup, sequence, schemaLocation);
            // use group as parent
            declaringGroup = sequenceGroup;
        }
        for (int j = 0; j < sequence.getItems().getCount(); j++) {
            XmlSchemaObject object = sequence.getItems().getItem(j);
            if (object instanceof XmlSchemaElement) {
                // <element>
                createPropertyFromElement((XmlSchemaElement) object, declaringGroup, schemaLocation, schemaNamespace);
            // </element>
            } else if (object instanceof XmlSchemaParticle) {
                // contained particles, e.g. a choice
                // content doesn't need to be grouped, it can be decided in
                // the method
                createPropertiesFromParticle(declaringGroup, (XmlSchemaParticle) object, schemaLocation, schemaNamespace, false);
            }
        }
    // </sequence>
    } else if (particle instanceof XmlSchemaChoice) {
        // <choice>
        XmlSchemaChoice choice = (XmlSchemaChoice) particle;
        // create a choice group
        QName choiceName = createGroupName(declaringGroup, "choice");
        DefaultGroupPropertyDefinition choiceGroup = new DefaultGroupPropertyDefinition(choiceName, declaringGroup, // no flatten allowed
        false);
        // because of choice
        // set custom display name
        choiceGroup.setConstraint(DISPLAYNAME_CHOICE);
        // set cardinality
        long max = (choice.getMaxOccurs() == Long.MAX_VALUE) ? (Cardinality.UNBOUNDED) : (choice.getMaxOccurs());
        choiceGroup.setConstraint(Cardinality.get(choice.getMinOccurs(), max));
        // set choice constraint
        choiceGroup.setConstraint(ChoiceFlag.ENABLED);
        // set metadata
        setMetadata(choiceGroup, choice, schemaLocation);
        // create properties with choiceGroup as parent
        for (int j = 0; j < choice.getItems().getCount(); j++) {
            XmlSchemaObject object = choice.getItems().getItem(j);
            if (object instanceof XmlSchemaElement) {
                // <element>
                createPropertyFromElement((XmlSchemaElement) object, choiceGroup, schemaLocation, schemaNamespace);
            } else if (object instanceof XmlSchemaParticle) {
                // contained particles, e.g. a choice or sequence
                // inside a choice they must form a group
                createPropertiesFromParticle(choiceGroup, (XmlSchemaParticle) object, schemaLocation, schemaNamespace, true);
            }
        }
    // </choice>
    } else if (particle instanceof XmlSchemaGroupRef) {
        // <group ref="..." />
        XmlSchemaGroupRef groupRef = (XmlSchemaGroupRef) particle;
        QName groupName = groupRef.getRefName();
        long max = (groupRef.getMaxOccurs() == Long.MAX_VALUE) ? (Cardinality.UNBOUNDED) : (groupRef.getMaxOccurs());
        long min = groupRef.getMinOccurs();
        /*
			 * Only allow flatten if group is not forced and appears exactly
			 * once
			 */
        XmlGroupReferenceProperty property = new XmlGroupReferenceProperty(groupName, declaringGroup, index, groupName, !forceGroup && min == 1 && max == 1);
        // set cardinality constraint
        property.setConstraint(Cardinality.get(min, max));
        // set metadata
        setMetadata(property, groupRef, schemaLocation);
    } else if (particle instanceof XmlSchemaAny) {
        // XXX ignore for now
        reporter.info(new IOMessageImpl("Particle that allows any element is not supported.", null, particle.getLineNumber(), particle.getLinePosition()));
    } else {
        reporter.error(new IOMessageImpl("Unrecognized particle: " + particle.getClass().getSimpleName(), null, particle.getLineNumber(), particle.getLinePosition()));
    }
}
Also used : QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaGroupRef(org.apache.ws.commons.schema.XmlSchemaGroupRef) XmlSchemaAny(org.apache.ws.commons.schema.XmlSchemaAny) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) DefaultGroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice) XmlGroupReferenceProperty(eu.esdihumboldt.hale.io.xsd.reader.internal.XmlGroupReferenceProperty)

Example 10 with XmlSchemaParticle

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

the class JavascriptUtils method getObjectParticle.

/**
 * If the object is an element or an any, return the particle. If it's not a particle, or it's a group,
 * throw. We're not ready for groups yet.
 * @param object
 */
public static XmlSchemaParticle getObjectParticle(XmlSchemaObject object, QName contextName, XmlSchema currentSchema) {
    if (!(object instanceof XmlSchemaParticle)) {
        unsupportedConstruct("NON_PARTICLE_CHILD", object.getClass().getSimpleName(), contextName, object);
    }
    if (object instanceof XmlSchemaGroupRef) {
        QName groupName = ((XmlSchemaGroupRef) object).getRefName();
        XmlSchemaGroup group = currentSchema.getGroupByName(groupName);
        if (group == null) {
            unsupportedConstruct("MISSING_GROUP", groupName.toString(), contextName, null);
        }
        XmlSchemaParticle groupParticle = group.getParticle();
        if (!(groupParticle instanceof XmlSchemaSequence)) {
            unsupportedConstruct("GROUP_REF_UNSUPPORTED_TYPE", groupParticle.getClass().getSimpleName(), contextName, groupParticle);
        }
        return groupParticle;
    }
    if (!(object instanceof XmlSchemaElement) && !(object instanceof XmlSchemaAny) && !(object instanceof XmlSchemaChoice) && !(object instanceof XmlSchemaSequence)) {
        unsupportedConstruct("GROUP_CHILD", object.getClass().getSimpleName(), contextName, object);
    }
    return (XmlSchemaParticle) object;
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaGroup(org.apache.ws.commons.schema.XmlSchemaGroup) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaGroupRef(org.apache.ws.commons.schema.XmlSchemaGroupRef) XmlSchemaAny(org.apache.ws.commons.schema.XmlSchemaAny)

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