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


Java JavaEmbedUtils.rubyToJava方法代码示例

本文整理汇总了Java中org.jruby.javasupport.JavaEmbedUtils.rubyToJava方法的典型用法代码示例。如果您正苦于以下问题:Java JavaEmbedUtils.rubyToJava方法的具体用法?Java JavaEmbedUtils.rubyToJava怎么用?Java JavaEmbedUtils.rubyToJava使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jruby.javasupport.JavaEmbedUtils的用法示例。


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

示例1: evaluate

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
public Object evaluate(final String expression, final Map<String, ?> values) throws ExpressionEvaluationException {
    LOG.debug("Evaluating JRuby expression: {1}", expression);
    try {
        final RubyInstanceConfig config = new RubyInstanceConfig();
        config.setCompatVersion(CompatVersion.RUBY1_9);
        final Ruby runtime = JavaEmbedUtils.initialize(new ArrayList<String>(), config);

        final StringBuilder localVars = new StringBuilder();
        for (final Entry<String, ?> entry : values.entrySet()) {
            runtime.getGlobalVariables().set("$" + entry.getKey(), JavaEmbedUtils.javaToRuby(runtime, entry.getValue()));
            localVars.append(entry.getKey()) //
                .append("=$") //
                .append(entry.getKey()) //
                .append("\n");
        }
        final IRubyObject result = runtime.evalScriptlet(localVars + expression);
        return JavaEmbedUtils.rubyToJava(runtime, result, Object.class);
    } catch (final RuntimeException ex) {
        throw new ExpressionEvaluationException("Evaluating JRuby expression failed: " + expression, ex);
    }
}
 
开发者ID:sebthom,项目名称:oval,代码行数:22,代码来源:ExpressionLanguageJRubyImpl.java

示例2: findAssertionProviderMethods

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private void findAssertionProviderMethods() {
    IRubyObject ro = interpreter.evalScriptlet("Object.private_instance_methods");
    String[] methods = (String[]) JavaEmbedUtils.rubyToJava(interpreter, ro, String[].class);
    assertionProviderList = new ArrayList<String>();
    for (Object method : methods) {
        if (method.toString().startsWith("marathon_assert_")) {
            assertionProviderList.add(method.toString());
        }
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:11,代码来源:RubyScript.java

示例3: convertFromRuby

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private Object convertFromRuby(IRubyObject rubyResult, Class<?> returnType) {
	Object result = JavaEmbedUtils.rubyToJava(this.ruby, rubyResult, returnType);
	if (result instanceof RubyArray && returnType.isArray()) {
		result = convertFromRubyArray(((RubyArray) result).toJavaArray(), returnType);
	}
	return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:JRubyScriptUtils.java

示例4: evaluate

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
@Override
public Object evaluate(DeferredObject[] parameters) throws HiveException {
    Object[] args = new Object[argsConverters.length];
    for (int i = 0; i < args.length; i++) {
        args[i] = argsConverters[i].convert(parameters[i + scriptParamPos + 1].get());
    }

    Object ret;
    if (mode == MODE.EVAL) {
        for (int i = 0; i < args.length; i++) {
            container.put("@arg" + (i + 1), args[i]);
        }
        ret = JavaEmbedUtils.rubyToJava((IRubyObject) (evalUnit.run()));
    } else {
        ret = container.callMethod(receiver, evaluateMethod, args);
    }

    if (scriptParamPos == 0) {
        // should return String
        if (ret != null) {
            retText.set(ret.toString());
            return retText;
        } else {
            return null;
        }
    } else {
        return ret;
    }
}
 
开发者ID:gree,项目名称:hive-ruby-scripting,代码行数:30,代码来源:GenericUDFRubyExec.java

示例5: toJavaObject

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private static Object toJavaObject(Object rubyObject) {
    if (rubyObject instanceof IRubyObject) {
        IRubyObject iRubyObject = (IRubyObject) rubyObject;
        return JavaEmbedUtils.rubyToJava(iRubyObject);
    }

    return rubyObject;
}
 
开发者ID:asciidoctor,项目名称:asciidoctorj,代码行数:9,代码来源:RubyHashUtil.java

示例6: executeScript

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private Object executeScript(String name, String main, Object... args)
	{
		RubyObject scriptInstance = instanceCache.get(name);
		if (scriptInstance == null)
		{
			Logger.log(ScriptExecuter.class, Logger.ERROR,
					"Script-Instance for " + name + " do not exists.");
			return null;
		}

		try
		{
			Logger.log(ScriptExecuter.class, Logger.DEBUG,
					"execute script: " + name + "." + main);
			
//			runtime.defineVariable( new GlobalVariable(runtime, "$trigger", toRubyObject(trigger)), Scope.THREAD);
			
			IRubyObject result;
			if (args != null && args.length > 0)
				result = scriptInstance.callMethod(main, toRubyObject(args));
			else
				result = scriptInstance.callMethod(main);
			
			return JavaEmbedUtils.rubyToJava(result);
		}
		catch (RaiseException e)
		{
			Logger.log(ScriptExecuter.class, Logger.ERROR, e);
			return null;
		}
	}
 
开发者ID:TheWhiteShadow3,项目名称:cuina,代码行数:32,代码来源:ScriptExecuter.java

示例7: readGlobals

import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private void readGlobals() {
    interpreter.evalScriptlet("$marathon = RubyMarathon.new('" + driverURL + "')");
    IRubyObject marathon = interpreter.evalScriptlet("$marathon");
    interpreter.evalScriptlet("$test = proc { test }");
    runtime = (MarathonRuby) JavaEmbedUtils.rubyToJava(interpreter, marathon, MarathonRuby.class);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:7,代码来源:RubyScript.java


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