use of eu.esdihumboldt.hale.common.align.model.impl.mdexpl.ParameterBinding in project hale by halestudio.
the class CustomGroovyTransformation method createGroovyBinding.
private Binding createGroovyBinding(ListMultimap<String, PropertyValue> variables, Cell cell, Cell typeCell, InstanceBuilder builder, TransformationLog log, ExecutionContext executionContext, TypeDefinition targetInstanceType) {
Binding binding = GroovyUtil.createBinding(builder, cell, typeCell, log, executionContext, targetInstanceType);
// create bindings for inputs
for (DefaultCustomPropertyFunctionEntity source : customFunction.getSources()) {
String varName = source.getName();
boolean useInstanceVariable = useInstanceVariableForSource(source);
List<PropertyValue> values = variables.get(varName);
if (source.isEager() || source.getMaxOccurrence() > 1 || source.getMaxOccurrence() == ParameterDefinition.UNBOUNDED) {
// multiple values
InstanceAccessorArrayList<Object> valueList = new InstanceAccessorArrayList<>();
for (PropertyValue value : values) {
valueList.add(GroovyTransformation.getUseValue(value.getValue(), useInstanceVariable));
}
binding.setVariable(varName, valueList);
} else {
// single value
if (values.isEmpty()) {
// no value
// -> use null value for missing variable
binding.setVariable(varName, null);
} else {
// value
binding.setVariable(varName, GroovyTransformation.getUseValue(values.get(0).getValue(), useInstanceVariable));
}
}
}
// create binding(s) for parameters
binding.setVariable(BINDING_PARAMS, new ParameterBinding(cell, customFunction.getDescriptor()));
return binding;
}
Aggregations