use of eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding in project hale by halestudio.
the class Centroid method evaluate.
@Override
protected Object evaluate(String transformationIdentifier, TransformationEngine engine, ListMultimap<String, PropertyValue> variables, String resultName, PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log) throws TransformationException, NoResultException {
// get input geometry
PropertyValue input = variables.get(null).get(0);
Object inputValue = input.getValue();
GeometryProperty<?> result = calculateCentroid(inputValue);
// try to yield a result compatible to the target
TypeDefinition targetType = resultProperty.getDefinition().getPropertyType();
// TODO check element type?
Class<?> binding = targetType.getConstraint(Binding.class).getBinding();
if (Geometry.class.isAssignableFrom(binding) && binding.isAssignableFrom(result.getClass())) {
return result.getGeometry();
}
return result;
}
use of eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding 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