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


Java GroovyUtil类代码示例

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


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

示例1: testGetObject

import org.ofbiz.base.util.GroovyUtil; //导入依赖的package包/类
public void testGetObject() {
    Long one = Long.valueOf(1);
    byte[] oneBytes = UtilObject.getBytes(one);
    assertNotNull("oneBytes", oneBytes);
    assertEquals("one getObject", one, UtilObject.getObject(oneBytes));
    boolean errorOn = Debug.isOn(Debug.ERROR);
    try {
        Debug.set(Debug.ERROR, false);
        assertNull("parse empty array", UtilObject.getObject(new byte[0]));

        // simulate a ClassNotFoundException
        Object groovySerializable = GroovyUtil.eval("class foo implements java.io.Serializable { }; return new foo()", new HashMap<String, Object>());
        byte[] groovySerializableBytes = UtilObject.getBytes(groovySerializable);
        assertNotNull("groovySerializableBytes", groovySerializableBytes);
        assertNull("groovyDeserializable", UtilObject.getObject(groovySerializableBytes));

        byte[] injectorBytes = UtilObject.getBytes(new SerializationInjector(false, false));
        assertNotNull("injectorBytes good", injectorBytes);
        assertNotNull("injector good", UtilObject.getObject(injectorBytes));
        injectorBytes = UtilObject.getBytes(new SerializationInjector(true, false));
        assertNotNull("injectorBytes bad", injectorBytes);
        assertNull("injector bad", UtilObject.getObject(injectorBytes));
    } finally {
        Debug.set(Debug.ERROR, errorOn);
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:27,代码来源:UtilObjectTests.java

示例2: run

import org.ofbiz.base.util.GroovyUtil; //导入依赖的package包/类
@Override
protected Object run(Map<String, Object> context) throws Exception {
    return GroovyUtil.runScriptAtLocation(location, invokeName, context);
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:5,代码来源:CmsScriptTemplate.java

示例3: serviceInvoker

import org.ofbiz.base.util.GroovyUtil; //导入依赖的package包/类
private Map<String, Object> serviceInvoker(String localName, ModelService modelService, Map<String, Object> context) throws GenericServiceException {
    if (UtilValidate.isEmpty(modelService.location)) {
        throw new GenericServiceException("Cannot run Groovy service with empty location");
    }
    Map<String, Object> params = new HashMap<String, Object>();
    params.putAll(context);

    Map<String, Object> gContext = new HashMap<String, Object>();
    gContext.putAll(context);
    gContext.put(ScriptUtil.PARAMETERS_KEY, params);

    DispatchContext dctx = dispatcher.getLocalContext(localName);
    gContext.put("dctx", dctx);
    gContext.put("dispatcher", dctx.getDispatcher());
    gContext.put("delegator", dispatcher.getDelegator());
    try {
        ScriptContext scriptContext = ScriptUtil.createScriptContext(gContext, protectedKeys);
        ScriptHelper scriptHelper = (ScriptHelper)scriptContext.getAttribute(ScriptUtil.SCRIPT_HELPER_KEY);
        if (scriptHelper != null) {
            gContext.put(ScriptUtil.SCRIPT_HELPER_KEY, scriptHelper);
        }
        Script script = InvokerHelper.createScript(GroovyUtil.getScriptClassFromLocation(this.getLocation(modelService)), GroovyUtil.getBinding(gContext));
        Object resultObj = null;
        if (UtilValidate.isEmpty(modelService.invoke)) {
            resultObj = script.run();
        } else {
            resultObj = script.invokeMethod(modelService.invoke, EMPTY_ARGS);
        }
        if (resultObj == null) {
            resultObj = scriptContext.getAttribute(ScriptUtil.RESULT_KEY);
        }
        if (resultObj != null && resultObj instanceof Map<?, ?>) {
            return cast(resultObj);
        }
        Map<String, Object> result = ServiceUtil.returnSuccess();
        result.putAll(modelService.makeValid(scriptContext.getBindings(ScriptContext.ENGINE_SCOPE), "OUT"));
        return result;
    } catch (GeneralException ge) {
        throw new GenericServiceException(ge);
    } catch (Exception e) {
        // detailMessage can be null.  If it is null, the exception won't be properly returned and logged, and that will
        // make spotting problems very difficult.  Disabling this for now in favor of returning a proper exception.
        // return ServiceUtil.returnError(e.getMessage());
        throw new GenericServiceException("Error running Groovy method [" + modelService.invoke + "] in Groovy file [" + modelService.location + "]: ", e);
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:47,代码来源:GroovyEngine.java

示例4: serviceInvoker

import org.ofbiz.base.util.GroovyUtil; //导入依赖的package包/类
private Map<String, Object> serviceInvoker(String localName, ModelService modelService, Map<String, Object> context) throws GenericServiceException {
    if (UtilValidate.isEmpty(modelService.location)) {
        throw new GenericServiceException("Cannot run Groovy service with empty location");
    }
    Map<String, Object> params = FastMap.newInstance();
    params.putAll(context);

    Map<String, Object> gContext = FastMap.newInstance();
    gContext.putAll(context);
    gContext.put(ScriptUtil.PARAMETERS_KEY, params);

    DispatchContext dctx = dispatcher.getLocalContext(localName);
    gContext.put("dctx", dctx);
    gContext.put("dispatcher", dctx.getDispatcher());
    gContext.put("delegator", dispatcher.getDelegator());
    try {
        ScriptContext scriptContext = ScriptUtil.createScriptContext(gContext, protectedKeys);
        ScriptHelper scriptHelper = (ScriptHelper)scriptContext.getAttribute(ScriptUtil.SCRIPT_HELPER_KEY);
        if (scriptHelper != null) {
            gContext.put(ScriptUtil.SCRIPT_HELPER_KEY, scriptHelper);
        }
        Script script = InvokerHelper.createScript(GroovyUtil.getScriptClassFromLocation(this.getLocation(modelService), groovyClassLoader), GroovyUtil.getBinding(gContext));
        Object resultObj = null;
        if (UtilValidate.isEmpty(modelService.invoke)) {
            resultObj = script.run();
        } else {
            resultObj = script.invokeMethod(modelService.invoke, EMPTY_ARGS);
        }
        if (resultObj == null) {
            resultObj = scriptContext.getAttribute(ScriptUtil.RESULT_KEY);
        }
        if (resultObj != null && resultObj instanceof Map<?, ?>) {
            return cast(resultObj);
        }
        Map<String, Object> result = ServiceUtil.returnSuccess();
        result.putAll(modelService.makeValid(scriptContext.getBindings(ScriptContext.ENGINE_SCOPE), "OUT"));
        return result;
    } catch (GeneralException ge) {
        throw new GenericServiceException(ge);
    } catch (Exception e) {
        return ServiceUtil.returnError(e.getMessage());
    }
}
 
开发者ID:gildaslemoal,项目名称:elpi,代码行数:44,代码来源:GroovyEngine.java


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