FileDocCategorySizeDatePackage
AddonInstallationController.javaAPI DocGlassfish v2 API12356Fri May 04 22:30:24 BST 2007com.sun.enterprise.addons

AddonInstallationController

public class AddonInstallationController extends AddonController
A controller class that install a specific addon or all addons. It is invoked either from appserver installer or asadmin install-addon command.
see
com.sun.appserv.addons.Installer
since
9.1
authod
binod@dev.java.net

Fields Summary
private final String
SERVICEINTERFACE
private final String
METAINFSERVICE
private final String
ADDONS
Constructors Summary
Methods Summary
private void_install(java.lang.Object obj, java.lang.String addonName)
Call Installer.install() on a specific addon.

        Installer inst = Installer.class.cast(obj);
        InstallationContext ic = new InstallationContext();
        ic.setInstallationDirectory(getInstallRoot()); 
        try {
            inst.install(ic);
            String addonInstalled = 
            localStrings.getString("addon.installed", addonName);
            if (getLogger().isLoggable(Level.INFO)) {
                getLogger().info(addonInstalled);
            }
        } catch (AddonFatalException afe) {
            getLogger().log(Level.FINE, "Fatal Exception while " +
            "installing the addon " + addonName, afe);
            throw afe;
        } catch (AddonException ae) {
            String msg = localStrings.getString
            ("addon.installationcomplete.error", 
            addonName, ae.getLocalizedMessage());
            getLogger().warning(msg);
        } catch (Exception e) {
            getLogger().log(Level.FINE, "Fatal Exception while " +
            "installing the addon " + addonName, e);
            throw new AddonFatalException(e);
        }
    
private void_uninstall(java.lang.Object obj, java.lang.String addonName)
Call Installer.uninstall() for a specific addon.

        Installer inst = Installer.class.cast(obj);
        InstallationContext ic = new InstallationContext();
        ic.setInstallationDirectory(getInstallRoot()); 
        try {
            inst.uninstall(ic);
            if (getLogger().isLoggable(Level.INFO)) {
                getLogger().info
                (localStrings.getString("addon.uninstalled", addonName));
            }
        } catch (AddonFatalException afe) {
            getLogger().log(Level.FINE, "Fatal Exception while " +
            "uninstalling the addon " + addonName, afe);
            throw afe;
        } catch (AddonException ae) {
            String msg = localStrings.getString
            ("addon.uninstallationcomplete.error", 
            addonName, ae.getLocalizedMessage());
            getLogger().warning(msg);
        } catch (Exception e) {
            getLogger().log(Level.FINE, "Fatal Exception while " +
            "uninstalling the addon " + addonName, e);
            throw new AddonFatalException(e);
        }
    
protected java.io.FilenameFiltergetFilenameFilter()
Installers are simple jar files. Return an instance of a filenamefilter that returns all jar files.

        return new JarFileFilter();
    
protected java.lang.StringgetName(java.io.File f)
Installer jar files are supposed to end with _installer.jar. Split out that portion and return the addon name.

        //Match _installer.jar
        String regex = "(_installer)\\.([j|J][a|A][r|R])";
        String name = f.getName();

        //Allow any String before _installer.jar 
        if (name.matches(".*"+regex)) {
            return name.split(regex)[0];
        } else {
            throw new AddonFatalException
            (localStrings.getString("addon.notinstaller", name));
        }
    
protected java.lang.StringgetServiceInterface()
Return the service interface name. The value is META-INF/services/com.sun.appserv.addons.Installer

        return METAINFSERVICE + SERVICEINTERFACE;
    
protected java.io.FilegetServiceJarLocation()
Return the location where installer plugins will be kept. It is AS_HOME/addons directory.


                      
       
        return new File(getInstallRoot(),"addons");
    
public voidinstall(java.io.File installRoot)
Main API used by clients. This installs all the addons.

        setInstallRoot(installRoot);
        loadServices(getServiceJarLocation());

        Set<Map.Entry<Object,String>> apiBasedServices = 
        getApiBasedServices().entrySet();

        for (Map.Entry<Object,String> entry : apiBasedServices) {
            _install(entry.getKey(), entry.getValue());
        }

        Set<Map.Entry<Object,String>> mainClassBasedServices = 
        getMainClassBasedServices().entrySet();

        for (Map.Entry<Object, String> entry : apiBasedServices) {
            if (getLogger().isLoggable(Level.FINER)) {
                getLogger().finer("Installing " + entry.getValue());
            }

            Object obj = entry.getKey();
            String addonName = entry.getValue();
            try {
                Method m = obj.getClass().getMethod("main", 
                       new Class[] {String[].class});
                String[] args = new String[] 
                {getInstallRoot().getCanonicalPath()};
                m.invoke(obj, new Object[] {args});

                String addonInstalled = 
                localStrings.getString("addon.installed", addonName);
                if (getLogger().isLoggable(Level.INFO)) {
                    getLogger().info(addonInstalled);
                }
            } catch (Exception e) {
                getLogger().log(Level.FINE, "Fatal Exception while " + 
                "configuring the addon " + addonName, e);
                throw new AddonFatalException (e);
            }
        }
    
public voidinstall(java.io.File installRoot, java.io.File jarFile)
Install a specific plugin. This plugin will be copied to AS_HOME/addons directory, before invoking the install api.

        try {
            setInstallRoot(installRoot);
            String addonName = getName(jarFile);
            String service = findApiBasedService(new JarFile(jarFile));
            if (service != null) {
                String fileName = jarFile.getName();
                File addonDir = new File(installRoot, ADDONS);
                if (getLogger().isLoggable(Level.FINER)) {
                    getLogger().log
                    (Level.FINER, "Addon Directory is :" + addonDir);
                }
                if (addonDir.exists() == false) {
                    addonDir.mkdir();
                }
                if (addonDir.equals(jarFile.getParentFile()) == false) {
                    FileOutputStream destFile = 
                    new FileOutputStream(new File(addonDir, fileName));

                    FileChannel dstChannel = destFile.getChannel();
                    FileChannel srcChannel = 
                    new FileInputStream(jarFile).getChannel();
                    
                    dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                    srcChannel.close();
                    dstChannel.close();
                } 
                Object obj = 
                createClassLoader(jarFile.toURI().toURL()).
                loadClass(service).newInstance();
                _install(obj, addonName);
            } else {
                throw new AddonFatalException
                (localStrings.getString("addon.servicenotfound",
                addonName, getServiceInterface()));
            }
        } catch (Exception e) {
            throw new AddonFatalException(e);
        }
    
public voiduninstall(java.io.File installRoot)
Uninstall all addons. Typically invoked when appserver is uninstalled.

        setInstallRoot(installRoot);
        loadServices(getServiceJarLocation());

        Set<Map.Entry<Object,String>> apiBasedServices = 
        getApiBasedServices().entrySet();

        for (Map.Entry<Object,String> entry : apiBasedServices) {
            _uninstall(entry.getKey(), entry.getValue());
        }
    
public voiduninstall(java.io.File installRoot, java.lang.String addonName)
API to uninstall a specific addon. The installer will be obtained from the AS_HOME/addons folder and installer api will be invoked.

        try {
            setInstallRoot(installRoot);
            File addonDir = new File(installRoot, ADDONS);
            File[] files = 
            addonDir.listFiles(new InstallerFileFilter(addonName));
            if (files == null || files.length == 0 ) {
                throw new AddonFatalException
                (localStrings.getString("addon.installernotfound", addonName));
            }
            if (files.length > 1 ) {
                throw new AddonFatalException
                (localStrings.getString("addon.morethanoneinstaller", addonName));
            }
            String service = findApiBasedService(new JarFile(files[0]));
            if (service != null) {
                Object obj = 
                createClassLoader(files[0].toURI().toURL()).
                loadClass(service).newInstance();
                _uninstall(obj, addonName);
            } else {
                throw new AddonFatalException
                (localStrings.getString("addon.servicenotfound",
                addonName, getServiceInterface()));
            }
        } catch (Exception e) {
            throw new AddonFatalException(e);
        }