org.kohsuke.stapler.framework
Class AbstractWebAppMain<T>

java.lang.Object
  extended by org.kohsuke.stapler.framework.AbstractWebAppMain<T>
Type Parameters:
T - The type of the root object instance
All Implemented Interfaces:
java.util.EventListener, javax.servlet.ServletContextListener

public abstract class AbstractWebAppMain<T>
extends java.lang.Object
implements javax.servlet.ServletContextListener

Entry point for web applications.

Applications that use stapler can use this as the base class, and then register that as the servlet context listener.

Author:
Kohsuke Kawaguchi

Field Summary
protected  javax.servlet.ServletContext context
           
protected  java.io.File home
          Once the home directory is determined, this value is set to that directory.
protected  java.lang.Class<T> rootType
           
 
Constructor Summary
protected AbstractWebAppMain(java.lang.Class<T> rootType)
           
 
Method Summary
protected  boolean checkEnvironment()
          Performs pre start-up environment check.
protected  void cleanUp(T app)
          Called during the destructino of the web app to perform any clean up act on the application object.
 void contextDestroyed(javax.servlet.ServletContextEvent event)
           
 void contextInitialized(javax.servlet.ServletContextEvent event)
           
protected abstract  java.lang.Object createApplication()
          Creates the root application object.
protected  java.lang.Object createPlaceHolderForAsyncLoad()
          If the root application object is loaded asynchronously, override this method to return the place holder object to serve the request in the mean time.
protected abstract  java.lang.String getApplicationName()
          Returns the application name, like "Hudson" or "Torricelli".
protected  java.io.File getDefaultHomeDir()
          If no home directory is configured, this method is called to determine the default location, which is "~/.appname".
protected  java.io.File getHomeDir()
          Determines the home directory for the application.
protected  void setApplicationObject()
          Sets the root application object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rootType

protected final java.lang.Class<T> rootType

context

protected javax.servlet.ServletContext context

home

protected java.io.File home
Once the home directory is determined, this value is set to that directory.

Constructor Detail

AbstractWebAppMain

protected AbstractWebAppMain(java.lang.Class<T> rootType)
Method Detail

getApplicationName

protected abstract java.lang.String getApplicationName()
Returns the application name, like "Hudson" or "Torricelli". The method should always return the same value. The name should only contain alpha-numeric character.


createPlaceHolderForAsyncLoad

protected java.lang.Object createPlaceHolderForAsyncLoad()
If the root application object is loaded asynchronously, override this method to return the place holder object to serve the request in the mean time.

Returns:
null to synchronously load the application object.

createApplication

protected abstract java.lang.Object createApplication()
                                               throws java.lang.Exception
Creates the root application object.

Throws:
java.lang.Exception

contextInitialized

public void contextInitialized(javax.servlet.ServletContextEvent event)
Specified by:
contextInitialized in interface javax.servlet.ServletContextListener

setApplicationObject

protected void setApplicationObject()
Sets the root application object.


checkEnvironment

protected boolean checkEnvironment()
Performs pre start-up environment check.

Returns:
false if a check fails. Webapp will fail to boot in this case.

getHomeDir

protected java.io.File getHomeDir()
Determines the home directory for the application. People makes configuration mistakes, so we are trying to be nice with those by doing String.trim().


getDefaultHomeDir

protected java.io.File getDefaultHomeDir()
If no home directory is configured, this method is called to determine the default location, which is "~/.appname". Override this method to change that behavior.


contextDestroyed

public void contextDestroyed(javax.servlet.ServletContextEvent event)
Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener

cleanUp

protected void cleanUp(T app)
Called during the destructino of the web app to perform any clean up act on the application object.



Copyright © 2011. All Rights Reserved.