use of eu.esdihumboldt.cst.functions.groovy.helper.DefaultHelperContext in project hale by halestudio.
the class GroovyUtil method createBinding.
/**
* Creates a basic binding used by all Groovy functions.
*
* @param builder the instance builder, may be <code>null</code>
* @param cell the cell of the function
* @param typeCell the type cell the function works on, may be
* <code>null</code>
* @param log the transformation log
* @param executionContext the execution context
* @param targetInstanceType the type of the target instance to create
* @return a basic binding
*/
public static Binding createBinding(InstanceBuilder builder, Cell cell, Cell typeCell, TransformationLog log, ExecutionContext executionContext, TypeDefinition targetInstanceType) {
Binding binding = new Binding();
HelperContext helperContext = new DefaultHelperContext(executionContext, executionContext, cell, typeCell);
binding.setVariable(BINDING_HELPER_FUNCTIONS, HelperFunctions.createDefault(helperContext));
binding.setVariable(BINDING_BUILDER, builder);
binding.setVariable(BINDING_CELL, cell);
TransformationLogWrapper cellLog = new TransformationLogWrapper(log);
binding.setVariable(BINDING_LOG, cellLog);
binding.setVariable(BINDING_CELL_CONTEXT, SynchronizedContextProvider.getContextClosure(executionContext.getCellContext()));
binding.setVariable(BINDING_FUNCTION_CONTEXT, SynchronizedContextProvider.getContextClosure(executionContext.getFunctionContext()));
binding.setVariable(BINDING_TRANSFORMATION_CONTEXT, SynchronizedContextProvider.getContextClosure(executionContext.getTransformationContext()));
// init type cell types
ArrayList<TypeEntityDefinition> sourceTypes = null;
TypeEntityDefinition targetType = null;
if (typeCell != null) {
targetType = ((Type) CellUtil.getFirstEntity(typeCell.getTarget())).getDefinition();
if (typeCell.getSource() != null) {
Collection<? extends Entity> sources = typeCell.getSource().values();
sourceTypes = new ArrayList<>(sources.size());
for (Object entity : sources) {
sourceTypes.add(((Type) entity).getDefinition());
}
}
}
binding.setVariable(BINDING_SOURCE_TYPES, sourceTypes);
binding.setVariable(BINDING_TARGET_TYPE, targetType);
binding.setVariable(BINDING_TARGET, new TargetCollector(builder, targetInstanceType));
binding.setVariable(BINDING_PROJECT, new ProjectAccessor(executionContext.getService(ProjectInfoService.class), cellLog, executionContext));
binding.setVariable(BINDING_SPATIAL_INDEX, executionContext.getService(SpatialIndexService.class));
binding.setVariable(BINDING_INSTANCE_INDEX, executionContext.getService(InstanceIndexService.class));
return binding;
}
Aggregations