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) throws NoSuchMethodException,
        IllegalAccessException, InvocationTargetException, InstantiationException 

Source Link

Document

Returns new instance of klazz created using the actual arguments args.

Usage

From source file:org.apache.impala.authorization.SentryAuthProvider.java

static ResourceAuthorizationProvider createProvider(AuthorizationConfig config, AuthorizationPolicy policy) {
    try {//  w  w  w .ja  va  2 s  . c om
        ProviderBackend providerBe;
        // Create the appropriate backend provider.
        if (config.isFileBasedPolicy()) {
            providerBe = new SimpleFileProviderBackend(config.getSentryConfig().getConfig(),
                    config.getPolicyFile());
            ProviderBackendContext context = new ProviderBackendContext();
            providerBe.initialize(context);
        } else {
            // Note: The second parameter to the ProviderBackend is a "resourceFile" path
            // which is not used by Impala. We cannot pass 'null' so instead pass an empty
            // string.
            providerBe = new SimpleCacheProviderBackend(config.getSentryConfig().getConfig(), "");
            Preconditions.checkNotNull(policy);
            ProviderBackendContext context = new ProviderBackendContext();
            context.setBindingHandle(policy);
            providerBe.initialize(context);
        }

        CommonPolicyEngine engine = new CommonPolicyEngine(providerBe);

        // Try to create an instance of the specified policy provider class.
        // Re-throw any exceptions that are encountered.
        String policyFile = config.getPolicyFile() == null ? "" : config.getPolicyFile();

        return (ResourceAuthorizationProvider) ConstructorUtils.invokeConstructor(
                Class.forName(config.getPolicyProviderClassName()),
                new Object[] { policyFile, engine, ImpalaPrivilegeModel.INSTANCE });
    } catch (Exception e) {
        // Re-throw as unchecked exception.
        throw new IllegalStateException("Error creating ResourceAuthorizationProvider: ", e);
    }
}

From source file:org.carewebframework.cal.api.patientlist.AbstractPatientList.java

/**
 * Returns a copy of this list.//from   w w w  . j a va2  s .c  om
 *
 * @see IPatientList#copy()
 */
@Override
public IPatientList copy() {
    try {
        return (IPatientList) ConstructorUtils.invokeConstructor(getClass(), this);
    } catch (Exception e) {
        log.error("Error attempting to copy list.", e);
        return null;
    }
}

From source file:org.chililog.server.engine.parsers.EntryParserFactory.java

/**
 * Instances the correct entry parser/*from  w ww.j  a  va  2 s .  c om*/
 * 
 * @param repoInfo
 *            Repository meta data
 * @param repoParserInfo
 *            Parser meta data
 * @return Entry parser
 * @throws ChiliLogException
 */
public static EntryParser getParser(RepositoryConfigBO repoInfo, RepositoryParserConfigBO repoParserInfo)
        throws ChiliLogException {
    if (repoParserInfo == null) {
        throw new NullArgumentException("repoParserInfo");
    }

    try {
        String className = repoParserInfo.getClassName();
        if (className.equals(_delimitedEntryParserClassName)) {
            return new DelimitedEntryParser(repoInfo, repoParserInfo);
        } else if (className.equals(_regexEntryParserClassName)) {
            return new RegexEntryParser(repoInfo, repoParserInfo);
        } else if (className.equals(_jsonEntryParserClassName)) {
            return new JsonEntryParser(repoInfo, repoParserInfo);
        }

        // Use reflection to instance it
        Class<?> cls = ClassUtils.getClass(className);
        return (EntryParser) ConstructorUtils.invokeConstructor(cls, new Object[] { repoInfo, repoParserInfo });
    } catch (Exception ex) {
        throw new ChiliLogException(ex, Strings.PARSER_FACTORY_ERROR, repoParserInfo.getName(),
                repoInfo.getName(), ex.getMessage());
    }
}

From source file:org.chililog.server.workbench.ApiRequestHandler.java

/**
 * <p>//from w  w w.j a v a  2  s.  c o m
 * Instance our API worker class using the name passed in on the URI.
 * </p>
 * <p>
 * If <code>/api/Authentication</code> is passed in, the class
 * <code>com.chililog.server.intefaces.management.workers.AuthenticationWorker</code> will be instanced.
 * </p>
 */
private ApiResult instanceApiWorker() throws Exception {
    // TODO - Invoke in another thread because we are mostly reading and writing to mongodb
    String className = null;
    try {
        String uri = _request.getUri();
        String[] segments = uri.split("/");
        String apiName = segments[2];

        // Get rid of query string
        int qs = apiName.indexOf("?");
        if (qs > 0) {
            apiName = apiName.substring(0, qs);
        }

        // Merge _ to camel case
        apiName = WordUtils.capitalizeFully(apiName, new char[] { '_' });
        apiName = apiName.replace("_", "");

        className = "org.chililog.server.workbench.workers." + apiName + "Worker";
        _logger.debug("Instancing ApiWorker: %s", className);

        Class<?> apiClass = ClassUtils.getClass(className);
        _apiWorker = (Worker) ConstructorUtils.invokeConstructor(apiClass, _request);

        return _apiWorker.validate();
    } catch (ClassNotFoundException ex) {
        return new ApiResult(HttpResponseStatus.NOT_FOUND,
                new ChiliLogException(ex, Strings.API_NOT_FOUND_ERROR, className, _request.getUri()));
    }
}

From source file:org.openengsb.persistence.connector.jpabackend.ConnectorPropertyJPAEntity.java

public Object toObject() throws PersistenceException {
    try {// w  w w.j a  va2s.c  om
        Class<?> clazz = this.getClass().getClassLoader().loadClass(this.className);
        return ConstructorUtils.invokeConstructor(clazz, this.strValue);
    } catch (ClassNotFoundException e) {
        throw new PersistenceException(e);
    } catch (NoSuchMethodException e) {
        throw new PersistenceException(e);
    } catch (IllegalAccessException e) {
        throw new PersistenceException(e);
    } catch (InvocationTargetException e) {
        throw new PersistenceException(e);
    } catch (InstantiationException e) {
        throw new PersistenceException(e);
    }
}

From source file:org.sonar.server.es.EsTester.java

/**
 * Get all the indexed documents (no paginated results). Results are converted to BaseDoc objects.
 * Results are not sorted./*from   ww w.  j a  v a  2 s .com*/
 */
public <E extends BaseDoc> List<E> getDocuments(IndexType indexType, final Class<E> docClass) {
    List<SearchHit> hits = getDocuments(indexType);
    return newArrayList(Collections2.transform(hits, new Function<SearchHit, E>() {
        @Override
        public E apply(SearchHit input) {
            try {
                return (E) ConstructorUtils.invokeConstructor(docClass, input.getSource());
            } catch (Exception e) {
                throw Throwables.propagate(e);
            }
        }
    }));
}