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);
}
}
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;
}
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());
}
}
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;
}
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;
}
Aggregations