Package org.kohsuke.stapler.framework
Class AbstractWebAppMain<T>
- java.lang.Object
-
- org.kohsuke.stapler.framework.AbstractWebAppMain<T>
-
- Type Parameters:
T
- The type of the root object instance
- All Implemented Interfaces:
EventListener
,javax.servlet.ServletContextListener
public abstract class AbstractWebAppMain<T> extends 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
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractWebAppMain(Class<T> rootType)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
checkEnvironment()
Performs pre start-up environment check.protected void
cleanUp(T app)
Called during the destruction 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 Object
createApplication()
Creates the root application object.protected 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.Object
getApplication()
Returns the root application object created increateApplication()
protected abstract String
getApplicationName()
Returns the application name, like "Hudson" or "Torricelli".protected File
getDefaultHomeDir()
If no home directory is configured, this method is called to determine the default location, which is "~/.appname".protected File
getHomeDir()
Determines the home directory for the application.Future<Object>
getInitializer()
Returns aFuture
ofgetApplication()
.protected void
setApplicationObject()
Sets the root application object.
-
-
-
Method Detail
-
getApplicationName
protected abstract 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 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 Object createApplication() throws Exception
Creates the root application object.- Throws:
Exception
-
contextInitialized
public void contextInitialized(javax.servlet.ServletContextEvent event)
- Specified by:
contextInitialized
in interfacejavax.servlet.ServletContextListener
-
setApplicationObject
protected void setApplicationObject()
Sets the root application object.
-
getInitializer
public Future<Object> getInitializer()
Returns aFuture
ofgetApplication()
. Useful to synchronize on the completion of initialization, successful or otherwise.
-
getApplication
public Object getApplication()
Returns the root application object created increateApplication()
-
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 File getHomeDir()
Determines the home directory for the application. People makes configuration mistakes, so we are trying to be nice with those by doingString.trim()
.
-
getDefaultHomeDir
protected 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 interfacejavax.servlet.ServletContextListener
-
cleanUp
protected void cleanUp(T app)
Called during the destruction of the web app to perform any clean up act on the application object.
-
-