Search in sources :

Example 16 with TypeDefinition

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

the class XmlSchemaReader method applyRelevantElements.

/**
 * Apply the relevant elements setting to the given XML index.
 *
 * @param index the XML index
 */
private void applyRelevantElements(XmlIndex index) {
    Set<? extends QName> names = getRelevantElements();
    if (names != null && !names.isEmpty()) {
        // only apply if any elements are given
        // get all currently marked relevant types
        Set<TypeDefinition> toggleTypes = new HashSet<>(index.getMappingRelevantTypes());
        boolean foundAny = false;
        for (QName name : names) {
            XmlElement elm = index.getElements().get(name);
            if (elm != null) {
                foundAny = true;
                TypeDefinition type = elm.getType();
                if (toggleTypes.contains(type)) {
                    // do not toggle -> stay relevant
                    toggleTypes.remove(type);
                } else {
                    // toggle -> become relevant
                    toggleTypes.add(type);
                }
            }
        }
        if (foundAny) {
            // only apply if one of the given elements was actually found in
            // the schema
            index.toggleMappingRelevant(toggleTypes);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) XmlTypeDefinition(eu.esdihumboldt.hale.io.xsd.reader.internal.XmlTypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) HashSet(java.util.HashSet)

Example 17 with TypeDefinition

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

the class SubstitutionGroupProperty method initChildren.

/**
 * @see LazyGroupPropertyDefinition#initChildren()
 */
@Override
protected void initChildren() {
    if (property != null) {
        TypeDefinition propertyType = property.getPropertyType();
        // add property and substitutions
        // collect substitution types and elements
        List<XmlElement> substitutions = collectSubstitutions(property.getName(), propertyType);
        if (substitutions == null || substitutions.isEmpty()) {
            // add property (XXX even if the property type is abstract)
            // no redeclaration necessary as this
            super.addChild(property);
        // is already the declaring group
        } else {
            // add property if the type is not abstract
            if (!propertyType.getConstraint(AbstractFlag.class).isEnabled()) {
                // no redeclaration necessary as
                super.addChild(property);
            // this is already the declaring
            // group
            }
            // add substitutions
            for (XmlElement substitution : substitutions) {
                PropertyDefinition p = new SubstitutionProperty(substitution, property, this);
                // must call super add
                super.addChild(p);
            }
        }
    }
// else empty group
}
Also used : XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) 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) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 18 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition 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)

Example 19 with TypeDefinition

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

the class UnionValidationConstraint method getValidator.

/**
 * @see eu.esdihumboldt.hale.common.schema.model.constraint.type.ValidationConstraint#getValidator()
 */
@Override
public Validator getValidator() {
    if (!initialized) {
        ArrayList<Validator> validators = new ArrayList<Validator>(unionTypes.size());
        for (TypeDefinition type : unionTypes) validators.add(type.getConstraint(ValidationConstraint.class).getValidator());
        validator = new OrValidator(validators);
    }
    return validator;
}
Also used : ValidationConstraint(eu.esdihumboldt.hale.common.schema.model.constraint.type.ValidationConstraint) ArrayList(java.util.ArrayList) OrValidator(eu.esdihumboldt.util.validator.OrValidator) OrValidator(eu.esdihumboldt.util.validator.OrValidator) Validator(eu.esdihumboldt.util.validator.Validator) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 20 with TypeDefinition

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

the class NestedCellRelationshipContentProvider method getElements.

/**
 * @see CellRelationshipContentProvider#getElements(Object)
 */
@Override
public Object[] getElements(Object input) {
    List<Object> elements = new ArrayList<Object>();
    entityMap.clear();
    Multimap<TypeDefinition, Type> types = HashMultimap.create();
    Collection<Property> properties = new ArrayList<Property>();
    for (Object element : super.getElements(input)) {
        if (element instanceof Type) {
            Type type = (Type) element;
            types.put(type.getDefinition().getDefinition(), type);
            elements.add(element);
        } else if (element instanceof Property) {
            properties.add((Property) element);
        } else {
            elements.add(element);
        }
    }
    // assign properties to corresponding parents
    for (Property property : properties) {
        // find association through type definition
        TypeDefinition parentType = property.getDefinition().getType();
        Collection<Type> typeList = types.get(parentType);
        for (Type type : typeList) {
            entityMap.put(type, property);
        }
    }
    return elements.toArray();
}
Also used : Type(eu.esdihumboldt.hale.common.align.model.Type) ArrayList(java.util.ArrayList) Property(eu.esdihumboldt.hale.common.align.model.Property) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)192 QName (javax.xml.namespace.QName)58 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)38 ArrayList (java.util.ArrayList)32 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)26 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)26 Test (org.junit.Test)24 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)22 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)21 HashSet (java.util.HashSet)21 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)20 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)20 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)16 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)15 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)15 Cell (eu.esdihumboldt.hale.common.align.model.Cell)14 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)14 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)12 Binding (eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding)12 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)12