Search in sources :

Example 1 with DeploymentFactory

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");
    }
}
Also used : DeploymentFactory(javax.enterprise.deploy.spi.factories.DeploymentFactory) Manifest(java.util.jar.Manifest) JarFile(java.util.jar.JarFile) URL(java.net.URL) IOException(java.io.IOException) PrivilegedAction(java.security.PrivilegedAction) LogRecord(java.util.logging.LogRecord) URLClassLoader(java.net.URLClassLoader)

Aggregations

IOException (java.io.IOException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 PrivilegedAction (java.security.PrivilegedAction)1 JarFile (java.util.jar.JarFile)1 Manifest (java.util.jar.Manifest)1 LogRecord (java.util.logging.LogRecord)1 DeploymentFactory (javax.enterprise.deploy.spi.factories.DeploymentFactory)1