Search in sources :

Example 1 with ComplexContentHasValue

use of eu.esdihumboldt.hale.io.xsd.model.ComplexContentHasValue 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 may have a value in certain cases
            // (if it is mixed it definitely has, which will override this
            // setting)
            typeDef.setConstraintIfNotSet(new ComplexContentHasValue(typeDef));
        // </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) ComplexContentHasValue(eu.esdihumboldt.hale.io.xsd.model.ComplexContentHasValue) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection) XmlSchemaSimpleContentRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction)

Aggregations

ComplexContentHasValue (eu.esdihumboldt.hale.io.xsd.model.ComplexContentHasValue)1 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)1 XmlSchemaComplexContentRestriction (org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction)1 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)1 XmlSchemaContent (org.apache.ws.commons.schema.XmlSchemaContent)1 XmlSchemaContentModel (org.apache.ws.commons.schema.XmlSchemaContentModel)1 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)1 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)1 XmlSchemaSimpleContentExtension (org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension)1 XmlSchemaSimpleContentRestriction (org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction)1