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.mirth.connect.client.core.api.util.OperationUtil.java

public static Set<Operation> getOperations(Class<?> servletInterface) {
    Set<Operation> operations = new HashSet<Operation>();
    for (Method method : servletInterface.getMethods()) {
        MirthOperation annotation = method.getAnnotation(MirthOperation.class);
        if (annotation != null) {
            operations.add(new Operation(annotation.name(), annotation.display(), annotation.type(),
                    annotation.auditable()));
        }//from  w ww  .j av a 2s . co  m
    }
    return operations;
}

From source file:com.mirth.connect.client.core.api.util.OperationUtil.java

public static Set<Operation> getAbortableOperations(Class<?> servletInterface) {
    Set<Operation> operations = new HashSet<Operation>();
    for (Method method : servletInterface.getMethods()) {
        MirthOperation annotation = method.getAnnotation(MirthOperation.class);
        if (annotation != null && annotation.abortable()) {
            operations.add(new Operation(annotation.name(), annotation.display(), annotation.type(),
                    annotation.auditable()));
        }/* w ww  .j a  va 2s . com*/
    }
    return operations;
}

From source file:com.spstudio.common.log.ServiceExceptionLogAspect.java

/**
 * */*from w  w w  .  j  a  va2s. c  o m*/
 * ???? service *
 *
 *
 * @param joinPoint 
 *
 * @return ??
 *
 * @throws Exception *
 */
public static String getServiceMthodDescription(JoinPoint joinPoint) throws Exception {

    String targetName = joinPoint.getTarget().getClass().getName();

    String methodName = joinPoint.getSignature().getName();

    Object[] arguments = joinPoint.getArgs();

    Class targetClass = Class.forName(targetName);

    Method[] methods = targetClass.getMethods();

    String description = ":" + targetName + " ;??:" + methodName
            + " ;???:";

    for (Method method : methods) {

        if (method.getName().equals(methodName)) {

            Class[] clazzs = method.getParameterTypes();

            if (clazzs.length == arguments.length) {

                description += method.getAnnotation(ServiceExceptionLog.class).description();

                break;

            }

        }

    }

    return description;

}

From source file:mangotiger.poker.channel.EventChannelImpl.java

static Method methodForEvent(final Class<?> subscriber, final Class<?> event) {
    for (Method method : subscriber.getMethods()) {
        if (methodMatchesEvent(method, event)) {
            return method;
        }//from w  ww  . j  a  v  a  2s .  c  om
    }
    return null;
}

From source file:org.openmrs.module.webservices.rest.web.DelegatingCrudResourceTest.java

/**
 * Convenience method that checks of the specified resource class has a method for setting the
 * given property/*from   w  w  w.  j a  v  a2  s  .  c o  m*/
 * 
 * @param propName
 * @param resource
 * @return
 */
@SuppressWarnings("rawtypes")
private static boolean hasSetterMethod(String propName, Class resourceClass) {
    for (Method candidate : resourceClass.getMethods()) {
        PropertySetter ann = candidate.getAnnotation(PropertySetter.class);
        if (ann != null && ann.value().equals(propName)) {
            return true;
        }
    }

    return false;
}

From source file:com.sapienter.jbilling.server.user.validator.NoUserInfoInPasswordValidator.java

/**
 * This method verifies that the password passed as parameter does not
 * contain any user information as retrieved from the user contact
 * record.// w ww.  j av  a2 s .  c  o  m
 * @param userId User ID of the user whose password is being verified.
 * @param password the new password that is being validated.
 * @return <code>true</code> if the password passes the verification,
 * otherwise returns <code>false</code>.
 */
public static boolean basicValidation(Object dto, String password) {
    boolean retVal = true;
    try {
        if (dto == null) {
            retVal = false;
        } else {
            // Check all the fields against the password by using reflection.
            Class cl = dto.getClass();
            Method m[] = cl.getMethods();
            for (int i = 0; i < m.length && retVal == true; i++) {
                // We're interested only in the getter methods
                // that return a String value.
                if (m[i].getReturnType() != String.class || !m[i].getName().startsWith("get")) {
                    continue;
                }

                // We can now invoke the method via reflection to retrieve
                // the value.
                String temp = (String) m[i].invoke(dto);
                if (temp == null) {
                    continue;
                }

                // Now check the value against the provided password.
                if (temp.equalsIgnoreCase(password)) {
                    retVal = false;
                    break;
                }
                /*
                 * Now, break up the returned values into words and check
                 * those. This intercepts a case where, for example, the
                 * contact's name is "John Michael Doe" and the password
                 * is set to be only "michael".
                 */
                String te[] = temp.split(" ");
                for (int j = 0; j < te.length; j++) {
                    if (te[j].equalsIgnoreCase(password)) {
                        retVal = false;
                        break;
                    }
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Exception validating for contact in password ", e);
        retVal = false;
    }
    return retVal;
}

From source file:de.unisb.cs.st.javalanche.mutation.runtime.testDriver.junit.Junit4Util.java

public static Method getSuiteMethod(Class<?> forName) {
    Method[] methods = forName.getMethods();
    for (Method method : methods) {
        if (method.getName().equals("suite") && method.getParameterTypes().length == 0) {
            return method;
        }//from  w ww. j a  va 2s .c o m
    }
    return null;
}

From source file:com.infinira.aerospike.dataaccess.util.Utils.java

public static void printSetterMethods(String className) throws Throwable {
    try {//from w  w  w  .  ja va  2s. c  o  m
        Class c = Class.forName(className);
        Method m[] = c.getMethods();
        for (int i = 0; i < m.length; i++)
            if (m[i].getName().startsWith("set")) {
                System.out.println("instanceName." + m[i].getName() + "(\"valOne\");");
            }

    } catch (Throwable e) {
        log(e);
        throw e;
    }
}

From source file:com.infinira.aerospike.dataaccess.util.Utils.java

public static void print(String className) throws Throwable {
    try {//from w  w  w. j a  v  a 2 s .  co  m
        Class c = Class.forName(className);
        Method m[] = c.getMethods();
        for (int i = 0; i < m.length; i++)
            if (m[i].getName().startsWith("set")) {
                System.out.println("instanceName." + m[i].getName() + "(\"valOne\");");
            }

    } catch (Throwable e) {
        log(e);
        throw e;
    }
}

From source file:org.springframework.data.web.JsonProjectingMethodInterceptorFactory.java

/**
 * Returns whether the given type contains a method with a {@link org.springframework.data.web.JsonPath} annotation.
 * //w  w w  .  j  a v  a2  s  .  c  o  m
 * @param type must not be {@literal null}.
 * @return
 */
private static boolean hasJsonPathAnnotation(Class<?> type) {

    for (Method method : type.getMethods()) {
        if (AnnotationUtils.findAnnotation(method, org.springframework.data.web.JsonPath.class) != null) {
            return true;
        }
    }

    return false;
}