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

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

Introduction

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

Prototype

public static Object invokeConstructor(Class cls, Object[] args, Class[] parameterTypes)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
        InstantiationException 

Source Link

Document

Returns new instance of klazz created using constructor with signature parameterTypes and actual arguments args.

The signatures should be assignment compatible.

Usage

From source file:br.com.ingenieux.jenkins.plugins.awsebdeployment.AWSClientFactory.java

@SuppressWarnings("unchecked")
public <T> T getService(Class<T> serviceClazz) throws NoSuchMethodException, IllegalAccessException,
        InvocationTargetException, InstantiationException {

    Class<?> paramTypes[] = new Class<?>[] { AWSCredentialsProvider.class, ClientConfiguration.class };

    ClientConfiguration newClientConfiguration = new ClientConfiguration(this.clientConfiguration);

    if (AmazonS3.class.isAssignableFrom(serviceClazz)) {
        newClientConfiguration = newClientConfiguration.withSignerOverride("AWSS3V4SignerType");
    } else {//  w  w w  . jav  a  2 s .co m
        newClientConfiguration = newClientConfiguration.withSignerOverride(null);
    }

    Object params[] = new Object[] { creds, newClientConfiguration };

    T resultObj = (T) ConstructorUtils.invokeConstructor(serviceClazz, params, paramTypes);

    if (DEFAULT_REGION.equals(defaultString(region, DEFAULT_REGION))) {
        return resultObj;
    } else {
        for (ServiceEndpointFormatter formatter : ServiceEndpointFormatter.values()) {
            if (formatter.matches(resultObj)) {
                ((AmazonWebServiceClient) resultObj).setEndpoint(getEndpointFor(formatter));
                break;
            }
        }
    }

    return resultObj;
}

From source file:pt.ua.tm.neji.core.batch.BatchExecutor.java

protected static <A, B> Processor newProcessor(final Class<? extends Processor> processorCls,
        final Context context, final A input, final List<B> outputList, final Object... args)
        throws NejiException {
    Validate.notNull(processorCls);// w  w  w  .j  ava  2s .c om
    Validate.notNull(context);
    Validate.notNull(input);
    Validate.notNull(outputList);

    int numberArgs = 3 + (args != null ? args.length : 0);
    List<Object> values = new ArrayList<>(numberArgs);
    values.add(context);
    values.add(input);
    values.add(outputList);

    List<Class> types = new ArrayList<>(numberArgs);
    types.add(context.getClass());
    types.add(input.getClass());
    types.add(outputList.getClass());

    if (args != null) {
        for (Object arg : args) {
            values.add(arg);
            types.add(arg.getClass());
        }
    }

    try {
        return (Processor) ConstructorUtils.invokeConstructor(processorCls, values.toArray(),
                types.toArray(new Class[types.size()]));
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException
            | InstantiationException ex) {
        logger.error("Error creating new pipeline processor.", ex);
        throw new NejiException("Error creating new pipeline processor.", ex);
    }
}

From source file:pt.ua.tm.neji.core.batch.BatchExecutor.java

protected static <A, B> Processor newProcessor(final Class<? extends Processor> processorCls,
        final Context context, final A input, final List<B> outputList, boolean addAnnotationsWithoutIDs,
        final Object... args) throws NejiException {
    Validate.notNull(processorCls);/*from w  w  w  .  j ava  2s.  c  o  m*/
    Validate.notNull(context);
    Validate.notNull(input);
    Validate.notNull(outputList);

    int numberArgs = 3 + (args != null ? args.length : 0);
    List<Object> values = new ArrayList<>(numberArgs);
    values.add(context);
    values.add(input);
    values.add(outputList);
    values.add(addAnnotationsWithoutIDs);

    List<Class> types = new ArrayList<>(numberArgs);
    types.add(context.getClass());
    types.add(input.getClass());
    types.add(outputList.getClass());
    types.add(boolean.class);

    if (args != null) {
        for (Object arg : args) {
            values.add(arg);
            types.add(arg.getClass());
        }
    }

    try {
        return (Processor) ConstructorUtils.invokeConstructor(processorCls, values.toArray(),
                types.toArray(new Class[types.size()]));
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException
            | InstantiationException ex) {
        logger.error("Error creating new pipeline processor.", ex);
        throw new NejiException("Error creating new pipeline processor.", ex);
    }
}

From source file:pt.ua.tm.neji.train.batch.TrainBatchExecutor.java

protected static <A, B, C> Processor newProcessor(final Class<? extends Processor> processorCls,
        final Context context, final A sentencesInput, final B annotationsInput, final Object... args)
        throws NejiException {

    Validate.notNull(processorCls);/*from   w w w .  ja v  a2s  .  co m*/
    Validate.notNull(context);
    Validate.notNull(sentencesInput);
    Validate.notNull(annotationsInput);

    int numberArgs = 3 + (args != null ? args.length : 0);
    List<Object> values = new ArrayList<>(numberArgs);
    values.add(context);
    values.add(sentencesInput);
    values.add(annotationsInput);

    List<Class> types = new ArrayList<>(numberArgs);
    types.add(context.getClass());
    types.add(sentencesInput.getClass());
    types.add(annotationsInput.getClass());

    if (args != null) {
        for (Object arg : args) {
            values.add(arg);
            types.add(arg.getClass());
        }
    }

    try {
        return (Processor) ConstructorUtils.invokeConstructor(processorCls, values.toArray(),
                types.toArray(new Class[types.size()]));
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException
            | InstantiationException ex) {
        logger.error("Error creating new pipeline processor.", ex);
        throw new NejiException("Error creating new pipeline processor.", ex);
    }
}

From source file:pt.ua.tm.neji.train.batch.TrainBatchExecutor.java

protected static <A, C> Processor newProcessor(final Class<? extends Processor> processorCls,
        final Context context, final A sentencesInput, final Object... args) throws NejiException {

    Validate.notNull(processorCls);/*from w  w w  .  ja va  2  s . co  m*/
    Validate.notNull(context);
    Validate.notNull(sentencesInput);

    int numberArgs = 2 + (args != null ? args.length : 0);
    List<Object> values = new ArrayList<>(numberArgs);
    values.add(context);
    values.add(sentencesInput);

    List<Class> types = new ArrayList<>(numberArgs);
    types.add(context.getClass());
    types.add(sentencesInput.getClass());

    if (args != null) {
        for (Object arg : args) {
            values.add(arg);
            types.add(arg.getClass());
        }
    }

    try {
        return (Processor) ConstructorUtils.invokeConstructor(processorCls, values.toArray(),
                types.toArray(new Class[types.size()]));
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException
            | InstantiationException ex) {
        logger.error("Error creating new pipeline processor.", ex);
        throw new NejiException("Error creating new pipeline processor.", ex);
    }
}