Example usage for org.springframework.util ReflectionUtils findMethod

List of usage examples for org.springframework.util ReflectionUtils findMethod

Introduction

In this page you can find the example usage for org.springframework.util ReflectionUtils findMethod.

Prototype

@Nullable
public static Method findMethod(Class<?> clazz, String name, @Nullable Class<?>... paramTypes) 

Source Link

Document

Attempt to find a Method on the supplied class with the supplied name and parameter types.

Usage

From source file:nh.examples.springintegration.order.framework.domain.internal.ReflectionHelper.java

public static Method getAccessibleMethod(String name, Class<?> targetClass, Object parameter) {
    checkNotNull(name);//from w ww.  jav a  2  s  .  c  o  m
    checkNotNull(targetClass);
    checkNotNull(parameter);

    Method executeMethod = ReflectionUtils.findMethod(targetClass, name, parameter.getClass());
    if (executeMethod == null) {
        throw new IllegalStateException(format("No '%s'-method for command type %s found on class %s", name,
                parameter.getClass().getName(), targetClass.getName()));
    }
    ReflectionUtils.makeAccessible(executeMethod);

    return executeMethod;
}

From source file:org.cleverbus.core.common.contextcall.ReflectionCallUtils.java

/**
 * Invokes target method.//from   www  . j  av a 2  s  .  c  om
 *
 * @param params the parameters of the call
 * @param beanFactory the Spring bean factory
 * @return response
 */
public static Object invokeMethod(ContextCallParams params, BeanFactory beanFactory) {
    // find target service
    Object targetService = beanFactory.getBean(params.getTargetType());

    // determine method's argument types
    List<Class> argTypes = new ArrayList<Class>();
    for (Object arg : params.getMethodArgs()) {
        argTypes.add(arg.getClass());
    }

    // exist method?
    Method method = ReflectionUtils.findMethod(params.getTargetType(), params.getMethodName(),
            argTypes.toArray(new Class[] {}));
    if (method == null) {
        throw new IllegalStateException("there is no method '" + params.getMethodName() + "' on target type '"
                + params.getTargetType().getSimpleName() + "'");
    }

    // invoke method
    return ReflectionUtils.invokeMethod(method, targetService, params.getMethodArgs().toArray());
}

From source file:grails.plugin.springsecurity.acl.util.ProxyUtils.java

/**
 * Finds the method in the unproxied superclass if proxied.
 * @param method  the method/*from   w  w  w.j a va2  s. c  o m*/
 * @return  the method in the unproxied class
 */
public static Method unproxy(final Method method) {
    Class<?> clazz = method.getDeclaringClass();

    if (!isProxy(clazz)) {
        return method;
    }

    return ReflectionUtils.findMethod(unproxy(clazz), method.getName(), method.getParameterTypes());
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.acl.ProxyUtils.java

/**
 * Finds the method in the unproxied superclass if proxied.
 * @param method  the method/*from   w  w w . j av  a 2  s.  c  o m*/
 * @return  the method in the unproxied class
 */
public static Method unproxy(final Method method) {
    Class<?> clazz = method.getDeclaringClass();

    if (!AopUtils.isCglibProxyClass(clazz)) {
        return method;
    }

    return ReflectionUtils.findMethod(unproxy(clazz), method.getName(), method.getParameterTypes());
}

From source file:spring.osgi.utils.OsgiBundleUtils.java

/**
 * Returns the underlying BundleContext for the given Bundle. This uses
 * reflection and highly dependent of the OSGi implementation. Should not be
 * used if OSGi 4.1 is being used./* w  w  w . j a  va  2s  .  c  o  m*/
 *
 * @param bundle OSGi bundle
 * @return the bundle context for this bundle
 */
public static BundleContext getBundleContext(final Bundle bundle) {
    if (bundle == null)
        return null;

    // try Equinox getContext
    Method meth = ReflectionUtils.findMethod(bundle.getClass(), "getContext", new Class[0]);

    // fallback to getBundleContext (OSGi 4.1)
    if (meth == null)
        meth = ReflectionUtils.findMethod(bundle.getClass(), "getBundleContext", new Class[0]);

    final Method m = meth;

    if (meth != null) {
        ReflectionUtils.makeAccessible(meth);
        return (BundleContext) ReflectionUtils.invokeMethod(m, bundle);
    }

    // fallback to field inspection (KF and Prosyst)
    final BundleContext[] ctx = new BundleContext[1];

    ReflectionUtils.doWithFields(bundle.getClass(), new FieldCallback() {

        public void doWith(final Field field) throws IllegalArgumentException, IllegalAccessException {
            ReflectionUtils.makeAccessible(field);
            ctx[0] = (BundleContext) field.get(bundle);
        }
    }, new FieldFilter() {

        public boolean matches(Field field) {
            return BundleContext.class.isAssignableFrom(field.getType());
        }
    });

    return ctx[0];
}

From source file:demo.tomcat.TomcatEmbeddedContext.java

public TomcatEmbeddedContext() {
    this.overrideLoadOnStart = ReflectionUtils
            .findMethod(StandardContext.class, "loadOnStartup", Container[].class)
            .getReturnType() == boolean.class;
}

From source file:grails.plugin.quartz2.GrailsArtefactJob.java

public GrailsArtefactJob(Object job) {
    this.job = job;
    this.executeMethod = ReflectionUtils.findMethod(job.getClass(), GrailsJobClassConstants.EXECUTE,
            (Class<?>[]) null);
    if (executeMethod == null) {
        throw new IllegalArgumentException(job.getClass().getName() + " should declare #execute() method");
    }/* w  w  w  .ja  va 2s . c  om*/
    switch (executeMethod.getParameterTypes().length) {
    case 0:
        passExecutionContext = false;
        break;
    case 1:
        passExecutionContext = true;
        break;
    default:
        throw new IllegalArgumentException(job.getClass().getName()
                + "#execute() method should take either no arguments or one argument of type JobExecutionContext");
    }
    this.interruptMethod = ReflectionUtils.findMethod(job.getClass(), GrailsJobClassConstants.INTERRUPT);
}

From source file:com.senfino.yodo.dao.AbstracAcountDao.java

/**
 *
 * @param t//from w  w w  .jav  a2s. c o m
 */
public void create(T t) {
    Method method = ReflectionUtils.findMethod(getDomainClass(), "setDateCreated", new Class[] { Date.class });
    if (method != null) {
        try {
            method.invoke(t, new Date());
        } catch (Exception e) {
        }
    }
    getSession().save(t);
}

From source file:grails.plugins.decorator.DecoratorArtefactHandler.java

@Override
public boolean isArtefactClass(Class clazz) {
    // class shouldn't be null and should end with Decorator suffix
    if (clazz == null || !clazz.getName().endsWith(GrailsDecoratorClass.TYPE)) {
        return false;
    }/* www . j  av a 2  s.  c  o  m*/

    return ReflectionUtils.findMethod(clazz, GrailsDecoratorClass.DECORATE,
            new Class[] { String.class, Map.class }) != null;
}

From source file:grails.plugins.crm.campaign.CampaignArtefactHandler.java

@Override
public boolean isArtefactClass(Class clazz) {
    // class shouldn't be null and should end with Importer suffix
    if (clazz == null || !clazz.getName().endsWith(GrailsCampaignClass.TYPE)) {
        return false;
    }/*  ww w. ja va2s .co  m*/

    return ReflectionUtils.findMethod(clazz, GrailsCampaignClass.PROCESS, new Class[] { Object.class }) != null;
}