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