use of eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding in project hale by halestudio.
the class SimpleTypeUtil method convertFromXml.
/**
* Convert a string belonging to a XML simple type to the binding specified
* by the given type definition.
*
* @param value the string value
* @param type the type definition
* @return <code>null</code> if the string was <code>null</code>, the
* converted object with the binding type if possible, otherwise the
* original string
*/
public static Object convertFromXml(String value, TypeDefinition type) {
if (value == null) {
return null;
}
Class<? extends XmlAnySimpleType> simpleType = getSimpleType(type);
Class<?> binding = type.getConstraint(Binding.class).getBinding();
if (List.class.isAssignableFrom(binding)) {
// XXX also for collection
// binding?
// we are dealing with a simple type list
// items separated by whitespace
String[] elements = value.trim().split("\\s+");
ElementType elementType = type.getConstraint(ElementType.class);
Class<? extends XmlAnySimpleType> elementSimpleType = null;
if (elementType.getDefinition() != null) {
elementSimpleType = getSimpleType(elementType.getDefinition());
}
Class<?> elementBinding = elementType.getBinding();
List<Object> result = new ArrayList<Object>();
for (String element : elements) {
Object convElement = convertFromXml(element, elementSimpleType, elementBinding);
result.add(convElement);
}
return result;
}
// convert ordinary value
return convertFromXml(value, simpleType, binding);
}
use of eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding in project hale by halestudio.
the class DefaultAttributeEditorFactory method createEditor.
@Override
public AttributeEditor<?> createEditor(Composite parent, PropertyDefinition property, EntityDefinition entityDef, boolean allowScripts) {
TypeDefinition type = property.getPropertyType();
if (!type.getConstraint(HasValueFlag.class).isEnabled())
return null;
else {
if (allowScripts) {
EditorChooserEditor<Object> result = new PropertyEditorChooserEditor(parent, property, entityDef);
result.selectDefaultEditor();
return result;
} else {
Class<?> binding = type.getConstraint(Binding.class).getBinding();
if (Boolean.class.equals(binding))
return new BooleanEditor(parent);
else
return new DefaultPropertyEditor(parent, property, entityDef);
}
}
}
use of eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding in project hale by halestudio.
the class TypeDefinitionElementTypeBindingSection method refresh.
/**
* @see AbstractPropertySection#refresh()
*/
@Override
public void refresh() {
Binding bind = getDefinition().getConstraint(Binding.class);
if (Collection.class.isAssignableFrom(bind.getBinding())) {
ElementType element = getDefinition().getConstraint(ElementType.class);
elementType.setText(element.getBinding().getName());
} else {
// XXX should not be displayed
elementType.setText("");
}
binding.setText(bind.getBinding().getName());
}
use of eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding in project hale by halestudio.
the class GeometryCondition method accept.
/**
* @see EntityCondition#accept(Entity)
*/
@Override
public boolean accept(Type entity) {
TypeDefinition type = entity.getDefinition().getDefinition();
if (!type.getConstraint(HasValueFlag.class).isEnabled() && !type.getConstraint(AugmentedValueFlag.class).isEnabled()) {
// whether defined in the schema or augmented
return false;
}
GeometryType geometryType = entity.getDefinition().getDefinition().getConstraint(GeometryType.class);
if (!geometryType.isGeometry()) {
// is no geometry type
return false;
}
Collection<Class<? extends Geometry>> tmpBindings = bindings;
if (tmpBindings == null) {
// check only if it is a geometry
tmpBindings = new HashSet<Class<? extends Geometry>>();
tmpBindings.add(Geometry.class);
}
// otherwise check the allowed bindings
// default
boolean to = true;
switch(entity.getDefinition().getSchemaSpace()) {
case SOURCE:
to = false;
break;
case TARGET:
to = true;
break;
}
for (Class<? extends Geometry> compatibleClass : tmpBindings) {
Binding binding = type.getConstraint(Binding.class);
boolean isCollection = Collection.class.isAssignableFrom(binding.getBinding());
// check binding
if (isCompatibleClass(geometryType.getBinding(), to, compatibleClass, allowConversion) && (!isCollection || allowCollection)) {
return true;
}
}
// no check succeeded
return false;
}
use of eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding in project hale by halestudio.
the class BindingCondition method accept.
/**
* @see EntityCondition#accept(Entity)
*/
@Override
public boolean accept(Type entity) {
// default
boolean to = true;
switch(entity.getDefinition().getSchemaSpace()) {
case SOURCE:
to = false;
break;
case TARGET:
to = true;
break;
}
TypeDefinition type = entity.getDefinition().getDefinition();
if (!type.getConstraint(HasValueFlag.class).isEnabled() && !type.getConstraint(AugmentedValueFlag.class).isEnabled()) {
// whether defined in the schema or augmented
return false;
}
// check binding
Binding binding = type.getConstraint(Binding.class);
if (isCompatibleClass(binding.getBinding(), to)) {
return true;
}
// check element type
if (allowCollection) {
ElementType elementType = type.getConstraint(ElementType.class);
if (isCompatibleClass(elementType.getBinding(), to)) {
return true;
}
}
// no check succeeded
return false;
}
Aggregations