use of eu.esdihumboldt.cst.functions.groovy.internal.InstanceAccessorArrayList in project hale by halestudio.
the class GroovyGreedyTransformation method createGroovyBinding.
/**
* Create a Groovy binding from the list of variables.
*
* @param vars the variable values
* @param varDefs definition of the assigned variables, in case some
* variable values are not set, may be <code>null</code>
* @param cell the cell the binding is created for
* @param typeCell the type cell the binding is created for, may be
* <code>null</code>
* @param builder the instance builder for creating target instances, or
* <code>null</code> if not applicable
* @param useInstanceVariables if instances should be used as variables for
* the binding instead of extracting the instance values
* @param log the transformation log
* @param context the execution context
* @param targetInstanceType the type of the target instance
* @return the binding for use with {@link GroovyShell}
*/
public static Binding createGroovyBinding(List<PropertyValue> vars, List<? extends Entity> varDefs, Cell cell, Cell typeCell, InstanceBuilder builder, boolean useInstanceVariables, TransformationLog log, ExecutionContext context, TypeDefinition targetInstanceType) {
Binding binding = GroovyUtil.createBinding(builder, cell, typeCell, log, context, targetInstanceType);
// collect definitions to check if all were provided
Set<EntityDefinition> notDefined = new HashSet<>();
if (varDefs != null) {
for (Entity entity : varDefs) {
notDefined.add(entity.getDefinition());
}
}
// keep only defs where no value is provided
if (!notDefined.isEmpty()) {
for (PropertyValue var : vars) {
notDefined.remove(var.getProperty());
}
}
// add empty lists to environment if necessary
if (!notDefined.isEmpty()) {
for (EntityDefinition entity : notDefined) {
GroovyTransformation.addToBinding(binding, (PropertyEntityDefinition) entity, Collections.emptyList());
}
}
Map<PropertyEntityDefinition, InstanceAccessorArrayList<Object>> bindingMap = new HashMap<>();
// collect the values
for (PropertyValue var : vars) {
PropertyEntityDefinition property = var.getProperty();
InstanceAccessorArrayList<Object> valueList = bindingMap.get(property);
if (valueList == null) {
valueList = new InstanceAccessorArrayList<>();
bindingMap.put(property, valueList);
}
valueList.add(GroovyTransformation.getUseValue(var.getValue(), useInstanceVariables));
}
// add collected values to environment
for (Entry<PropertyEntityDefinition, InstanceAccessorArrayList<Object>> entry : bindingMap.entrySet()) {
GroovyTransformation.addToBinding(binding, entry.getKey(), entry.getValue());
}
return binding;
}
use of eu.esdihumboldt.cst.functions.groovy.internal.InstanceAccessorArrayList 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