Example usage for java.lang Class getDeclaredConstructor

List of usage examples for java.lang Class getDeclaredConstructor

Introduction

In this page you can find the example usage for java.lang Class getDeclaredConstructor.

Prototype

@CallerSensitive
public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
        throws NoSuchMethodException, SecurityException 

Source Link

Document

Returns a Constructor object that reflects the specified constructor of the class or interface represented by this Class object.

Usage

From source file:ch.ksfx.web.pages.spidering.ManageResultVerifierConfiguration.java

public void onValidateFromResultVerifierConfigurationForm() {
    try {// w  w  w  . ja v  a  2s  .co m
        GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
        Class clazz = groovyClassLoader.parseClass(resultVerifierConfiguration.getGroovyCode());

        Constructor cons = clazz.getDeclaredConstructor(ObjectLocator.class);
    } catch (Exception e) {
        resultVerifierConfigurationForm.recordError(StacktraceUtil.getStackTrace(e));
    }
}

From source file:ch.ksfx.web.pages.spidering.ManageResourceLoaderPluginConfiguration.java

public void onValidateFromResourceLoaderPluginConfigurationForm() {
    try {//from w  w w  .j av  a  2  s  .c  om
        GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
        Class clazz = groovyClassLoader.parseClass(resourceLoaderPluginConfiguration.getGroovyCode());

        Constructor cons = clazz.getDeclaredConstructor(ObjectLocator.class);
    } catch (Exception e) {
        resourceLoaderPluginConfigurationForm.recordError(StacktraceUtil.getStackTrace(e));
    }
}

From source file:ch.ksfx.web.pages.spidering.ManageResultUnitModifierConfiguration.java

public void onValidateFromResultUnitModifierConfigurationForm() {
    try {/*from w w w.j  ava2  s.  com*/
        GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
        Class clazz = groovyClassLoader.parseClass(resultUnitModifierConfiguration.getGroovyCode());

        Constructor cons = clazz.getDeclaredConstructor(SystemLogger.class);
    } catch (Exception e) {
        resultUnitModifierConfigurationForm.recordError(StacktraceUtil.getStackTrace(e));
    }
}

From source file:com.adaptris.core.config.DefaultPreProcessorLoader.java

private ConfigPreProcessor createInstance(String classname, KeyValuePairSet config) throws CoreException {
    ConfigPreProcessor preProcessor = null;
    log.trace("Loading pre-processor: " + classname);
    Class<?>[] paramTypes = { KeyValuePairSet.class };
    Object[] args = { config };/*from   www.java  2s .  c o  m*/
    try {
        Class<?> clazz = Class.forName(classname);
        Constructor<?> cnst = clazz.getDeclaredConstructor(paramTypes);
        preProcessor = (ConfigPreProcessor) cnst.newInstance(args);
    } catch (Exception e) {
        throw ExceptionHelper.wrapCoreException(e);
    }
    return preProcessor;
}

From source file:com.link_intersystems.lang.reflect.SerializableConstructor.java

protected Constructor<?> getConstructor(Class<?> declaringClass, Class<?>[] parameterTypes)
        throws NoSuchMethodException {
    Constructor<?> constructor = declaringClass.getDeclaredConstructor(parameterTypes);
    return constructor;
}

From source file:com.adaptris.core.config.DefaultPreProcessorLoader.java

private ConfigPreProcessor createInstance(String classname, BootstrapProperties bootstrapProperties)
        throws CoreException {
    ConfigPreProcessor preProcessor = null;
    log.trace("Loading pre-processor: " + classname);
    Class<?>[] paramTypes = { BootstrapProperties.class };
    Object[] args = { bootstrapProperties };
    try {/*from w  w w  .  j  a v  a2s.  c o  m*/
        Class<?> clazz = Class.forName(classname);
        Constructor<?> cnst = clazz.getDeclaredConstructor(paramTypes);
        preProcessor = (ConfigPreProcessor) cnst.newInstance(args);
    } catch (Exception e) {
        throw ExceptionHelper.wrapCoreException(e);
    }

    return preProcessor;
}

From source file:org.jadira.scanner.classpath.types.JConstructor.java

public Constructor<?> getActualConstructor() throws ClasspathAccessException {

    Class<?>[] methodParams = getMethodParamClasses(getMethodInfo());

    try {//  w ww.jav a 2  s  .  c o m
        Class<?> clazz = ((JClass) getEnclosingType()).getActualClass();
        return clazz.getDeclaredConstructor(methodParams);
    } catch (SecurityException e) {
        throw new ClasspathAccessException("Could not access constructor: " + e, e);
    } catch (NoSuchMethodException e) {
        throw new ClasspathAccessException("Could not find constructor: " + e, e);
    }
}

From source file:ch.ksfx.web.pages.publishing.ManagePublishingResource.java

public void onValidateFromPublishingResourceForm() {
    if (publishingResource.getPublishingConfiguration().getLockedForEditing() == true) {
        publishingResourceForm.recordError("This publishing configuration is locked, please unlock it first!");
    }//  www .  j  a  v a2  s.com

    try {
        GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
        Class clazz = groovyClassLoader.parseClass(publishingResource.getPublishingStrategy());

        Constructor cons = clazz.getDeclaredConstructor(ObjectLocator.class);
    } catch (Exception e) {
        publishingResourceForm.recordError(StacktraceUtil.getStackTrace(e));
    }
}

From source file:com.curl.orb.context.ApplicationContextFactory.java

protected ApplicationContextFactory(ServletContext context) throws ApplicationContextException {
    try {/*w  w  w .j a  va  2  s .  c  om*/
        String applicationContextClassName = context.getInitParameter(APPLICATION_CONTEXT_CLASS);
        if (applicationContextClassName != null) {
            Class<?> applicationContextClass = Class.forName(applicationContextClassName);
            applicationContext = (AbstractApplicationContext) (applicationContextClass
                    .getDeclaredConstructor(ServletContext.class).newInstance(context));
        }
    } catch (ClassNotFoundException e) {
        throw new ApplicationContextException(e);
    } catch (NoSuchMethodException e) {
        throw new ApplicationContextException(e);
    } catch (IllegalAccessException e) {
        throw new ApplicationContextException(e);
    } catch (InvocationTargetException e) {
        throw new ApplicationContextException(e);
    } catch (InstantiationException e) {
        throw new ApplicationContextException(e);
    }
    if (applicationContext == null)
        applicationContext = new ServletApplicationContext(context);
}

From source file:com.glaf.core.util.ReflectUtils.java

public static Constructor<?> getConstructor(Class<?> type, Class<?>[] parameterTypes) {
    try {//from   w  w w. j  a v  a2s .c o  m
        Constructor<?> constructor = type.getDeclaredConstructor(parameterTypes);
        constructor.setAccessible(true);
        return constructor;
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    }
}