Example usage for org.apache.commons.discovery.tools ClassUtils findPublicStaticMethod

List of usage examples for org.apache.commons.discovery.tools ClassUtils findPublicStaticMethod

Introduction

In this page you can find the example usage for org.apache.commons.discovery.tools ClassUtils findPublicStaticMethod.

Prototype

public static Method findPublicStaticMethod(Class clazz, Class returnType, String methodName,
        Class[] paramTypes) 

Source Link

Usage

From source file:org.apache.axis.configuration.EngineConfigurationFactoryFinder.java

private static EngineConfigurationFactory newFactory(Class service, Class[] paramTypes, Object[] param) {
    /**//w w  w. java 2s  .c  o m
     * Some JDK's may link on method resolution (findPublicStaticMethod)
     * and others on method call (method.invoke).
     * 
     * Either way, catch class load/resolve problems and return null.
     */

    try {
        /**
         * Verify that service implements:
         *  public static EngineConfigurationFactory newFactory(Object);
         */
        Method method = ClassUtils.findPublicStaticMethod(service, EngineConfigurationFactory.class,
                "newFactory", paramTypes);

        if (method == null) {
            log.warn(Messages.getMessage("engineConfigMissingNewFactory", service.getName(), requiredMethod));
        } else {
            try {
                return (EngineConfigurationFactory) method.invoke(null, param);
            } catch (InvocationTargetException e) {
                if (e.getTargetException() instanceof NoClassDefFoundError) {
                    log.debug(Messages.getMessage("engineConfigLoadFactory", service.getName()));
                } else {
                    log.warn(Messages.getMessage("engineConfigInvokeNewFactory", service.getName(),
                            requiredMethod), e);
                }
            } catch (Exception e) {
                log.warn(Messages.getMessage("engineConfigInvokeNewFactory", service.getName(), requiredMethod),
                        e);
            }
        }
    } catch (NoClassDefFoundError e) {
        log.debug(Messages.getMessage("engineConfigLoadFactory", service.getName()));
    }

    return null;
}