當前位置: 首頁>>代碼示例>>Java>>正文


Java ScriptingContainer.put方法代碼示例

本文整理匯總了Java中org.jruby.embed.ScriptingContainer.put方法的典型用法代碼示例。如果您正苦於以下問題:Java ScriptingContainer.put方法的具體用法?Java ScriptingContainer.put怎麽用?Java ScriptingContainer.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jruby.embed.ScriptingContainer的用法示例。


在下文中一共展示了ScriptingContainer.put方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import org.jruby.embed.ScriptingContainer; //導入方法依賴的package包/類
@Override
public ScriptExecutionResult execute(GameScript<EmbedEvalUnit> s, ScriptBindings bindings,
		boolean returnResult) throws Exception {
	PerThreadGameScript<EmbedEvalUnit> script = (PerThreadGameScript<EmbedEvalUnit>) s;

	ScriptingContainer scriptingContainer = executorPool.getLocalScriptingContainer();
	
	for (String variableName : bindings.keySet()) {
		scriptingContainer.put(variableName, bindings.get(variableName));
	}
	if (!script.hasLocalScript()) {
		script.putLocalScript(scriptingContainer.parse(script.getContent()));
	}
	
	try {
		EmbedEvalUnit embedEvalUnit = script.getScript();
		embedEvalUnit.run();
	} catch (Exception e) {
		if(e.getCause() instanceof ScriptSkippedException) {
			throw new ScriptSkippedException();
		} else {
			throw e;
		}
	}

	if (!returnResult) {
		scriptingContainer.clear();
		return null;
	}		
	ScriptExecutionResult executionResult = new ScriptExecutionResult(scriptingContainer.getVarMap().getMap());
	scriptingContainer.clear();
	return executionResult;
}
 
開發者ID:mini2Dx,項目名稱:miniscript,代碼行數:34,代碼來源:RubyScriptExecutor.java

示例2: rubyCanDecodeHmacSignedToken

import org.jruby.embed.ScriptingContainer; //導入方法依賴的package包/類
@Test
public void rubyCanDecodeHmacSignedToken() throws Exception {
	Jwt jwt = JwtHelper.encode(TEST_CLAIMS, hmac);
	ScriptingContainer container = new ScriptingContainer();
	container.put("@token", jwt.getEncoded());
	container.put("@claims", "");
	String script =
			"require \"rubygems\"\n" +
			"require \"jwt\"\n" +
			"@claims = JWT.decode(@token, \"secret\", \"HS256\").to_json\n" +
			"puts @claims";
	container.runScriptlet(script);
	assertEquals(TEST_CLAIMS, container.get("@claims"));
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:15,代碼來源:RubyJwtIntegrationTests.java

示例3: canDecodeRubyHmacSignedToken

import org.jruby.embed.ScriptingContainer; //導入方法依賴的package包/類
@Test
public void canDecodeRubyHmacSignedToken() throws Exception {
	ScriptingContainer container = new ScriptingContainer();
	container.put("@token", "xxx");
	String script =
			"require \"rubygems\"\n" +
			"require \"jwt\"\n" +
			"@token = JWT.encode({\"some\" => \"payload\"}, \"secret\", \"HS256\")\n" +
			"puts @token";
	container.runScriptlet(script);
	String token = (String) container.get("@token");
	Jwt jwt = JwtHelper.decodeAndVerify(token, hmac);
	assertEquals(TEST_CLAIMS, jwt.getClaims());
	container.terminate();
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:16,代碼來源:RubyJwtIntegrationTests.java

示例4: createApplication

import org.jruby.embed.ScriptingContainer; //導入方法依賴的package包/類
private IRubyObject createApplication() {
  // There's a lot you could do here; for now, we just read a rackup file from the classpath,
  // then build a Rack application based on it.
  ScriptingContainer container = new ScriptingContainer();
  container.put("builder_script", readResource("config.ru"));
  return container.parse("require 'rack'; Rack::Builder.new_from_string(builder_script)").run();
}
 
開發者ID:square,項目名稱:rack-servlet,代碼行數:8,代碼來源:ExampleService.java

示例5: getScript

import org.jruby.embed.ScriptingContainer; //導入方法依賴的package包/類
public JavaEmbedUtils.EvalUnit getScript() throws FileNotFoundException {
    if (this.unit == null) {
        if (!this.configFile.exists()) {
            throw new FileNotFoundException("Configuration file does not exist");
        }

        ScriptingContainer scriptingContainer = new ScriptingContainer(
                LocalContextScope.THREADSAFE,
                LocalVariableBehavior.PERSISTENT);

        scriptingContainer.setOutput(new PrintStream(new NullOutputStream()));

        StringBuilder script = new StringBuilder()
                .append("require 'compass'\n")
                .append("require 'compass/sass_compiler'\n")
                .append("Compass.reset_configuration!\n")
                .append("Compass.add_project_configuration configLocation\n")

                        // remove color codes since they cannot be proceeded correctly by IDE consoles
                .append("Compass.configuration.color_output = false\n")

                .append("Compass.configure_sass_plugin!\n")
                .append("Compass.configuration.on_stylesheet_saved { |filename| callback_logger.onStylesheetSaved(filename) }\n")
                .append("Compass.configuration.on_stylesheet_error { |filename, message| callback_logger.onStylesheetError(filename, message) }\n")
                .append("Compass.configuration.on_sprite_saved { |filename| callback_logger.onSpriteSaved(filename) }\n")
                .append("Dir.chdir(File.dirname(configLocation)) do\n")
                .append("  Compass.sass_compiler.compile!\n")
                .append("end\n");

        scriptingContainer.put("configLocation", this.configFile.getAbsolutePath().replaceAll("\\\\", "/"));
        scriptingContainer.put("callback_logger", callbackLogger);
        this.unit = scriptingContainer.parse(script.toString());
    }

    return this.unit;
}
 
開發者ID:ricardjp,項目名稱:jcompass,代碼行數:37,代碼來源:CompassCompiler.java

示例6: prepareInterpreter

import org.jruby.embed.ScriptingContainer; //導入方法依賴的package包/類
@Override
protected void prepareInterpreter() {
    container = new ScriptingContainer(LocalContextScope.SINGLETHREAD, LocalVariableBehavior.PERSISTENT);
    setLoadPaths(getEngineOperations() != null ? getEngineOperations().getEngine() : null);

    addSpecific();

    PROCESSOR_CLASSES.forEach((interfaceClass, scriptClass) -> addImport(scriptClass, interfaceClass.getSimpleName()));
    addImport(JRubyPlugin.class, Plugin.class.getSimpleName());

    getStandardImportClasses().forEach(cls -> addImport(cls));

    addImport(RubyUtils.class);

    container.put(createVariableName(KnowledgeBaseConstants.VAR_ENGINE_OPERATIONS), getEngineOperations());

    container.setErrorWriter(new JRubyLogErrorWriter());
}
 
開發者ID:softelnet,項目名稱:sponge,代碼行數:19,代碼來源:JRubyKnowledgeBaseInterpreter.java


注:本文中的org.jruby.embed.ScriptingContainer.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。