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);
}
Aggregations