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.heliosphere.athena.base.resource.bundle.ResourceBundleManager.java

/**
 * Returns the resource bundle string of a given enumerated value for the given enumeration class. This
 * method is generally used by enumeration classes using the {@code BundleEnum} annotation.
 * <hr>// w ww  .  j  av  a  2  s .com
 * @param eClass Class of the enumeration.
 * @param e Enumerated value.
 * @param locale {@link Locale} to use for resource string retrieval.
 * @return Resource bundle string.
 */
@SuppressWarnings("nls")
public static final String getResourceForMethodName(@NonNull final Class<? extends Enum<?>> eClass,
        final Enum<?> e, final Locale locale) {
    String key = null;
    ResourceBundle bundle;
    String methodName = null;
    String className;

    int index = 1;
    boolean found = false;
    while (!found) {
        className = Thread.currentThread().getStackTrace()[index].getClassName();
        if (className.equals(eClass.getName())) {
            methodName = Thread.currentThread().getStackTrace()[index].getMethodName();
            found = true;
        } else {
            index++;
        }
    }

    if (found) {
        for (Method method : eClass.getMethods()) {
            BundleEnum annotation = method.getAnnotation(BundleEnum.class);
            if (annotation != null && method.getName().equals(methodName)) {
                bundle = ResourceBundle.getBundle(annotation.file(), locale);
                key = annotation.path() + "." + e.name();
                return bundle.getString(key);
            }
        }
    }

    throw new ResourceBundleException(BundleAthenaBase.ResourceBundleInvalidKey, null, key, null, locale, e);
}

From source file:com.heliosphere.demeter.base.resource.bundle.ResourceBundleManager.java

/**
 * Returns the resource bundle string of a given enumerated value for the given enumeration class. This
 * method is generally used by enumeration classes using the {@code BundleEnum} annotation.
 * <hr>//from ww w . ja v a  2  s .  c  o  m
 * @param eClass Class of the enumeration.
 * @param e Enumerated value.
 * @param locale {@link Locale} to use for resource string retrieval.
 * @return Resource bundle string.
 */
@SuppressWarnings("nls")
public static final String getResourceForMethodName(@NonNull final Class<? extends Enum<?>> eClass,
        final Enum<?> e, final Locale locale) {
    String key = null;
    ResourceBundle bundle;
    String methodName = null;
    String className;

    int index = 1;
    boolean found = false;
    while (!found) {
        className = Thread.currentThread().getStackTrace()[index].getClassName();
        if (className.equals(eClass.getName())) {
            methodName = Thread.currentThread().getStackTrace()[index].getMethodName();
            found = true;
        } else {
            index++;
        }
    }

    if (found) {
        for (Method method : eClass.getMethods()) {
            BundleEnum annotation = method.getAnnotation(BundleEnum.class);
            if (annotation != null && method.getName().equals(methodName)) {
                bundle = ResourceBundle.getBundle(annotation.file(), locale);
                key = annotation.path() + "." + e.name();
                return bundle.getString(key);
            }
        }
    }

    throw new ResourceBundleException(BundleDemeterBase.ResourceBundleInvalidKey, null, key, null, locale, e);
}

From source file:com.sf.ddao.shards.conn.ShardedConnectionHandler.java

protected void initShardKeys(Class clazz) {
    for (Method method : clazz.getMethods()) {
        ShardKeyGetter shardKeyGetter = createShardKeyGetter(method);
        if (shardKeyGetter != null) {
            shardKeyGetterMap.put(method, shardKeyGetter);
        }//from  www.ja va 2  s . c  o m
    }
}

From source file:pl.com.bottega.ecommerce.system.saga.impl.SimpleSagaEngine.java

private Method findHandlerMethodForEvent(Class<?> type, Object event) {
    for (Method method : type.getMethods()) {
        if (method.getAnnotation(SagaAction.class) != null || method.getAnnotation(LoadSaga.class) != null) {
            if (method.getParameterTypes().length == 1
                    && method.getParameterTypes()[0].isAssignableFrom(event.getClass())) {
                return method;
            }//from   w  w w . j a  v a2  s . c  o  m
        }
    }
    throw new RuntimeException("no method handling " + event.getClass());
}

From source file:com.ephesoft.dcma.workflows.aspects.DCMAPostProcessAspect.java

/**
 * Executes post-process annotation methods in a service for a batch.
 * /* www .jav a 2  s .  co  m*/
 * @param joinPoint {@link JoinPoint}
 * @throws DCMAException
 */
@AfterReturning("execution(* com.ephesoft.dcma.*.service.*.*(..)) "
        + "&& !within(com.ephesoft.dcma.da.service.*) " + "&& !within(com.ephesoft.dcma.workflows.service.*)")
public void postProcess(final JoinPoint joinPoint) throws DCMAException {
    try {
        final Object target = joinPoint.getTarget();
        if (null != target) {
            Class<?> clazz = ClassUtils.getUserClass(target);
            Method[] methods = clazz.getMethods();
            if (!ArrayUtils.isEmpty(methods)) {
                findAspectMethodsToExecute(joinPoint, target, methods);
            }
        }
    } catch (final Exception exception) {
        LOGGER.error("Exception in Post-processing", exception);
        throw new DCMAException("Exception in Post-processing", exception);
    }
}

From source file:com.ephesoft.dcma.workflows.aspects.DCMAPreProcessAspect.java

/**
 * Executes pre-process annotation methods in a service for a batch.
 * //from   ww w . j a  va2s .  c  om
 * @param joinPoint {@link JoinPoint}
 * @throws DCMAException {@link DCMAException}
 */
@Before("execution(* com.ephesoft.dcma.*.service.*.*(..)) " + "&& !within(com.ephesoft.dcma.da.service.*) "
        + "&& !within(com.ephesoft.dcma.workflows.service.*)")
public void preprocess(JoinPoint joinPoint) throws DCMAException {
    try {
        Object target = joinPoint.getTarget();
        if (null != target) {
            Class<?> clazz = ClassUtils.getUserClass(target);
            Method[] methods = clazz.getMethods();
            if (!ArrayUtils.isEmpty(methods)) {
                findAspectMethodsToExecute(joinPoint, target, methods);
            }
        }
    } catch (Exception exception) {
        LOGGER.error("Exception in Pre-processing", exception);
        throw new DCMAException("Exception in Pre-processing", exception);
    }
}

From source file:io.realm.datastorebenchmark.DataStoreTest.java

public void allTests() {
    Class clazz = this.getClass();
    Method[] methods = clazz.getMethods();
    for (Method method : methods) {
        String name = method.getName();
        if (name.startsWith("test")) {
            try {
                Log.i("DataStoreBenchmark", "invoking " + getTag() + ":" + method.getName());
                method.invoke(this);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }//  ww w  . ja va  2 s.c  o m
        }
    }
}

From source file:mangotiger.bus.BusImpl.java

public void register(final Object consumer) {
    final Class clazz = consumer.getClass();
    for (Method method : clazz.getMethods()) {
        final Matcher matcher = eventMethod.matcher(method.toString());
        final boolean isEventMethod = matcher.matches();
        if (isEventMethod) {
            final String eventName = Strings.decapitalize(matcher.group(2));
            register(consumer, eventName);
        }//www. ja v  a  2s . com
    }
}

From source file:fr.cvlaminck.merging.impl.mergers.object.DefaultObjectMerger.java

protected List<Field> getPublicFieldsWithGetterAndSetter(Class<?> object) {
    List<Field> fields = new ArrayList<>();
    for (Method method : object.getMethods()) {
        if (method.getName().startsWith("get")) {
            Method setter = getSetterFromGetter(object, method);
            if (setter != null)
                fields.add(new Field(getFieldNameFromGetter(method), setter, method));
        }// ww w  .j  a v a2  s .co  m
    }
    return fields;
}

From source file:edu.duke.cabig.c3pr.AbstractTestCase.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();/*  ww w  .j av  a  2 s  .c o m*/
        }
    }
    return registerMockFor(forClass, methods.toArray(new Method[methods.size()]));
}