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


Java GroovyObject.invokeMethod方法代码示例

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


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

示例1: execGroovy

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
public static boolean execGroovy(String groovyName, String methodName,
		Object... paramArray) {
	try {
		GroovyObject groovyObject = (GroovyObject) getGroovyObj(groovyName);
		//groovyObject.invokeMethod(methodName, paramArray);
		//GroovyAopInter groovyAop=(GroovyAopInter) MicroContextHolder.getContextMap().get("groovyAop");
		GroovyAopInter firstAop=GroovyAopChain.getFirstAop();
		Object retObj=null;
		if(firstAop==null){
			retObj=groovyObject.invokeMethod(methodName, paramArray);
		}else{
			retObj=firstAop.invokeMethod(groovyObject,groovyName, methodName, paramArray);
		}			
		return true;
	} catch (Throwable t) {
		logger.error(t.toString(), t);
		if(throwFlag){
			throw new RuntimeException(t);
		}
		return false;
	}
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:23,代码来源:GroovyExecUtil.java

示例2: execGroovyRetObj

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
public static Object execGroovyRetObj(String groovyName, String methodName,
		Object... paramArray) {
	try {
		GroovyObject groovyObject = (GroovyObject) getGroovyObj(groovyName);
		//GroovyAopInter groovyAop=(GroovyAopInter) MicroContextHolder.getContextMap().get("groovyAop");
		GroovyAopInter firstAop=GroovyAopChain.getFirstAop();
		Object retObj=null;
		if(firstAop==null){
			retObj=groovyObject.invokeMethod(methodName, paramArray);
		}else{
			retObj=firstAop.invokeMethod(groovyObject,groovyName, methodName, paramArray);
		}
		return retObj;
	} catch (Throwable t) {
		logger.error(t.toString(), t);
		if(throwFlag){
			throw new RuntimeException(t);
		}
		return null;
	}
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:22,代码来源:GroovyExecUtil.java

示例3: getBody

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
/**
 * Creates a Closure representing the body of this GPathResult.
 *
 * @return the body of this GPathResult, converted to a <code>Closure</code>
 */
public Closure getBody() {
    return new Closure(this.parent,this) {
        public void doCall(Object[] args) {
            final GroovyObject delegate = (GroovyObject)getDelegate();
            final GPathResult thisObject = (GPathResult)getThisObject();

            Node node = (Node)thisObject.getAt(0);
            List children = node.children();

            for (Object child : children) {
                delegate.getProperty("mkp");
                if (child instanceof Node) {
                    delegate.invokeMethod("yield", new Object[]{new NodeChild((Node) child, thisObject, "*", null)});
                } else {
                    delegate.invokeMethod("yield", new Object[]{child});
                }
            }                
        }
    };
}
 
开发者ID:apache,项目名称:groovy,代码行数:26,代码来源:GPathResult.java

示例4: executeGroovyHandler

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
/**
 * If something goes wrong here the returnBinding is unchanged, that is the
 * regular action commences.
 */
public static Map<String, Object> executeGroovyHandler(String handlerClass, Map<String, Object> inputBinding) {
	Map<String, Object> returnBinding = null;
	if (GroovyScriptLoader.getInstance().doesGroovyClassExist(handlerClass)) {
		try {
			// GroovyObject handler =
			// GroovyScriptLoader.getInstance().newInstance(handlerClass);
			GroovyObject handler = (GroovyObject) GroovyScriptLoader.getInstance().getGroovyClass(handlerClass).newInstance();
			returnBinding = (Map<String, Object>) handler.invokeMethod(HANDLE_METHOD_NAME, inputBinding);
		} catch (Exception e) {
			LOGGER.error("Problem calling Groovy EventHandler: " + e.getMessage());
			LOGGER.debug(ExceptionUtils.getStackTrace(e));
		}
	} else {
		LOGGER.debug("The Groovy class " + handlerClass + " was not found");
	}
	return returnBinding;
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:22,代码来源:GroovyScriptExecuter.java

示例5: logical

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
private static Object logical(Object node, String op, final Action<Object> withNode) {
    GroovyObject groovyObject = (GroovyObject) node;
    groovyObject.invokeMethod(op, new Closure(null, null) {
        void doCall() {
            withNode.execute(getDelegate());
        }
    });
    return node;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:10,代码来源:PatternSetAntBuilderDelegate.java

示例6: addFilenames

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
private static Object addFilenames(Object node, Iterable<String> filenames, boolean caseSensitive) {
    GroovyObject groovyObject = (GroovyObject) node;
    Map<String, Object> props = new HashMap<String, Object>(2);
    props.put("casesensitive", caseSensitive);
    for (String filename : filenames) {
        props.put("name", AntUtil.maskFilename(filename));
        groovyObject.invokeMethod("filename", props);
    }
    return node;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:11,代码来源:PatternSetAntBuilderDelegate.java

示例7: executeGroovyScript

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
/**
 * Execute groovy script t.
 *
 * @param <T>          the type parameter
 * @param groovyScript the groovy script
 * @param methodName   the method name
 * @param args         the args
 * @param clazz        the clazz
 * @return the t
 */
public static <T> T executeGroovyScript(final Resource groovyScript,
                                        final String methodName,
                                        final Object[] args,
                                        final Class<T> clazz) {

    if (groovyScript == null || StringUtils.isBlank(methodName)) {
        return null;
    }

    final ClassLoader parent = ScriptingUtils.class.getClassLoader();
    try (GroovyClassLoader loader = new GroovyClassLoader(parent)) {
        final File groovyFile = groovyScript.getFile();
        if (groovyFile.exists()) {                  
            final Class<?> groovyClass = loader.parseClass(groovyFile);
            LOGGER.trace("Creating groovy object instance from class [{}]", groovyFile.getCanonicalPath());

            final GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();

            LOGGER.trace("Executing groovy script's [{}] method, with parameters [{}]", methodName, args);
            final T result = (T) groovyObject.invokeMethod(methodName, args);
            LOGGER.trace("Results returned by the groovy script are [{}]", result);

            if (!clazz.isAssignableFrom(result.getClass())) {
                throw new ClassCastException("Result [" + result
                        + " is of type " + result.getClass()
                        + " when we were expecting " + clazz);
            }
            return result;
        } else {
            LOGGER.trace("Groovy script at [{}] does not exist", groovyScript);
        }
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:47,代码来源:ScriptingUtils.java

示例8: buildClosure

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
public static Closure<?> buildClosure(String... strings) throws IOException {

        Closure<?> closure = null;

        // Create a method returning a closure
        StringBuilder sb = new StringBuilder("def closure() { { script -> ");
        sb.append(StringUtils.join(strings, "\n"));
        sb.append(" } }");

        // Create an anonymous class for the method
        GroovyClassLoader loader = new GroovyClassLoader();
        Class<?> groovyClass = loader.parseClass(sb.toString());

        try {
            // Create an instance of the class
            GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();

            // Invoke the object's method and thus obtain the closure
            closure = (Closure<?>) groovyObject.invokeMethod("closure", null);
        } catch (Throwable e) {
            throw new RuntimeException(e);
        } finally {
            loader.close();
        }

        return closure;
    }
 
开发者ID:alibaba,项目名称:atlas,代码行数:28,代码来源:ClosureFactory.java

示例9: execNextHandler

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
public Object execNextHandler(GroovyObject groovyObject, String GroovyName, String methodName, Object... param){
	if(nextAop!=null){
		return nextAop.invokeMethod(groovyObject, GroovyName, methodName, param);
	}else{
		return groovyObject.invokeMethod(methodName, param);
	}
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:8,代码来源:GroovyAopInter.java

示例10: executeMain

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
protected static void executeMain()
{
	String scriptName = WRAPPER_MANAGER.getGroovyScript();
	if (scriptName == null)
	{
		System.out.println("script not found in configuration -> aborting");
		System.exit(999);
	}
	File scriptFile = new File(scriptName);
	if (!scriptFile.exists())
	{
		System.out.println("script not found -> aborting: "
				+ scriptFile.getAbsolutePath());
		System.exit(999);
	}
	Object[] mainMethodArgs = WRAPPER_MANAGER.getMainMethodArgs();
	try
	{
		ClassLoader parent = WrapperGroovyMain.class.getClassLoader();
		GroovyClassLoader loader = new GroovyClassLoader(parent);
		Class groovyClass = loader.parseClass(scriptFile);
		GroovyObject script = (GroovyObject) groovyClass.newInstance();
		script.invokeMethod("main", mainMethodArgs);
	}
	catch (Throwable e)
	{
		e.printStackTrace();
		exception = e;
	}
}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:31,代码来源:WrapperGroovyMain.java

示例11: addFilenames

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
private static Object addFilenames(Object node, Iterable<String> filenames, boolean caseSensitive) {
    GroovyObject groovyObject = (GroovyObject) node;
    Map<String, Object> props = new HashMap<String, Object>(2);
    props.put("casesensitive", caseSensitive);
    for (String filename : filenames) {
        props.put("name", filename);
        groovyObject.invokeMethod("filename", props);
    }
    return node;
}
 
开发者ID:Pushjet,项目名称:Pushjet-Android,代码行数:11,代码来源:PatternSetAntBuilderDelegate.java

示例12: invokeMethod

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
@Override
public Object invokeMethod(GroovyObject groovyObject, String groovyName, String methodName,Object... param) {
	Object retObj=groovyObject.invokeMethod(methodName, param);
	return retObj;
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:6,代码来源:GroovyAopImpl.java

示例13: build

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
public void build(final GroovyObject builder) {
    builder.getProperty("mkp");
    builder.invokeMethod("yield", new Object[]{text()});
}
 
开发者ID:apache,项目名称:groovy,代码行数:5,代码来源:Attributes.java

示例14: testClosureInClosureTest

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
public void testClosureInClosureTest() throws Exception {
    GroovyObject object = compile("src/test/groovy/ClosureInClosureTest.groovy");
    object.invokeMethod("testInvisibleVariable", null);
}
 
开发者ID:apache,项目名称:groovy,代码行数:5,代码来源:RunBugsTest.java

示例15: testTryCatchBug

import groovy.lang.GroovyObject; //导入方法依赖的package包/类
public void testTryCatchBug() throws Exception {
    GroovyObject object = compile("src/test/groovy/bugs/TryCatchBug.groovy");
    object.invokeMethod("testBug", null);
}
 
开发者ID:apache,项目名称:groovy,代码行数:5,代码来源:RunBugsTest.java


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