use of com.evolveum.midpoint.model.common.expression.script.ScriptExpressionFactory in project midpoint by Evolveum.
the class ExpressionTestUtil method createInitializedExpressionFactory.
public static ExpressionFactory createInitializedExpressionFactory(ObjectResolver resolver, ProtectorImpl protector, PrismContext prismContext, SecurityEnforcer securityEnforcer) {
ExpressionFactory expressionFactory = new ExpressionFactory(resolver, securityEnforcer, prismContext);
// asIs
AsIsExpressionEvaluatorFactory asIsFactory = new AsIsExpressionEvaluatorFactory(prismContext, protector);
expressionFactory.addEvaluatorFactory(asIsFactory);
expressionFactory.setDefaultEvaluatorFactory(asIsFactory);
// value
LiteralExpressionEvaluatorFactory valueFactory = new LiteralExpressionEvaluatorFactory(prismContext);
expressionFactory.addEvaluatorFactory(valueFactory);
// const
ConstantsManager constManager = new ConstantsManager(createConfiguration());
ConstExpressionEvaluatorFactory constFactory = new ConstExpressionEvaluatorFactory(protector, constManager, prismContext);
expressionFactory.addEvaluatorFactory(constFactory);
// path
PathExpressionEvaluatorFactory pathFactory = new PathExpressionEvaluatorFactory(prismContext, resolver, protector);
expressionFactory.addEvaluatorFactory(pathFactory);
// generate
ValuePolicyProcessor valuePolicyGenerator = new ValuePolicyProcessor();
valuePolicyGenerator.setExpressionFactory(expressionFactory);
GenerateExpressionEvaluatorFactory generateFactory = new GenerateExpressionEvaluatorFactory(protector, resolver, valuePolicyGenerator, prismContext);
expressionFactory.addEvaluatorFactory(generateFactory);
// script
Collection<FunctionLibrary> functions = new ArrayList<FunctionLibrary>();
functions.add(FunctionLibraryUtil.createBasicFunctionLibrary(prismContext, protector));
functions.add(FunctionLibraryUtil.createLogFunctionLibrary(prismContext));
ScriptExpressionFactory scriptExpressionFactory = new ScriptExpressionFactory(resolver, prismContext, protector);
scriptExpressionFactory.setFunctions(functions);
XPathScriptEvaluator xpathEvaluator = new XPathScriptEvaluator(prismContext);
scriptExpressionFactory.registerEvaluator(XPathScriptEvaluator.XPATH_LANGUAGE_URL, xpathEvaluator);
Jsr223ScriptEvaluator groovyEvaluator = new Jsr223ScriptEvaluator("Groovy", prismContext, protector);
scriptExpressionFactory.registerEvaluator(groovyEvaluator.getLanguageUrl(), groovyEvaluator);
ScriptExpressionEvaluatorFactory scriptExpressionEvaluatorFactory = new ScriptExpressionEvaluatorFactory(scriptExpressionFactory, securityEnforcer);
expressionFactory.addEvaluatorFactory(scriptExpressionEvaluatorFactory);
return expressionFactory;
}
Aggregations