Search in sources :

Example 1 with UnionEnumeration

use of eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionEnumeration in project hale by halestudio.

the class XmlTypeUtil method configureSimpleTypeUnion.

/**
 * Configure a type definition for a simple type based on a simple type
 * union.
 *
 * @param type the type definition
 * @param union the simple type union
 * @param index the XML index for resolving type definitions
 * @param reporter the report
 */
private static void configureSimpleTypeUnion(XmlTypeDefinition type, XmlSchemaSimpleTypeUnion union, XmlIndex index, IOReporter reporter) {
    XmlSchemaObjectCollection baseTypes = union.getBaseTypes();
    // collect type definitions
    Set<TypeDefinition> unionTypes = new HashSet<TypeDefinition>();
    if (union.getMemberTypesQNames() != null) {
        for (QName unionMember : union.getMemberTypesQNames()) unionTypes.add(index.getOrCreateType(unionMember));
    }
    // base type definitions
    if (baseTypes != null && baseTypes.getCount() > 0) {
        for (int i = 0; i < baseTypes.getCount(); i++) {
            XmlSchemaObject baseType = baseTypes.getItem(i);
            if (baseType instanceof XmlSchemaSimpleType) {
                XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) baseType;
                // Here it is a xs:localSimpleTypes, name attribute is
                // prohibited!
                // So it always is a anonymous type.
                QName baseName = new QName(type.getName().getNamespaceURI() + "/" + type.getName().getLocalPart(), // $NON-NLS-1$ //$NON-NLS-2$
                "AnonymousType" + i);
                XmlTypeDefinition baseDef = new AnonymousXmlType(baseName);
                configureSimpleType(baseDef, simpleType, index, reporter);
                unionTypes.add(baseDef);
            } else {
                reporter.error(new IOMessageImpl("Unrecognized base type for simple type union", null, union.getLineNumber(), union.getLinePosition()));
            }
        }
    }
    // binding constraint
    type.setConstraint(new UnionBinding(unionTypes));
    // enumeration constraint
    type.setConstraint(new UnionEnumeration(unionTypes));
    // validation constraint
    type.setConstraint(new UnionValidationConstraint(unionTypes));
}
Also used : UnionValidationConstraint(eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionValidationConstraint) UnionBinding(eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionBinding) QName(javax.xml.namespace.QName) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) UnionValidationConstraint(eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionValidationConstraint) TypeConstraint(eu.esdihumboldt.hale.common.schema.model.TypeConstraint) ValidationConstraint(eu.esdihumboldt.hale.common.schema.model.constraint.type.ValidationConstraint) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) UnionEnumeration(eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionEnumeration) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection) HashSet(java.util.HashSet)

Aggregations

IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 TypeConstraint (eu.esdihumboldt.hale.common.schema.model.TypeConstraint)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 ValidationConstraint (eu.esdihumboldt.hale.common.schema.model.constraint.type.ValidationConstraint)1 UnionBinding (eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionBinding)1 UnionEnumeration (eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionEnumeration)1 UnionValidationConstraint (eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionValidationConstraint)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)1 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)1 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)1