當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。