Search in sources :

Example 1 with ChildContextType

use of eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ChildContextType 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

ChildContextType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ChildContextType)1 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)1 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)1 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)1 Filter (eu.esdihumboldt.hale.common.instance.model.Filter)1 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)1 Definition (eu.esdihumboldt.hale.common.schema.model.Definition)1 DefinitionGroup (eu.esdihumboldt.hale.common.schema.model.DefinitionGroup)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1