Example usage for java.lang Class getMethods

List of usage examples for java.lang Class getMethods

Introduction

In this page you can find the example usage for java.lang Class getMethods.

Prototype

@CallerSensitive
public Method[] getMethods() throws SecurityException 

Source Link

Document

Returns an array containing Method objects reflecting all the public methods of the class or interface represented by this Class object, including those declared by the class or interface and those inherited from superclasses and superinterfaces.

Usage

From source file:com.fortuityframework.spring.broker.SpringEventListenerLocator.java

/**
 * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
 *///from   ww  w .jav a  2 s . com
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ContextStartedEvent || event instanceof ContextRefreshedEvent) {
        ApplicationContext context = ((ApplicationContextEvent) event).getApplicationContext();

        for (String beanDefinitionName : context.getBeanDefinitionNames()) {
            Class<?> type = context.getType(beanDefinitionName);

            if (type != null && type.getMethods() != null) {
                for (Method m : type.getMethods()) {
                    registerMethodAsListener(context, beanDefinitionName, m);
                }
            }
        }
    }

}

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

private Method getMethod(Class<?> clazz, String methodName) {
    Set<Method> candidates = new HashSet<Method>(1);
    Method[] methods = clazz.getMethods();
    for (Method method : methods) {
        if (methodName.equals(method.getName())) {
            candidates.add(method);/*from w  ww  .ja va  2s .co m*/
        }
    }
    if (candidates.size() == 1) {
        return candidates.iterator().next();
    } else if (candidates.isEmpty()) {
        throw new IllegalStateException("Expected method not found: " + clazz + "." + methodName);
    } else {
        throw new IllegalStateException("No unique method found: " + clazz + "." + methodName);
    }
}

From source file:com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable.java

/**
 * {@inheritDoc}/*w ww.  j  av a2s  . c  o m*/
 * Same as base implementation, but includes all methods inherited from super classes as well.
 */
@Override
public void defineFunctionProperties(final String[] names, final Class<?> clazz, final int attributes) {
    final Method[] methods = clazz.getMethods();
    for (final String name : names) {
        final Method method = findMethod(methods, name);
        if (method == null) {
            throw Context.reportRuntimeError("Method \"" + name + "\" not found in \"" + clazz.getName() + '"');
        }
        final FunctionObject f = new FunctionObject(name, method, this);
        defineProperty(name, f, attributes);
    }
}

From source file:com.mycollab.db.persistence.service.DefaultCrudService.java

private void findCacheUpdateMethod() {
    ICrudGenericDAO<K, T> crudMapper = getCrudMapper();
    Class<? extends ICrudGenericDAO> crudMapperCls = crudMapper.getClass();
    for (Method method : crudMapperCls.getMethods()) {
        if ("updateByPrimaryKeyWithBLOBs".equals(method.getName())) {
            cacheUpdateMethod = method;/*from   www.ja va 2s. co  m*/
            return;
        } else if ("updateByPrimaryKey".equals(method.getName())) {
            cacheUpdateMethod = method;
        }
    }
}

From source file:edu.duke.cabig.c3pr.utils.ApplicationTestCase.java

protected <T extends C3PRBaseDao> T registerDaoMockFor(Class<T> forClass) {
    List<Method> methods = new LinkedList<Method>(Arrays.asList(forClass.getMethods()));
    for (Iterator<Method> iterator = methods.iterator(); iterator.hasNext();) {
        Method method = iterator.next();
        if ("domainClass".equals(method.getName())) {
            iterator.remove();//from   w ww. jav a  2s . c o  m
        }
    }
    return registerMockFor(forClass, methods.toArray(new Method[methods.size()]));
}

From source file:koper.event.DataEventListenerPostProcessor.java

/**
 * @param bean0/*w w  w.ja  v a2  s  .c  o m*/
 */
protected void registerDataEventListener(Object dataEventListener, String dataObjectName) {

    if (StringUtils.isBlank(dataObjectName)) {
        throw new IllegalArgumentException(
                "dataObjectName can't be blank of dataEventListener class! Use @DataListener or implements DataEventListener interface."
                        + dataEventListener.getClass());
    }
    Class<?> clazz = dataEventListener.getClass();

    Method[] methods = clazz.getMethods();
    for (Method method : methods) {
        if (!isExcludedMethod(method)) {
            if (method.getName().startsWith("on")) {
                registerDataEventListener(dataEventListener, dataObjectName, method);
            }
        }
    }
}

From source file:com.sf.ddao.chain.ChainInvocationHandler.java

public void init(Class<?> iFace) {
    List<Command> classLevelList = new ArrayList<Command>();
    addChainMemebers(iFace, classLevelList);
    final Method[] methods = iFace.getMethods();
    for (Method method : methods) {
        List<Command> list = new ArrayList<Command>(classLevelList.size() + method.getAnnotations().length);
        list.addAll(classLevelList);/*from   w w w  .  j  a  v a 2 s.c  o  m*/
        addChainMemebers(method, list);
        map.put(method, new MethodInvocationHandler(iFace, method, list));
    }
}

From source file:com.esofthead.mycollab.core.persistence.service.DefaultCrudService.java

@SuppressWarnings("rawtypes")
private void findCacheUpdateMethod() {
    ICrudGenericDAO<K, T> crudMapper = getCrudMapper();
    Class<? extends ICrudGenericDAO> crudMapperCls = crudMapper.getClass();
    for (Method method : crudMapperCls.getMethods()) {
        if ("updateByPrimaryKeyWithBLOBs".equals(method.getName())) {
            cacheUpdateMethod = method;/*from w  w  w . ja  v a2  s .com*/
            return;
        } else if ("updateByPrimaryKey".equals(method.getName())) {
            cacheUpdateMethod = method;
        }
    }
}

From source file:com.wavemaker.runtime.ws.salesforce.SalesforceSupport.java

public static Object convertToQueryReturnType(Class cls, List<JSONObject> list) {
    List<Object> rtn = new ArrayList<Object>();
    Method[] methods = cls.getMethods();
    try {/*  ww w .ja v a2 s.co  m*/
        for (JSONObject jsonObj : list) {
            Collection<Object> vals = jsonObj.values();
            int i = 0;
            Object obj = cls.newInstance();
            for (Object val : vals) {
                Method method = getSetMethod(i, methods);
                method.invoke(obj, val);
                i++;
            }
            rtn.add(obj);
        }
    } catch (Exception ex) {
        throw new WMRuntimeException(ex);
    }
    return rtn;
}

From source file:com.openmeap.web.form.ParameterMapBuilder.java

private Method methodForFormName(Class<?> clazz, String formName) {

    for (Method method : clazz.getMethods()) {
        Parameter param = method.getAnnotation(Parameter.class);
        if (param != null) {
            if (formNameForMethod(param, method).equals(formName)) {
                return method;
            }/* w  w  w  .j a  v a  2s.c o m*/
        }
    }
    return null;
}