当前位置: 首页>>代码示例>>Java>>正文


Java GroovyScriptEngineImpl类代码示例

本文整理汇总了Java中org.codehaus.groovy.jsr223.GroovyScriptEngineImpl的典型用法代码示例。如果您正苦于以下问题:Java GroovyScriptEngineImpl类的具体用法?Java GroovyScriptEngineImpl怎么用?Java GroovyScriptEngineImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GroovyScriptEngineImpl类属于org.codehaus.groovy.jsr223包,在下文中一共展示了GroovyScriptEngineImpl类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl; //导入依赖的package包/类
@Override
public void start() {
    scriptEngine = new GroovyScriptEngineImpl();
    TypedProperties properties = getTypedProperties();
    rowsPerMessage = properties.getLong(ROWS_PER_MESSAGE);
    String json = getComponent().get(SETTING_CONFIG);
    onlyRouteFirstMatch = getComponent().getBoolean(ONLY_ROUTE_FIRST_MATCH, false);
    if (isNotBlank(json)) {
        try {
            routes = new ObjectMapper().readValue(json, new TypeReference<List<Route>>() {
            });
            // Verify all routes are valid
            for (Route route : routes) {
                FlowStepLink link = getFlow()
                        .findLinkBetweenSourceAndTarget(this.getFlowStepId(),route.getTargetStepId());
                if (link == null) {
                    throw new MisconfiguredException("A route target step is not linked."); 
                }
            }
        } catch (Exception e) {
            throw new IoException(e);
        }
    }
}
 
开发者ID:JumpMind,项目名称:metl,代码行数:25,代码来源:ContentRouter.java

示例2: initialize

import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl; //导入依赖的package包/类
@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);
		}
	}
}
 
开发者ID:walkmod,项目名称:walkmod-core,代码行数:25,代码来源:ScriptingQueryEngine.java

示例3: ConfigManager

import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl; //导入依赖的package包/类
private ConfigManager()
{
    CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
    ImportCustomizer importCustomizer = new ImportCustomizer();
    importCustomizer.addStarImports("org.diorite.config", "org.diorite.config.serialization", "org.diorite", "org.diorite.config.exceptions");
    compilerConfiguration.addCompilationCustomizers(importCustomizer);
    GroovyClassLoader groovyClassLoader = new GroovyClassLoader(this.getClass().getClassLoader(), compilerConfiguration);
    this.groovy = new GroovyScriptEngineImpl(groovyClassLoader);
    DynamicClassLoader classLoader = DynamicClassLoader.injectAsSystemClassLoader();
    classLoader.addClassLoader(groovyClassLoader, 0);
    this.setImplementationProvider(GroovyImplementationProvider.getInstance());
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:13,代码来源:ConfigManager.java

示例4: processGroovyValidators

import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <X> void processGroovyValidators(@Nullable GroovyValidator[] groovyValidators, ConfigPropertyTemplateImpl<X> template)
{
    if ((groovyValidators == null) || (groovyValidators.length == 0))
    {
        return;
    }
    StringBuilder groovyScript = new StringBuilder(groovyValidators.length * 100);
    groovyScript.append("ValidatorFunction func = { def x, Config cfg -> \n");
    for (GroovyValidator groovyValidator : groovyValidators)
    {
        groovyScript.append("    if (!(").append(groovyValidator.isTrue()).append(")) throw new RuntimeException(\"\"\"")
                    .append(groovyValidator.elseThrow())
                    .append("\"\"\")\n");
    }
    groovyScript.append("    return x;\n}\nreturn func");
    String script = groovyScript.toString();
    GroovyScriptEngineImpl groovy = (GroovyScriptEngineImpl) ConfigManager.get().getGroovy();
    try
    {
        ValidatorFunction<Config, X> validatorFunction = (ValidatorFunction<Config, X>) groovy.eval(groovyScript.toString());
        template.appendValidator(validatorFunction);
    }
    catch (ScriptException e)
    {
        throw new RuntimeException("Can't compile validator script for: " + template.getName() + " in " + this.type.getCanonicalName() + "\n\n" +
                                   groovyScript.toString() + "\n====================", e);
    }
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:30,代码来源:ConfigTemplateImpl.java

示例5: getScriptEngine

import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl; //导入依赖的package包/类
@Override
public ScriptEngine getScriptEngine() {
  CompilerConfiguration conf = new CompilerConfiguration();
  Map<String, Boolean> optimizationOptions = conf.getOptimizationOptions();
  optimizationOptions.put(INVOKEDYNAMIC, useInvokeDynamic());
  conf.setOptimizationOptions(optimizationOptions);
  conf.setTargetBytecode(JDK8);

  GroovyClassLoader classLoader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader(), conf);
  return new GroovyScriptEngineImpl(classLoader);
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:12,代码来源:StreamSetsGroovyScriptEngineFactory.java

示例6: initialize

import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl; //导入依赖的package包/类
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);
}
 
开发者ID:walkmod,项目名称:walkmod-core,代码行数:33,代码来源:ScriptProcessor.java

示例7: configureScriptEngine

import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl; //导入依赖的package包/类
/**
 * SCIPIO: Configures the given script engine with any non-default settings needed.
 * <p>
 * 2017-01-27: This now sets our custom GroovyClassLoader on the engine, so that
 * all Groovy scripts will derived from Ofbiz GroovyBaseScript and methods
 * such as <code>from(...)</code> (entity queries) are available everywhere,
 * notably from inline scripts.
 */
private static ScriptEngine configureScriptEngine(ScriptEngine scriptEngine) {
    if (scriptEngine instanceof GroovyScriptEngineImpl) {
        GroovyScriptEngineImpl groovyScriptEngine = (GroovyScriptEngineImpl) scriptEngine;
        groovyScriptEngine.setClassLoader(GroovyUtil.getGroovyScriptClassLoader());
    }
    return scriptEngine;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:16,代码来源:ScriptUtil.java


注:本文中的org.codehaus.groovy.jsr223.GroovyScriptEngineImpl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。