Example usage for org.apache.commons.lang ClassUtils getPublicMethod

List of usage examples for org.apache.commons.lang ClassUtils getPublicMethod

Introduction

In this page you can find the example usage for org.apache.commons.lang ClassUtils getPublicMethod.

Prototype

public static Method getPublicMethod(Class<?> cls, String methodName, Class<?> parameterTypes[])
        throws SecurityException, NoSuchMethodException 

Source Link

Document

Returns the desired Method much like Class.getMethod, however it ensures that the returned Method is from a public class or interface and not from an anonymous inner class.

Usage

From source file:org.jdal.dao.hibernate.HibernateExecutable.java

/**
 * @param uniqueResult//www.  j  ava 2 s  .  co  m
 * @return
 */
@SuppressWarnings("rawtypes")
private Object invoke(String name, Object... args) {

    Method method = methodMap.get(name);
    if (method == null) {
        Class clazz = executable.getClass();
        Class[] types = new Class[args.length];

        for (int i = 0; i < args.length; i++) {
            types[i] = args[i].getClass();
        }

        try {
            method = ClassUtils.getPublicMethod(clazz, name, types);
        } catch (Exception e) {
            log.error(e);
        }

        methodMap.put(name, method);
    }

    try {
        return method.invoke(executable, args);
    } catch (Exception e) {
        log.error(e);
    }

    return null;
}

From source file:org.opentaps.testsuit.web.IntegrTestsServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {//from   w w  w .j  a v  a 2s. c om
        String serviceName = request.getParameter("service");
        String testName = request.getParameter("test");
        if (GenericValidator.isBlankOrNull(serviceName) || GenericValidator.isBlankOrNull(testName)) {
            throw new ServletException("Missing required parameters.");
        }

        InitialContext context = new InitialContext();
        Object testSrvc = context.lookup(String.format("osgi:service/%1$s", serviceName));
        if (testSrvc == null) {
            throw new ServletException("Test service is unavailable.");
        }

        PrintWriter out = response.getWriter();

        try {
            Method testCase = ClassUtils.getPublicMethod(testSrvc.getClass(), testName, new Class[0]);
            testCase.invoke(testSrvc, new Object[] {});

            out.println(BaseTestCase.SUCCESS_RET_CODE);

        } catch (InvocationTargetException e) {
            out.println(e.getTargetException().getLocalizedMessage());
            return;
        }

    } catch (NamingException e) {
        throw new ServletException(e);
    } catch (IllegalArgumentException e) {
        throw new ServletException(e);
    } catch (IllegalAccessException e) {
        throw new ServletException(e);
    } catch (SecurityException e) {
        throw new ServletException(e);
    } catch (NoSuchMethodException e) {
        throw new ServletException(e);
    }
}

From source file:org.talend.dataprep.transformation.api.action.context.TransformationContext.java

/**
 * Cleanup transformation context.//from w  ww .j a v  a2 s .  co  m
 */
public void cleanup() {
    final Collection<ActionContext> allActionsContexts = getAllActionsContexts();
    LOGGER.debug("cleaning up {} action context(s) ", allActionsContexts.size());
    for (ActionContext currentContext : allActionsContexts) {
        currentContext.getContextEntries().forEach(contextEntry -> {
            try {
                try {
                    final Method destroy = ClassUtils.getPublicMethod(contextEntry.getClass(), "destroy",
                            new Class[0]);
                    LOGGER.debug("destroy {}", contextEntry);
                    destroy.invoke(contextEntry);
                } catch (NoSuchMethodException e) {
                    LOGGER.trace("Context entry {} does not need clean up.", contextEntry, e);
                }
            } catch (Exception error) {
                LOGGER.warn("error cleaning action context {}", contextEntry, error);
            }
        });
    }
}