Example usage for org.apache.commons.lang.reflect ConstructorUtils getAccessibleConstructor

List of usage examples for org.apache.commons.lang.reflect ConstructorUtils getAccessibleConstructor

Introduction

In this page you can find the example usage for org.apache.commons.lang.reflect ConstructorUtils getAccessibleConstructor.

Prototype

public static Constructor getAccessibleConstructor(Class cls, Class[] parameterTypes) 

Source Link

Document

Returns a constructor given a class and signature.

Usage

From source file:org.diffkit.diff.sns.DKAbstractSheet.java

/**
 * throws IllegalArgumentException if it's not able to find a handler in
 * availableSheetClasses_ for file_//  w w  w .  j av  a2 s  . c  om
 */
@SuppressWarnings("unchecked")
public static DKSheet constructSheet(File file_, String requestedName_, boolean isSorted_, boolean hasHeader_,
        boolean validateLazily_, Class<DKSheet>[] availableSheetClasses_) throws NoSuchMethodException,
        IllegalAccessException, InvocationTargetException, InstantiationException {
    DKValidate.notNull(file_);
    DKValidate.notEmpty((Object[]) availableSheetClasses_);
    Class<DKSheet> handlerClass = getHandlerClassForFile(file_, availableSheetClasses_);
    LOG.debug("handlerClass->{}", handlerClass);
    if (handlerClass == null)
        throw new IllegalArgumentException(
                String.format("Couldn't find handler in availableSheetClasses_->%s for file_->%s",
                        Arrays.toString(availableSheetClasses_), file_));
    Constructor<DKSheet> constructor = ConstructorUtils.getAccessibleConstructor(handlerClass,
            IMPLEMENTOR_CONSTRUCTOR_PARAM_TYPES);
    LOG.debug("constructor->{}", constructor);
    if (constructor == null)
        throw new IllegalArgumentException(
                String.format("Couldn't find Constructor in handlerClass->%s for constructor parm types->%s",
                        handlerClass, Arrays.toString(IMPLEMENTOR_CONSTRUCTOR_PARAM_TYPES)));
    Object[] constructorArgs = { file_, requestedName_, Boolean.valueOf(isSorted_), Boolean.valueOf(hasHeader_),
            Boolean.valueOf(validateLazily_) };
    return constructor.newInstance(constructorArgs);
}

From source file:org.forgerock.openam.guice.GuiceModuleCreator.java

/**
 * Finds and returns the Constructor to use to create the Guice module.
 *
 * Note: There must be one and only one public no-arg constructor for the Guice module.
 *
 * @param clazz The Guice module class./* www.  j a v a 2s .  c  o  m*/
 * @param <T> The Guice module class type.
 * @return The public no-arg constructor.
 * @throws NoSuchMethodException If no public no-arg constructor exists in this class.
 */
private <T> Constructor<T> getConstructor(Class<T> clazz) throws NoSuchMethodException {

    Constructor constructor = ConstructorUtils.getAccessibleConstructor(clazz, new Class[] {});

    if (constructor != null) {
        return constructor;
    } else {
        throw new NoSuchMethodException(
                String.format("No public zero-arg constructor found on %s", clazz.getCanonicalName()));
    }
}

From source file:org.mili.core.logging.DefaultLogger.java

/**
 * Static method to create a new logger from class clazz.
 *
 * @param clazz the class.//from   w w  w.j a  v a 2  s . c  om
 * @return logger.
 */
public static Logger create(Class<?> clazz) {
    String adapterClassname = System.getProperty(PROP_ADAPTERCLASS, Log4jAdapter.class.getName());
    Class<?> cls;
    try {
        cls = Class.forName(adapterClassname);
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException(e);
    }
    Constructor<Logger> constructor = ConstructorUtils.getAccessibleConstructor(cls, Class.class);
    try {
        return constructor.newInstance(clazz);
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}