use of org.codehaus.groovy.jsr223.GroovyScriptEngineImpl in project walkmod-core by walkmod.
the class ScriptingQueryEngine method initialize.
@Override
public void initialize(VisitorContext context, Map<String, Object> parameters) {
if (engine == null) {
ScriptEngineManager factory = new ScriptEngineManager(context.getClassLoader());
engine = factory.getEngineByName(language);
if (engine instanceof GroovyScriptEngineImpl) {
((GroovyScriptEngineImpl) engine).setClassLoader(new GroovyClassLoader(context.getClassLoader(), new CompilerConfiguration()));
}
}
this.context = context;
bindings = engine.createBindings();
Set<String> keys = parameters.keySet();
if (keys != null) {
for (String key : keys) {
Object value = parameters.get(key);
if (key.equals("node")) {
rootNode = value;
}
bindings.put(key, value);
}
}
}
use of org.codehaus.groovy.jsr223.GroovyScriptEngineImpl in project walkmod-core by walkmod.
the class ScriptProcessor method initialize.
public void initialize(VisitorContext context, Object node) {
if (engine == null) {
ScriptEngineManager factory = new ScriptEngineManager(context.getClassLoader());
engine = factory.getEngineByName(language);
if (engine instanceof GroovyScriptEngineImpl) {
((GroovyScriptEngineImpl) engine).setClassLoader(new GroovyClassLoader(context.getClassLoader(), new CompilerConfiguration()));
}
}
if (queryEngine == null) {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("language", "groovy");
List<String> includes = new LinkedList<String>();
includes.add("query.alias.groovy");
parameters.put("includes", includes);
Object bean = context.getBean("org.walkmod.query.ScriptingQueryEngine", parameters);
if (bean != null) {
if (bean instanceof QueryEngine) {
queryEngine = (QueryEngine) bean;
}
} else {
throw new WalkModException("Query Engine not found");
}
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("node", node);
queryEngine.initialize(context, params);
}
Aggregations