use of javax.enterprise.deploy.spi.factories.DeploymentFactory in project Payara by payara.
the class DeploymentFactoryInstaller method installDeploymentFactory.
protected void installDeploymentFactory(final File installedDM) throws IOException {
if (deplLogger.isLoggable(Level.FINE)) {
deplLogger.fine("Installing Deployment factory = " + installedDM.getAbsolutePath());
}
// let's check first that we indeed have a valid
// deployment manager implementation
/*
*Declare the JarFile and Manifest but populate them inside the first try block. This way the
*jar file can be closed right away to conserve resources.
*/
Manifest m = null;
JarFile jarFile = new JarFile(installedDM);
try {
m = jarFile.getManifest();
} finally {
jarFile.close();
}
String className = m.getMainAttributes().getValue(J2EE_DEPLOYMENT_MANAGER);
final URL[] urls = new URL[] { installedDM.toURI().toURL() };
URLClassLoader urlClassLoader;
urlClassLoader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() {
public URLClassLoader run() {
return new java.net.URLClassLoader(urls, getClass().getClassLoader());
}
});
Class factory = null;
try {
factory = urlClassLoader.loadClass(className);
} catch (ClassNotFoundException cnfe) {
deplLogger.log(Level.SEVERE, NO_DEPLOYMENT_MANAGER, className);
throw new IllegalArgumentException(className + " is not present in the " + installedDM.getName());
}
// Ok we have the class, let's instanciate it, check it and
// if everything is fine, register it to the DeploymentFactoryManager
Object df = null;
try {
df = factory.newInstance();
} catch (Exception ie) {
LogRecord lr = new LogRecord(Level.SEVERE, NO_DEPLOYMENT_MANAGER);
Object[] args = { className };
lr.setParameters(args);
lr.setThrown(ie);
deplLogger.log(lr);
throw new IllegalArgumentException("Cannot install " + installedDM.getName());
}
if (df instanceof DeploymentFactory) {
DeploymentFactoryManager.getInstance().registerDeploymentFactory((DeploymentFactory) df);
} else {
throw new IllegalArgumentException("The " + className + " declared as a DeploymentFactory does implement the DeploymentFactory interface");
}
}
Aggregations