Java Code Examples for groovy.lang.MetaClass#invokeStaticMethod()

The following examples show how to use groovy.lang.MetaClass#invokeStaticMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InvokerHelper.java    From groovy with Apache License 2.0 6 votes vote down vote up
/**
 * Invokes the given method on the object.
 */
public static Object invokeMethod(Object object, String methodName, Object arguments) {
    if (object == null) {
        object = NullObject.getNullObject();
        //throw new NullPointerException("Cannot invoke method " + methodName + "() on null object");
    }

    // if the object is a Class, call a static method from that class
    if (object instanceof Class) {
        Class theClass = (Class) object;
        MetaClass metaClass = metaRegistry.getMetaClass(theClass);
        return metaClass.invokeStaticMethod(object, methodName, asArray(arguments));
    }

    // it's an instance; check if it's a Java one
    if (!(object instanceof GroovyObject)) {
        return invokePojoMethod(object, methodName, arguments);
    }

    // a groovy instance (including builder, closure, ...)
    return invokePogoMethod(object, methodName, arguments);
}
 
Example 2
Source File: GrailsDataBinder.java    From AlgoTrader with GNU General Public License v2.0 5 votes vote down vote up
private Object autoInstantiateDomainInstance(Class<?> type) {
	Object created = null;
	try {
		MetaClass mc = GroovySystem.getMetaClassRegistry().getMetaClass(type);
		if (mc != null) {
			created = mc.invokeStaticMethod(type, CreateDynamicMethod.METHOD_NAME, new Object[0]);
		}
	} catch (MissingMethodException mme) {
		LOG.warn("Unable to auto-create type, 'create' method not found");
	} catch (GroovyRuntimeException gre) {
		LOG.warn("Unable to auto-create type, Groovy Runtime error: " + gre.getMessage(), gre);
	}
	return created;
}
 
Example 3
Source File: OwnedMetaClass.java    From groovy with Apache License 2.0 4 votes vote down vote up
public Object invokeStaticMethod(Object object, String methodName, Object[] arguments) {
    final Object owner = getOwner();
    final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
    return ownerMetaClass.invokeStaticMethod(object, methodName, arguments);
}
 
Example 4
Source File: InvokerHelper.java    From groovy with Apache License 2.0 4 votes vote down vote up
public static Object invokeStaticMethod(Class type, String method, Object arguments) {
    MetaClass metaClass = metaRegistry.getMetaClass(type);
    return metaClass.invokeStaticMethod(type, method, asArray(arguments));
}