Search in sources :

Example 1 with DefaultGroupPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition in project hale by halestudio.

the class XmlSchemaReader method setMetadata.

/**
 * Set the metadata for a definition
 *
 * @param definition the definition
 * @param annotated the XML annotated object
 * @param schemaLocation the schema location
 */
public static void setMetadata(AbstractDefinition<?> definition, XmlSchemaAnnotated annotated, String schemaLocation) {
    definition.setDescription(XMLSchemaIO.getDescription(annotated));
    List<XmlSchemaAppInfo> appInfo = XMLSchemaIO.getAppInfo(annotated);
    if (appInfo != null) {
        XmlAppInfo constraint = new XmlAppInfo(appInfo);
        if (definition instanceof DefaultPropertyDefinition) {
            ((DefaultPropertyDefinition) definition).setConstraint(constraint);
        } else if (definition instanceof DefaultGroupPropertyDefinition) {
            ((DefaultGroupPropertyDefinition) definition).setConstraint(constraint);
        } else if (definition instanceof DefaultTypeDefinition) {
            ((DefaultTypeDefinition) definition).setConstraint(constraint);
        }
    }
    definition.setLocation(createLocationURI(schemaLocation, annotated));
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) DefaultGroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition) XmlAppInfo(eu.esdihumboldt.hale.io.xsd.constraint.XmlAppInfo) XmlSchemaAppInfo(org.apache.ws.commons.schema.XmlSchemaAppInfo)

Example 2 with DefaultGroupPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition 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 3 with DefaultGroupPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition in project hale by halestudio.

the class CustomTypeContentHelper method applyElementsMode.

private static void applyElementsMode(PropertyDefinition propDef, DefinitionGroup propParent, CustomTypeContent config, XmlIndex index) {
    // build new property type based on config
    DefaultTypeDefinition type = new DefaultTypeDefinition(new QName(propDef.getIdentifier(), "customElementsContentType"), false);
    type.setConstraint(MappableFlag.DISABLED);
    DefaultGroupPropertyDefinition choice = new DefaultGroupPropertyDefinition(new QName(propDef.getIdentifier(), "customElementsContentChoice"), type, false);
    choice.setConstraint(new DisplayName("elements"));
    choice.setConstraint(ChoiceFlag.ENABLED);
    choice.setConstraint(Cardinality.CC_ANY_NUMBER);
    for (QName elementName : config.getElements()) {
        XmlElement element = index.getElements().get(elementName);
        if (element != null) {
            DefaultPropertyDefinition elementProp = new DefaultPropertyDefinition(elementName, choice, element.getType());
            elementProp.setConstraint(Cardinality.CC_EXACTLY_ONCE);
            elementProp.setConstraint(NillableFlag.DISABLED);
        } else {
            log.error("Element {} could not be found when creating custom type content", elementName);
        }
    }
    replaceTypeForProperty(propDef, propParent, type);
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) DefaultGroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition) QName(javax.xml.namespace.QName) DisplayName(eu.esdihumboldt.hale.common.schema.model.constraint.DisplayName) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement)

Example 4 with DefaultGroupPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition in project hale by halestudio.

the class CustomTypeContentHelper method replaceTypeForProperty.

private static void replaceTypeForProperty(PropertyDefinition propDef, DefinitionGroup propParent, TypeDefinition newPropertyType) {
    PropertyDefinition newProperty;
    if (propDef instanceof PropertyTypeOverrideProperty) {
        newProperty = new PropertyTypeOverrideProperty(((PropertyTypeOverrideProperty) propDef).getDecoratedProperty(), newPropertyType);
    } else {
        newProperty = new PropertyTypeOverrideProperty(propDef, newPropertyType);
    }
    if (propParent instanceof DefaultTypeDefinition) {
        DefaultTypeDefinition type = (DefaultTypeDefinition) propParent;
        type.overrideChild(newProperty);
    } else // else if (propParent instanceof DefaultGroupPropertyDefinition) {
    // // TODO
    // }
    {
        log.error("Could not update custom content property because of unsupported parent definition group");
    }
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) PropertyTypeOverrideProperty(eu.esdihumboldt.hale.common.schema.model.impl.PropertyTypeOverrideProperty) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) DefaultGroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)

Aggregations

DefaultGroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition)4 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)3 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)3 QName (javax.xml.namespace.QName)2 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)1 DisplayName (eu.esdihumboldt.hale.common.schema.model.constraint.DisplayName)1 PropertyTypeOverrideProperty (eu.esdihumboldt.hale.common.schema.model.impl.PropertyTypeOverrideProperty)1 XmlAppInfo (eu.esdihumboldt.hale.io.xsd.constraint.XmlAppInfo)1 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)1 XmlGroupReferenceProperty (eu.esdihumboldt.hale.io.xsd.reader.internal.XmlGroupReferenceProperty)1 XmlSchemaAny (org.apache.ws.commons.schema.XmlSchemaAny)1 XmlSchemaAppInfo (org.apache.ws.commons.schema.XmlSchemaAppInfo)1 XmlSchemaChoice (org.apache.ws.commons.schema.XmlSchemaChoice)1 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)1 XmlSchemaGroupRef (org.apache.ws.commons.schema.XmlSchemaGroupRef)1 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)1 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)1 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)1