Search in sources :

Example 1 with XmlSchemaChoice

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

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

the class SchemaCollection method addCrossImportsType.

private void addCrossImportsType(XmlSchema schema, XmlSchemaType schemaType) {
    // the base type might cross schemas.
    if (schemaType instanceof XmlSchemaComplexType) {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType) schemaType;
        XmlSchemaUtils.addImportIfNeeded(schema, complexType.getBaseSchemaTypeName());
        addCrossImports(schema, complexType.getContentModel());
        addCrossImportsAttributeList(schema, complexType.getAttributes());
        if (complexType.getParticle() instanceof XmlSchemaChoice) {
            XmlSchemaChoice choice = (XmlSchemaChoice) complexType.getParticle();
            addCrossImports(schema, choice);
        } else if (complexType.getParticle() instanceof XmlSchemaAll) {
            XmlSchemaAll all = (XmlSchemaAll) complexType.getParticle();
            addCrossImports(schema, all);
        } else if (complexType.getParticle() instanceof XmlSchemaSequence) {
            XmlSchemaSequence sequence = (XmlSchemaSequence) complexType.getParticle();
            addCrossImports(schema, sequence);
        }
    }
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaAll(org.apache.ws.commons.schema.XmlSchemaAll) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 3 with XmlSchemaChoice

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

the class ParticleInfo method factoryCommon.

private static void factoryCommon(XmlSchemaParticle particle, XmlSchema currentSchema, SchemaCollection schemaCollection, NamespacePrefixAccumulator prefixAccumulator, ParticleInfo elementInfo) {
    if (particle instanceof XmlSchemaElement) {
        XmlSchemaElement element = (XmlSchemaElement) particle;
        QName elementQName = XmlSchemaUtils.getElementQualifiedName(element, currentSchema);
        String elementNamespaceURI = elementQName.getNamespaceURI();
        boolean elementNoNamespace = "".equals(elementNamespaceURI);
        XmlSchema elementSchema = null;
        if (!elementNoNamespace) {
            elementSchema = schemaCollection.getSchemaByTargetNamespace(elementNamespaceURI);
            if (elementSchema == null) {
                throw new RuntimeException("Missing schema " + elementNamespaceURI);
            }
        }
        boolean qualified = !elementNoNamespace && XmlSchemaUtils.isElementQualified(element, true, currentSchema, elementSchema);
        elementInfo.xmlName = prefixAccumulator.xmlElementString(elementQName, qualified);
        // we are assuming here that we are not dealing, in close proximity,
        // with elements with identical local names and different
        // namespaces.
        elementInfo.javascriptName = elementQName.getLocalPart();
        String schemaDefaultValue = element.getDefaultValue();
        /*
             * Schema default values are carried as strings.
             * In javascript, for actual strings, we need quotes, but not for
             * numbers. The following is a trick.
             */
        schemaDefaultValue = protectDefaultValue(schemaDefaultValue);
        elementInfo.defaultValue = schemaDefaultValue;
        factorySetupType(element, schemaCollection, elementInfo);
        elementInfo.isGroup = false;
    } else if (particle instanceof XmlSchemaChoice) {
        elementInfo.isGroup = true;
    } else if (particle instanceof XmlSchemaSequence) {
        elementInfo.isGroup = true;
    } else {
        // any
        elementInfo.any = true;
        // unknown until runtime.
        elementInfo.xmlName = null;
        // TODO: multiple 'any'
        elementInfo.javascriptName = "any";
        // runtime for any.
        elementInfo.type = null;
        elementInfo.isGroup = false;
    }
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice)

Example 4 with XmlSchemaChoice

use of org.apache.ws.commons.schema.XmlSchemaChoice 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)) {
        throw 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) {
            throw unsupportedConstruct("MISSING_GROUP", groupName.toString(), contextName, null);
        }
        XmlSchemaParticle groupParticle = group.getParticle();
        if (!(groupParticle instanceof XmlSchemaSequence)) {
            throw 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)) {
        throw 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)

Example 5 with XmlSchemaChoice

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

the class JavascriptUtils method getChoice.

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

Aggregations

XmlSchemaChoice (org.apache.ws.commons.schema.XmlSchemaChoice)15 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)12 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)10 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)8 QName (javax.xml.namespace.QName)6 XmlSchemaAll (org.apache.ws.commons.schema.XmlSchemaAll)6 ArrayList (java.util.ArrayList)3 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)3 MemberType (org.apache.cxf.binding.corba.wsdl.MemberType)3 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)3 Union (org.apache.cxf.binding.corba.wsdl.Union)2 XmlSchemaAny (org.apache.ws.commons.schema.XmlSchemaAny)2 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)2 XmlSchemaComplexContentRestriction (org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction)2 XmlSchemaContent (org.apache.ws.commons.schema.XmlSchemaContent)2 XmlSchemaGroupRef (org.apache.ws.commons.schema.XmlSchemaGroupRef)2 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)2 XmlSchemaSequenceMember (org.apache.ws.commons.schema.XmlSchemaSequenceMember)2 XmlSchemaSimpleContentExtension (org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension)2 XmlSchemaSimpleContentRestriction (org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction)2