Search in sources :

Example 31 with Constructor

use of java.lang.reflect.Constructor in project OpenAM by OpenRock.

the class ApplicationManager method newApplication.

/**
     * Creates an application.
     *
     * @param name Name of application.
     * @param applicationType application type.
     * @throws EntitlementException if application class is not found.
     */
public static Application newApplication(String name, ApplicationType applicationType) throws EntitlementException {
    Class clazz = applicationType.getApplicationClass();
    Class[] parameterTypes = { String.class, ApplicationType.class };
    Constructor constructor;
    try {
        constructor = clazz.getConstructor(parameterTypes);
        Object[] parameters = { name, applicationType };
        return (Application) constructor.newInstance(parameters);
    } catch (NoSuchMethodException ex) {
        throw new EntitlementException(6, ex);
    } catch (SecurityException ex) {
        throw new EntitlementException(6, ex);
    } catch (InstantiationException ex) {
        throw new EntitlementException(6, ex);
    } catch (IllegalAccessException ex) {
        throw new EntitlementException(6, ex);
    } catch (IllegalArgumentException ex) {
        throw new EntitlementException(6, ex);
    } catch (InvocationTargetException ex) {
        throw new EntitlementException(6, ex);
    }
}
Also used : Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 32 with Constructor

use of java.lang.reflect.Constructor in project android_frameworks_base by ResurrectionRemix.

the class EffectFactory method instantiateEffect.

private Effect instantiateEffect(Class effectClass, String name) {
    // Make sure this is an Effect subclass
    try {
        effectClass.asSubclass(Effect.class);
    } catch (ClassCastException e) {
        throw new IllegalArgumentException("Attempting to allocate effect '" + effectClass + "' which is not a subclass of Effect!", e);
    }
    // Look for the correct constructor
    Constructor effectConstructor = null;
    try {
        effectConstructor = effectClass.getConstructor(EffectContext.class, String.class);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException("The effect class '" + effectClass + "' does not have " + "the required constructor.", e);
    }
    // Construct the effect
    Effect effect = null;
    try {
        effect = (Effect) effectConstructor.newInstance(mEffectContext, name);
    } catch (Throwable t) {
        throw new RuntimeException("There was an error constructing the effect '" + effectClass + "'!", t);
    }
    return effect;
}
Also used : Constructor(java.lang.reflect.Constructor)

Example 33 with Constructor

use of java.lang.reflect.Constructor in project OpenAM by OpenRock.

the class AuthContext method setCertDBPassword.

/**
     * Sets the password for the certificate database.
     * It is required to call only once to initialize certificate database if
     * the password is not set in the password file (specified as
     * the value for <code>com.iplanet.am.admin.cli.certdb.passfile</code>
     * in <code>AMConfig.properties</code>). If both are set, this method will
     * overwrite the value in certificate password file.
     *
     * @param password Password for the certificate database.
     *
     * @supported.api
     */
public static void setCertDBPassword(String password) {
    try {
        if (usingJSSEHandler) {
            Class pcbClass = (Class) Class.forName(JSSE_PASSWORD_CALLBACK);
            Object passwdCallback = (Object) pcbClass.newInstance();
            Method method = pcbClass.getMethod("setPassword", new Class[] { String.class });
            KeyStore keystore = (KeyStore) method.invoke(passwdCallback, new Object[] { password });
        } else {
            Class initializer = Class.forName(JSS_PASSWORD_UTIL);
            Constructor initializerConstructor = initializer.getConstructor(new Class[] { String.class });
            initializerConstructor.newInstance(new Object[] { password });
        }
    } catch (Exception e) {
        e.printStackTrace();
        authDebug.message("Error in setCertDBPassword : " + e.getMessage());
    }
}
Also used : Constructor(java.lang.reflect.Constructor) Method(java.lang.reflect.Method) KeyStore(java.security.KeyStore) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) AMSecurityPropertiesException(com.sun.identity.security.AMSecurityPropertiesException) IOException(java.io.IOException) AuthException(com.sun.identity.authentication.service.AuthException)

Example 34 with Constructor

use of java.lang.reflect.Constructor in project Synthese_2BIN by TheYoungSensei.

the class Controleur method chercherConstruteurs.

private List<Propriete> chercherConstruteurs(Class cls) {
    List<Propriete> constructeurs = new ArrayList<Propriete>();
    for (Constructor constructeur : cls.getDeclaredConstructors()) {
        Visibilite visibilite = chercherVisibilite(constructeur.getModifiers());
        boolean estStatique = false;
        if (Modifier.isStatic(constructeur.getModifiers()))
            estStatique = true;
        String nom = constructeur.getName();
        String ex = chercherExceptions(constructeur.getExceptionTypes());
        Parameter[] parameters = constructeur.getParameters();
        nom += " (";
        nom += chercherParametres(parameters);
        nom += ") " + ex;
        Propriete prop = new Propriete(nom, estStatique, Modifier.isAbstract(constructeur.getModifiers()), visibilite);
        constructeurs.add(prop);
    }
    return constructeurs;
}
Also used : Constructor(java.lang.reflect.Constructor) Visibilite(gimme.domaine.Visibilite) ArrayList(java.util.ArrayList) Parameter(java.lang.reflect.Parameter) Propriete(gimme.domaine.Propriete)

Example 35 with Constructor

use of java.lang.reflect.Constructor in project tdi-studio-se by Talend.

the class SWTResourceManager method getPluginImageURL.

/**
     * Retuns an URL based on a plugin and file path
     * 
     * @param plugin Object The plugin containing the file path
     * @param name String The file path
     * @return URL The URL representing the file at the specified path
     * @throws Exception
     */
private static URL getPluginImageURL(Object plugin, String name) throws Exception {
    // try to work with 'plugin' as with OSGI BundleContext
    try {
        //$NON-NLS-1$
        Class<?> bundleClass = Class.forName("org.osgi.framework.Bundle");
        //$NON-NLS-1$
        Class<?> bundleContextClass = Class.forName("org.osgi.framework.BundleContext");
        if (bundleContextClass.isAssignableFrom(plugin.getClass())) {
            //$NON-NLS-1$
            Method getBundleMethod = bundleContextClass.getMethod("getBundle", new Class[0]);
            Object bundle = getBundleMethod.invoke(plugin, new Object[0]);
            //
            //$NON-NLS-1$
            Class<?> ipathClass = Class.forName("org.eclipse.core.runtime.IPath");
            //$NON-NLS-1$
            Class<?> pathClass = Class.forName("org.eclipse.core.runtime.Path");
            Constructor<?> pathConstructor = pathClass.getConstructor(new Class[] { String.class });
            Object path = pathConstructor.newInstance(new Object[] { name });
            //
            //$NON-NLS-1$
            Class<?> platformClass = Class.forName("org.eclipse.core.runtime.Platform");
            //$NON-NLS-1$
            Method findMethod = platformClass.getMethod("find", new Class[] { bundleClass, ipathClass });
            return (URL) findMethod.invoke(null, new Object[] { bundle, path });
        }
    } catch (Throwable e) {
    // Ignore any exceptions
    }
    // else work with 'plugin' as with usual Eclipse plugin
    {
        //$NON-NLS-1$
        Class<?> pluginClass = Class.forName("org.eclipse.core.runtime.Plugin");
        if (pluginClass.isAssignableFrom(plugin.getClass())) {
            //
            //$NON-NLS-1$
            Class<?> ipathClass = Class.forName("org.eclipse.core.runtime.IPath");
            //$NON-NLS-1$
            Class<?> pathClass = Class.forName("org.eclipse.core.runtime.Path");
            Constructor<?> pathConstructor = pathClass.getConstructor(new Class[] { String.class });
            Object path = pathConstructor.newInstance(new Object[] { name });
            //
            //$NON-NLS-1$
            Method findMethod = pluginClass.getMethod("find", new Class[] { ipathClass });
            return (URL) findMethod.invoke(plugin, new Object[] { path });
        }
    }
    return null;
}
Also used : Constructor(java.lang.reflect.Constructor) Method(java.lang.reflect.Method) URL(java.net.URL)

Aggregations

Constructor (java.lang.reflect.Constructor)1311 InvocationTargetException (java.lang.reflect.InvocationTargetException)281 Method (java.lang.reflect.Method)252 IOException (java.io.IOException)128 Field (java.lang.reflect.Field)111 ArrayList (java.util.ArrayList)106 Test (org.junit.Test)92 DOMTestDocumentBuilderFactory (org.w3c.domts.DOMTestDocumentBuilderFactory)74 JUnitTestSuiteAdapter (org.w3c.domts.JUnitTestSuiteAdapter)73 List (java.util.List)61 JAXPDOMTestDocumentBuilderFactory (org.w3c.domts.JAXPDOMTestDocumentBuilderFactory)58 Map (java.util.Map)50 Type (java.lang.reflect.Type)39 Annotation (java.lang.annotation.Annotation)38 HashMap (java.util.HashMap)38 HashSet (java.util.HashSet)31 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)31 ParameterizedType (java.lang.reflect.ParameterizedType)30 File (java.io.File)20 URL (java.net.URL)20