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