Search in sources :

Example 11 with DefinitionGroup

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

the class GroupPath method createChildGroups.

/**
 * Create groups for the children in the path (which are only represented as
 * definitions). May only be called if the path is valid. This will also
 * update the path to include the groups instead of the definitions.
 *
 * @return the list of created groups
 *
 * @see #isValid()
 */
protected List<MutableGroup> createChildGroups() {
    MutableGroup parent = parents.get(parents.size() - 1);
    final List<MutableGroup> result = new ArrayList<MutableGroup>();
    for (DefinitionGroup child : children) {
        checkState(child instanceof GroupPropertyDefinition);
        // create group
        MutableGroup group = new DefaultGroup(child);
        // add to parent
        QName propertyName = ((GroupPropertyDefinition) child).getName();
        parent.addProperty(propertyName, group);
        // add to result
        result.add(group);
        // prepare for next iteration
        parent = group;
    }
    // update children and parents
    children.clear();
    parents.addAll(result);
    return result;
}
Also used : GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) DefaultGroup(eu.esdihumboldt.hale.common.instance.model.impl.DefaultGroup) MutableGroup(eu.esdihumboldt.hale.common.instance.model.MutableGroup) DefinitionGroup(eu.esdihumboldt.hale.common.schema.model.DefinitionGroup)

Example 12 with DefinitionGroup

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

the class GroupPath method isValid.

/**
 * Determines if the group path in this configuration is valid in respect to
 * the creation of new groups based on the contained definition groups.
 *
 * @return if the path is valid
 */
public boolean isValid() {
    if (children == null || children.isEmpty()) {
        // parents is assumed to be valid
        return true;
    }
    MutableGroup parentGroup = parents.get(parents.size() - 1);
    DefinitionGroup parentDef = parentGroup.getDefinition();
    for (DefinitionGroup child : children) {
        if (child instanceof GroupPropertyDefinition) {
            if (!GroupUtil.allowAdd(parentGroup, parentDef, ((GroupPropertyDefinition) child).getName())) {
                return false;
            }
        } else {
            // XXX TypeDefinitions not supported in path
            return false;
        }
        // prepare next iteration
        parentGroup = null;
        parentDef = child;
    }
    return true;
}
Also used : GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) MutableGroup(eu.esdihumboldt.hale.common.instance.model.MutableGroup) DefinitionGroup(eu.esdihumboldt.hale.common.schema.model.DefinitionGroup)

Example 13 with DefinitionGroup

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

the class StreamGmlWriter method hasOnlyNilReason.

/**
 * Determines if a group has as its only property the nilReason attribute.
 *
 * @param group the group to test
 * @return <code>true</code> if the group has the nilReason attribute and no
 *         other children, or no children at all, <code>false</code>
 *         otherwise
 */
private boolean hasOnlyNilReason(Group group) {
    int count = 0;
    QName nilReasonName = null;
    for (QName name : group.getPropertyNames()) {
        if (count > 0)
            // more than one property
            return false;
        if (!name.getLocalPart().equals("nilReason"))
            // a property different from nilReason
            return false;
        nilReasonName = name;
        count++;
    }
    if (nilReasonName != null) {
        // make sure it is an attribute
        DefinitionGroup parent = group.getDefinition();
        ChildDefinition<?> child = parent.getChild(nilReasonName);
        if (child.asProperty() == null) {
            // is a group
            return false;
        }
        if (!child.asProperty().getConstraint(XmlAttributeFlag.class).isEnabled()) {
            // not an attribute
            return false;
        }
    }
    return true;
}
Also used : QName(javax.xml.namespace.QName) DefinitionGroup(eu.esdihumboldt.hale.common.schema.model.DefinitionGroup)

Example 14 with DefinitionGroup

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

the class JaxbToEntityDefinition method convert.

/**
 * Converts the given property to a property entity definition.
 *
 * @param property the property to convert
 * @param types the type index to use
 * @param schemaSpace the schema space to assign
 * @return the property entity definition
 */
public static PropertyEntityDefinition convert(PropertyType property, TypeIndex types, SchemaSpaceID schemaSpace) {
    TypeDefinition typeDef = types.getType(asName(property.getType()));
    Filter filter = getTypeFilter(property);
    List<ChildContext> path = new ArrayList<ChildContext>();
    DefinitionGroup parent = typeDef;
    for (ChildContextType childContext : property.getChild()) {
        if (parent == null) {
            throw new IllegalStateException("Could not resolve property entity definition: child not present");
        }
        Pair<ChildDefinition<?>, List<ChildDefinition<?>>> childs = PropertyBean.findChild(parent, asName(childContext));
        // if the child is still null throw an exception
        if (childs == null || childs.getFirst() == null) {
            String childName = asName(childContext).getLocalPart();
            String parentName;
            if (parent instanceof Definition<?>) {
                parentName = ((Definition<?>) parent).getName().getLocalPart();
            } else {
                parentName = parent.getIdentifier();
            }
            throw new IllegalStateException(MessageFormat.format("Could not resolve property entity definition: child {0} not found in parent {1}", childName, parentName));
        }
        ChildDefinition<?> child = childs.getFirst();
        if (childs.getSecond() != null) {
            for (ChildDefinition<?> pathElems : childs.getSecond()) {
                path.add(new ChildContext(contextName(childContext.getContext()), contextIndex(childContext.getIndex()), createCondition(childContext.getCondition()), pathElems));
            }
        }
        path.add(new ChildContext(contextName(childContext.getContext()), contextIndex(childContext.getIndex()), createCondition(childContext.getCondition()), child));
        if (child instanceof DefinitionGroup) {
            parent = (DefinitionGroup) child;
        } else if (child.asProperty() != null) {
            parent = child.asProperty().getPropertyType();
        } else {
            parent = null;
        }
    }
    return new PropertyEntityDefinition(typeDef, path, schemaSpace, filter);
}
Also used : ArrayList(java.util.ArrayList) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefinitionGroup(eu.esdihumboldt.hale.common.schema.model.DefinitionGroup) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) ChildContextType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ChildContextType) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

DefinitionGroup (eu.esdihumboldt.hale.common.schema.model.DefinitionGroup)14 ArrayList (java.util.ArrayList)7 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)6 QName (javax.xml.namespace.QName)6 MutableGroup (eu.esdihumboldt.hale.common.instance.model.MutableGroup)5 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)5 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)4 List (java.util.List)4 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)3 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)2 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)2 DefaultGroup (eu.esdihumboldt.hale.common.instance.model.impl.DefaultGroup)2 Definition (eu.esdihumboldt.hale.common.schema.model.Definition)2 LinkedList (java.util.LinkedList)2 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)1 ORecordAbstract (com.orientechnologies.orient.core.record.ORecordAbstract)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)1 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)1