FileDocCategorySizeDatePackage
UserConfig.javaAPI DocGlassfish v2 API11451Fri May 04 22:32:30 BST 2007org.apache.catalina.startup

UserConfig

public final class UserConfig extends Object implements org.apache.catalina.LifecycleListener
Startup event listener for a Host that configures Contexts (web applications) for all defined "users" who have a web application in a directory with the specified name in their home directories. The context path of each deployed application will be set to ~xxxxx, where xxxxx is the username of the owning user for that web application
author
Craig R. McClanahan
version
$Revision: 1.3 $ $Date: 2007/05/05 05:32:29 $

Fields Summary
private String
configClass
The Java class name of the Context configuration class we should use.
private String
contextClass
The Java class name of the Context implementation we should use.
private int
debug
The debugging detail level for this component.
private String
directoryName
The directory name to be searched for within each user home directory.
private String
homeBase
The base directory containing user home directories.
private org.apache.catalina.Host
host
The Host we are associated with.
private static final org.apache.catalina.util.StringManager
sm
The string resources for this package.
private String
userClass
The Java class name of the user database class we should use.
Constructors Summary
Methods Summary
private voiddeploy()
Deploy a web application for any user who has a web application present in a directory with a specified name within their home directory.


        if (debug >= 1)
            log(sm.getString("userConfig.deploying"));

        // Load the user database object for this host
        UserDatabase database = null;
        try {
            Class clazz = Class.forName(userClass);
            database = (UserDatabase) clazz.newInstance();
            database.setUserConfig(this);
        } catch (Exception e) {
            log(sm.getString("userConfig.database"), e);
            return;
        }

        // Deploy the web application (if any) for each defined user
        Enumeration users = database.getUsers();
        while (users.hasMoreElements()) {
            String user = (String) users.nextElement();
            String home = database.getHome(user);
            deploy(user, home);
        }

    
private voiddeploy(java.lang.String user, java.lang.String home)
Deploy a web application for the specified user if they have such an application in the defined directory within their home directory.

param
user Username owning the application to be deployed
param
home Home directory of this user


        // Does this user have a web application to be deployed?
        String contextPath = "/~" + user;
        if (host.findChild(contextPath) != null)
            return;
        File app = new File(home, directoryName);
        if (!app.exists() || !app.isDirectory())
            return;
        /*
        File dd = new File(app, "/WEB-INF/web.xml");
        if (!dd.exists() || !dd.isFile() || !dd.canRead())
            return;
        */
        log(sm.getString("userConfig.deploy", user));

        // Deploy the web application for this user
        try {
            Class clazz = Class.forName(contextClass);
            Context context =
              (Context) clazz.newInstance();
            context.setPath(contextPath);
            context.setDocBase(app.toString());
            if (context instanceof Lifecycle) {
                clazz = Class.forName(configClass);
                LifecycleListener listener =
                  (LifecycleListener) clazz.newInstance();
                ((Lifecycle) context).addLifecycleListener(listener);
            }
            host.addChild(context);
        } catch (Exception e) {
            log(sm.getString("userConfig.error", user), e);
        }

    
public java.lang.StringgetConfigClass()
Return the Context configuration class name.



    // ------------------------------------------------------------- Properties


               
       

        return (this.configClass);

    
public java.lang.StringgetContextClass()
Return the Context implementation class name.


        return (this.contextClass);

    
public intgetDebug()
Return the debugging detail level for this component.


        return (this.debug);

    
public java.lang.StringgetDirectoryName()
Return the directory name for user web applications.


        return (this.directoryName);

    
public java.lang.StringgetHomeBase()
Return the base directory containing user home directories.


        return (this.homeBase);

    
public java.lang.StringgetUserClass()
Return the user database class name for this component.


        return (this.userClass);

    
public voidlifecycleEvent(org.apache.catalina.LifecycleEvent event)
Process the START event for an associated Host.

param
event The lifecycle event that has occurred


        // Identify the host we are associated with
        try {
            host = (Host) event.getLifecycle();
        } catch (ClassCastException e) {
            log(sm.getString("hostConfig.cce", event.getLifecycle()), e);
            return;
        }

        // Process the event that has occurred
        if (event.getType().equals(Lifecycle.START_EVENT))
            start();
        else if (event.getType().equals(Lifecycle.STOP_EVENT))
            stop();

    
private voidlog(java.lang.String message)
Log a message on the Logger associated with our Host (if any)

param
message Message to be logged


        Logger logger = null;
        if (host != null)
            logger = host.getLogger();
        if (logger != null)
            logger.log("UserConfig[" + host.getName() + "]: " + message);
        else
            System.out.println("UserConfig[" + host.getName() + "]: "
                               + message);

    
private voidlog(java.lang.String message, java.lang.Throwable throwable)
Log a message on the Logger associated with our Host (if any)

param
message Message to be logged
param
throwable Associated exception


        Logger logger = null;
        if (host != null)
            logger = host.getLogger();
        if (logger != null)
            logger.log("UserConfig[" + host.getName() + "] "
                       + message, throwable);
        else {
            System.out.println("UserConfig[" + host.getName() + "]: "
                               + message);
            System.out.println("" + throwable);
            throwable.printStackTrace(System.out);
        }

    
public voidsetConfigClass(java.lang.String configClass)
Set the Context configuration class name.

param
configClass The new Context configuration class name.


        this.configClass = configClass;

    
public voidsetContextClass(java.lang.String contextClass)
Set the Context implementation class name.

param
contextClass The new Context implementation class name.


        this.contextClass = contextClass;

    
public voidsetDebug(int debug)
Set the debugging detail level for this component.

param
debug The new debugging detail level


        this.debug = debug;

    
public voidsetDirectoryName(java.lang.String directoryName)
Set the directory name for user web applications.

param
directoryName The new directory name


        this.directoryName = directoryName;

    
public voidsetHomeBase(java.lang.String homeBase)
Set the base directory containing user home directories.

param
homeBase The new base directory


        this.homeBase = homeBase;

    
public voidsetUserClass(java.lang.String userClass)
Set the user database class name for this component.


        this.userClass = userClass;

    
private voidstart()
Process a "start" event for this Host.


        if (debug > 0)
            log(sm.getString("userConfig.start"));

        deploy();

    
private voidstop()
Process a "stop" event for this Host.


        if (debug > 0)
            log(sm.getString("userConfig.stop"));