use of eu.esdihumboldt.hale.common.schema.model.constraint.type.ElementType 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.ElementType 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.ElementType 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;
}
use of eu.esdihumboldt.hale.common.schema.model.constraint.type.ElementType in project hale by halestudio.
the class FunctionExecutor method convert.
/**
* Convert a value according to a target property entity definition.
*
* @param value the value to convert
* @param propertyEntityDefinition the target property entity definition
* @return the converted object
* @throws ConversionException if an error occurs during conversion
*/
private Object convert(Object value, PropertyEntityDefinition propertyEntityDefinition) throws ConversionException {
if (value == null) {
return null;
}
PropertyDefinition def = propertyEntityDefinition.getDefinition();
Binding binding = def.getPropertyType().getConstraint(Binding.class);
Class<?> target = binding.getBinding();
// special handling for Value
if (value instanceof Value) {
// try value's internal conversion
Object result = ((Value) value).as(target);
if (result != null) {
return result;
} else {
// unwrap value
value = ((Value) value).getValue();
if (value == null) {
return null;
}
}
}
if (target.isAssignableFrom(value.getClass())) {
return value;
}
if (Collection.class.isAssignableFrom(target) && target.isAssignableFrom(List.class)) {
// collection / list
ElementType elementType = def.getPropertyType().getConstraint(ElementType.class);
return ConversionUtil.getAsList(value, elementType.getBinding(), true);
}
return ConversionUtil.getAs(value, target);
}
Aggregations