FileDocCategorySizeDatePackage
AddonController.javaAPI DocGlassfish v2 API11907Thu Jul 26 14:44:34 BST 2007com.sun.enterprise.addons

AddonController

public abstract class AddonController extends Object
Abstract Controller class. This gives all the common functionality for AddonInstallationController and AddonConfigurationController. It is also the basic factory that provide concrete Controller classes.

NOT THREAD SAFE: mutable instance variable: logger, installRoot, servicesAreLoaded

see
AddonInstallationController
see
AddonConfigurationController
since
9.1
author
binod@dev.java.net

Fields Summary
private final HashMap
apiBasedServices
private final HashMap
mainClassBasedServices
private final HashMap
simpleJars
private volatile File
installRoot
private boolean
servicesAreLoaded
private static String
adminUser
private static String
adminPassword
private final String
DEFAULT_ADMIN_USER
private final String
DEFAULT_ADMIN_PASSWORD
private File
domainRoot
private volatile Logger
logger
protected static final com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
Methods Summary
protected java.lang.ClassLoadercreateClassLoader(java.net.URL jar)
Create a classloader that load the service.

        URL[] classpath = null;
        try {
            classpath = AddonClassPath.getClassPath(jar, 
            getInstallRoot().getCanonicalPath(), getLogger());
        } catch (Exception e) {
            throw new AddonFatalException(e);
        }
        return new URLClassLoader(classpath, this.getClass().getClassLoader());
    
protected java.lang.StringfindApiBasedService(java.util.jar.JarFile jF)
Find the api based service from the jar file.

        try {
            ZipEntry zE = jF.getEntry(getServiceInterface());
            if (zE != null) {
                InputStream in = jF.getInputStream(zE);
                BufferedReader br = new BufferedReader(
                                    new InputStreamReader(in));
                return br.readLine();
            }
        } catch (Exception e) {
            getLogger().log(Level.FINE, e.getMessage(), e);
            throw new AddonFatalException(e);
        }
        return null;
    
protected java.lang.StringfindMainClassBasedService(java.util.jar.JarFile jF)
Find the main class based service from the jarFile.

        try {
            Manifest mf = jF.getManifest();
            if(mf != null) {
                Attributes attrs = mf.getMainAttributes();
                if(attrs != null) {
                    String main = attrs.getValue(Attributes.Name.MAIN_CLASS);
                    if(main != null) {
                        return main;
                    }
                }
            }
        } catch (Exception e) {
            throw new AddonFatalException(e);
        }
        return null;
    
public static AddonConfigurationControllergetAddonConfigurationController()
Create a controller class for Addon Configuration.

        return new AddonConfigurationController();
    
public static AddonInstallationControllergetAddonInstallationController()
Create a controller class for Addon Installation.

        return new AddonInstallationController();
    
protected java.util.HashMapgetApiBasedServices()
Return the services that are based on the java api for addons.

        return apiBasedServices;
    
java.io.FilegetDomainRoot()

        return this.domainRoot;
    
protected abstract java.io.FilenameFiltergetFilenameFilter()
Each controller use specific naming scheme for the finding the plugins.

protected java.io.FilegetInstallRoot()
Return the installation root directory.

        return this.installRoot;
    
protected synchronized java.util.logging.LoggergetLogger()
Return the logger instance used for logging.

        if (logger == null) {
            return Logger.getAnonymousLogger();
        }
        return logger;
    
protected java.util.HashMapgetMainClassBasedServices()
Return the services that are based on the manifest main class.

        return mainClassBasedServices;
    
protected abstract java.lang.StringgetName(java.io.File jar)
Retrive the name of the addon from the file name.

protected abstract java.lang.StringgetServiceInterface()
Return the service interface name.

protected abstract java.io.FilegetServiceJarLocation()
Return the directory where the plugin jar files will be kept.

protected java.util.HashMapgetSimpleJars()
Return the services that are neither api based nor main class based. These are simple jar files.

        return simpleJars;
    
protected voidloadServices(java.io.File jarDir)


    /*
     * Examine the plugins and load the necessary services.
     * The loaded services and their names will be saved in HashMap
     * that can be used by others.
     */
          

        if (servicesAreLoaded) {
            return;
        } else {
            servicesAreLoaded = true;
        }

        try {
            File[] jars = jarDir.listFiles(getFilenameFilter());
            if (jars == null) return;
            for (File jar : jars) {
                 if (jar != null) {
                    if (jar.getName().startsWith("grizzly")) {
                        continue;
                    } else if (jar.getName().startsWith("freemarker")) {
                        continue;
                    } else if (jar.getName().startsWith("wadl2java")) {
                        continue;
                    }
                 }
                 JarFile jF = new JarFile(jar);
                 String serviceName = findApiBasedService(jF);
                 ClassLoader cl = createClassLoader(jar.toURI().toURL());
                 if (serviceName != null) {
                     apiBasedServices.put(cl.loadClass
                     (serviceName).newInstance(), getName(jar));
                 } else {
                     String mainClass = findMainClassBasedService(jF);
                     if (mainClass != null) {
                         mainClassBasedServices.put(cl.loadClass
                         (mainClass).newInstance(), getName(jar));
                     } else {
                         simpleJars.put(jar, getName(jar));
                     }
                 }
            }
        } catch (AddonFatalException afe) {
            throw afe;
        }catch (Exception e) {
            throw new AddonFatalException(e);
        }
    
private voidpopulateAdminCredentials()

         try {
           String domainXMLLocation = 
                (getDomainRoot().getCanonicalPath()) + File.separator + 
                "config" + File.separator + "domain.xml"; 
           File domainXML=new File(domainXMLLocation);
           ConfigContext configContext=ConfigFactory.createConfigContext(
                                domainXML.getAbsolutePath()); 
           HttpListener as=ServerHelper.getHttpListener(configContext, 
                                "server", ServerHelper.ADMIN_HTTP_LISTNER_ID);
           String host="localhost";
           int port=Integer.parseInt(as.getPort());
           final LoginInfoStore store = LoginInfoStoreFactory.getStore(null);
           if (store.exists(host, port)) {
               LoginInfo login = store.read(host, port);
               adminPassword = login.getPassword();
               adminUser = login.getUser();
               if (adminUser == null) {
                    adminUser = DEFAULT_ADMIN_USER;
                    adminPassword = DEFAULT_ADMIN_PASSWORD;
               }
           }
       } catch (Exception e) {
           adminUser = DEFAULT_ADMIN_USER;
           adminPassword = DEFAULT_ADMIN_PASSWORD;
           getLogger().log(Level.WARNING, e.getMessage(), e);
       } 
    
public voidsetAdminCredentials(com.sun.appserv.addons.ConfigurationContext cc)

        if ((adminPassword == null) || (adminPassword.length() < 1)) {
            populateAdminCredentials();
        }
        cc.setAdminUser(adminUser);
        cc.setAdminPassword(adminPassword);
    
voidsetDomainRoot(java.io.File domainRoot)

        this.domainRoot = domainRoot;
    
public voidsetInstallRoot(java.io.File installRoot)
Set the installation root directory.

        this.installRoot = installRoot;
    
public voidsetLogger(java.util.logging.Logger logger)
Set an appropriate logger.

        this.logger = logger;