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) 

Source Link

Document

Attempt to find a Method on the supplied class with the supplied name and no parameters.

Usage

From source file:org.jboss.spring.vfs.context.ContextClassUtil.java

public static boolean isJBossAS5orHigher() {
    try {// w  w w .  j a v a 2  s  .  com
        Class jBossVersionClass = DelegatingContextLoaderListener.class.getClassLoader()
                .loadClass("org.jboss.Version");
        Object versionObject = ReflectionUtils
                .invokeMethod(ReflectionUtils.findMethod(jBossVersionClass, "getInstance"), null);
        Integer majorVersion = (Integer) ReflectionUtils
                .invokeMethod(ReflectionUtils.findMethod(jBossVersionClass, "getMajor"), versionObject);
        // For JBoss AS versions 5 and higher
        if (majorVersion >= 5) {
            return true;
        }
    } catch (ClassNotFoundException e) {
        // do nothing;
    }
    return false;
}

From source file:io.pivotal.spring.xd.jdbcgpfdist.TestUtils.java

@SuppressWarnings("unchecked")
public static <T> T callMethod(String name, Object target) throws Exception {
    Class<?> clazz = target.getClass();
    Method method = ReflectionUtils.findMethod(clazz, name);

    if (method == null)
        throw new IllegalArgumentException(
                "Cannot find method '" + method + "' in the class hierarchy of " + target.getClass());
    method.setAccessible(true);//from  w ww. j a  va 2  s.co  m
    return (T) ReflectionUtils.invokeMethod(method, target);
}

From source file:org.shept.persistence.provider.hibernate.HibernateUtils_old.java

public static Serializable getIdValue(HibernateDaoSupport dao, Object model) {
    String idStr = getIdentifierPropertyName(dao, model);
    // TODO use BeanWrapper instead ?
    Method idMth = ReflectionUtils.findMethod(model.getClass(), "get" + StringUtils.capitalize(idStr));
    Serializable idxObj = (Serializable) ReflectionUtils.invokeMethod(idMth, model);
    return idxObj;
}

From source file:by.creepid.docsreporter.converter.PdfConverterAdapterTest.java

public PdfConverterAdapterTest() {
    converter = new PoiPdfConverterAdapter();

    Method propSetMethod = ReflectionUtils.findMethod(PoiPdfConverterAdapter.class, "afterPropertiesSet");
    ReflectionUtils.invokeMethod(propSetMethod, converter);
}

From source file:net.paslavsky.springrest.SpringRestClientToStringAdvisorTest.java

@DataProvider
public Object[][] data() {
    return new Object[][] { new Object[] { ReflectionUtils.findMethod(getClass(), "data"), false },
            new Object[] { ReflectionUtils.findMethod(getClass(), "toString"), true }, };
}

From source file:org.grails.datastore.gorm.support.BeforeValidateHelper.java

public void invokeBeforeValidate(final Object target, final List<?> validatedFieldsList) {
    Class<?> domainClass = target.getClass();
    Method method = null;//from   w  w w .j  ava 2s .  co  m
    if (validatedFieldsList == null) {
        // prefer the no-arg version of beforeValidate() if validatedFieldsList
        // is null...
        method = ReflectionUtils.findMethod(domainClass, BEFORE_VALIDATE);
        if (method == null) {
            method = ReflectionUtils.findMethod(domainClass, BEFORE_VALIDATE, List.class);
        }
    } else {
        // prefer the list-arg version of beforeValidate() if
        // validatedFieldsList is not null...
        method = ReflectionUtils.findMethod(domainClass, BEFORE_VALIDATE, List.class);
        if (method == null) {
            method = ReflectionUtils.findMethod(domainClass, BEFORE_VALIDATE);
        }
    }
    if (method != null) {
        ReflectionUtils.makeAccessible(method);
        Class<?>[] parameterTypes = method.getParameterTypes();
        if (parameterTypes.length == 1) {
            ReflectionUtils.invokeMethod(method, target, validatedFieldsList);
        } else {
            ReflectionUtils.invokeMethod(method, target);
        }
    }
}

From source file:am.ik.categolj2.infra.codelist.EnumCodeList.java

@Override
public Map<String, String> asMap() {
    Map<String, String> codeList = new LinkedHashMap<String, String>();
    Method method = ReflectionUtils.findMethod(enumClass, "values");

    Enum<?>[] result = (Enum<?>[]) ReflectionUtils.invokeMethod(method, enumClass);
    for (Enum<?> e : result) {
        CodeListItem item = (CodeListItem) e;
        codeList.put(item.getCodeValue(), item.getCodeLabel());
    }//  ww  w .  j av  a 2 s .  c om

    return Collections.unmodifiableMap(codeList);
}

From source file:net.paslavsky.springrest.SpringRestClientAOPAdvisorTest.java

@DataProvider
public Object[][] data() {
    return new Object[][] {
            new Object[] { ReflectionUtils.findMethod(TestClient1.class, "test3"), TestClient1.class, true },
            new Object[] { ReflectionUtils.findMethod(getClass(), "data"), getClass(), false },
            new Object[] { ReflectionUtils.findMethod(getClass(), "toString"), getClass(), false }, };
}

From source file:edu.wisc.hrs.dao.HrsUtils.java

@SuppressWarnings("unchecked")
private static <T> T callMethodSafe(Object obj, String method, Object... args) {
    if (obj == null) {
        return null;
    }//from  w w  w . j  a  v a  2s  .  co m

    final Class<? extends Object> cls = obj.getClass();

    if (args == null) {
        final Method valueMethod = ReflectionUtils.findMethod(cls, method);
        return (T) ReflectionUtils.invokeMethod(valueMethod, obj);
    }

    final Class<?>[] types = new Class<?>[args.length];
    for (int i = 0; i < args.length; i++) {
        final Object arg = args[i];
        if (arg == null) {
            types[i] = Object.class;
        } else {
            types[i] = arg.getClass();
        }
    }

    final Method valueMethod = ReflectionUtils.findMethod(cls, method, types);
    return (T) ReflectionUtils.invokeMethod(valueMethod, obj, args);
}

From source file:de.codecentric.boot.admin.web.PrefixHandlerMappingTest.java

@Before
public void init() throws Exception {
    this.method = ReflectionUtils.findMethod(TestController.class, "invoke");
}