net.wotonomy.web
Class WOApplication

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by net.wotonomy.web.WOApplication
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class WOApplication
extends javax.servlet.http.HttpServlet

A pure java implementation of WOApplication.

The application is responsible for creating and managing sessions and dispatching requests to the appropriate handlers.

This implementation extends HttpServlet, so the application itself is a servlet and can be configured and managed as such by the servlet container.

Version:
$Revision: 905 $
Author:
michael@mpowers.net, $Author: cgruber $
See Also:
Serialized Form

Field Summary
static java.lang.String WOApplicationDidFinishLaunchingNotification
           
static java.lang.String WOApplicationWillFinishLaunchingNotification
           
static java.lang.String WOGarbageCollectionPeriodKey
           
 
Constructor Summary
WOApplication()
           
 
Method Summary
 boolean adaptorsDispatchRequestsConcurrently()
          Returns whether this application allows request to be handled concurrently.
 boolean allowsConcurrentRequestHandling()
          Returns whether this application allows request to be handled concurrently.
 void appendToResponse(WOResponse aResponse, WOContext aContext)
          Invoked to start the third phase of the request-response cycle, after invokeAction() has completed and returned a WOResponse.
static WOApplication application()
          Returns the singleton instance of this application.
static boolean autoOpenInBrowser()
          Returns whether this application should attempt to open a web browser on the host machine when launched standalone.
 void awake()
          Invoked first in the request-response cycle.
 java.lang.String baseURL()
          Returns the path to the application on the local file system relative to the server's document root.
static java.lang.String componentRequestHandlerKey()
          Returns the component request handler key, which is defined by the system property _ComponentRequestHandlerKey.
 WOResourceManager createResourceManager()
          Called to create the application's resource manager.
 WOSession createSessionForRequest(WORequest aRequest)
          Called to create a session for a new request.
 WORequestHandler defaultRequestHandler()
          Returns the default request handler used if the requested handler isn't specified or cannot be found.
static java.lang.String directActionRequestHandlerKey()
          Returns the direct action request handler key, which is defined by the system property _DirectActionRequestHandlerKey.
 WOResponse dispatchRequest(WORequest aRequest)
          Dispatches the request to the appropriate handler.
protected  void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Dispatches the request and updates the specified response as appropriate.
protected  void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Handles post requests by calling doGet(), since the framework handles both gets and posts similarly.
 WOElement dynamicElementWithName(java.lang.String anElementName, net.wotonomy.foundation.NSDictionary anAssociationMap, WOElement aBodyElement, java.util.List aLanguageList)
          Returns either a dynamic element or a component for the specified name.
 WOResponse handleException(java.lang.Throwable aThrowable, WOContext aContext)
           
 WOResponse handlePageRestorationErrorInContext(WOContext aContext)
           
 WORequestHandler handlerForRequest(WORequest aRequest)
          Returns the request handler that would best service the specified request.
 WOResponse handleSessionCreationErrorInContext(WOContext aContext)
           
 WOResponse handleSessionRestorationErrorInContext(WOContext aContext)
           
 WOActionResults invokeAction(WORequest aRequest, WOContext aContext)
          Invoked to start the second phase of the request-response cycle, after all calls to takeValuesFromRequest have finished.
static boolean isCachingEnabled()
          Returns whether templates are cached.
 boolean isConcurrentRequestHandlingEnabled()
          Returns whether this application allows request to be handled concurrently.
static boolean isDebuggingEnabled()
          Returns whether the application is in "debug mode".
 boolean isPageRefreshOnBacktrackEnabled()
          Returns whether a "backtrack" for an existing page should simply call generateResponse() on the existing page instance.
static void main(java.lang.String[] argv)
          Main entry point for applications that do not subclass WOApplication.
static void main(java.lang.String[] argv, java.lang.Class subclass)
          Subclasses may call this method to start a self-hosted web server to serve themselves directly (for testing).
 java.lang.String name()
          Returns the name of the application.
 int pageCacheSize()
          Returns the number of pages that will be retained in the user's session.
 WOComponent pageWithName(java.lang.String aName, WOContext aContext)
          Called to retrieve a component for the specified context.
 WOComponent pageWithName(java.lang.String aName, WORequest aRequest)
          Returns the page component with the specified name.
 java.lang.String path()
          Returns the absolute path to the application on the local file system.
 int permanentPageCacheSize()
          Returns the number of pages that will be retained in the longer-term "permanent" page cache in the user's session, which is typically used for navigation bars in frames, etc.
static java.lang.Number port()
          Gets the port used when run as a standalone server.
 net.wotonomy.foundation.NSArray registeredRequestHandlerKeys()
          Returns the keys under which request handlers are registered.
 void registerRequestHandler(WORequestHandler aRequestHandler, java.lang.String aKey)
          Registers the specified request handler for the specified key.
 WORequestHandler removeRequestHandlerForKey(java.lang.String aKey)
          Unregisters any existing request handler for the specified key returning the existing request handler, if any.
 WORequestHandler requestHandlerForKey(java.lang.String aKey)
          Returns the request handler registered for the specified key, or null if no request handler is registered for that key.
 WOResourceManager resourceManager()
          Returns the application's current resource manager.
static java.lang.String resourceRequestHandlerKey()
          Returns the resource request handler key, which is defined by the system property _ResourceRequestHandlerKey.
 WOSession restoreSessionWithID(java.lang.String aSessionID, WOContext aContext)
          Called at the beginning of the request-response cycle to obtain the current session from the user's last request.
 void saveSessionForContext(WOContext aContext)
          Called at the end of the request-response cycle to persist the current session until the user's next request.
 WOSessionStore sessionStore()
          Returns the session store used by this application to persist sessions between request-response transactions.
static void setAutoOpenInBrowser(boolean autoOpen)
          Sets whether this application should attempt to open a web browser on the host machine when launched standalone.
static void setCachingEnabled(boolean enabled)
          Sets whether templates are cached.
static void setComponentRequestHandlerKey(java.lang.String aKey)
          Deprecated. Set the system property _ComponentRequestHandlerKey.
static void setDebuggingEnabled(boolean enabled)
          Sets whether the application is in "debug mode".
 void setDefaultRequestHandler(WORequestHandler aRequestHandler)
          Sets the default request handler used if the requested handler isn't specified or cannot be found.
static void setDirectActionRequestHandlerKey(java.lang.String aKey)
          Deprecated. Set the system property _DirectActionRequestHandlerKey.
 void setPageCacheSize(int aPositiveInt)
          Sets the number of pages that will be retained in the user's session.
 void setPageRefreshOnBacktrackEnabled(boolean enabled)
          Returns whether a "backtrack" for an existing page should simply call generateResponse() on the existing page instance.
 void setPermanentPageCacheSize(int aPositiveInt)
          Returns the number of pages that will be retained in the longer-term "permanent" page cache in the user's session, which is typically used for navigation bars in frames, etc.
 void setResourceManager(WOResourceManager aResourceManager)
          Deprecated. Override createResourceManager() instead.
static void setResourceRequestHandlerKey(java.lang.String aKey)
          Deprecated. Set the system property _ResourceRequestHandlerKey.
 void setSessionStore(WOSessionStore aSessionStore)
          Sets the session store used by this application to persist sessions between request-response transactions.
static void setSMTPHost(java.lang.String aHost)
          Deprecated. Set the system property WOSMTPHost.
 void sleep()
          Invoked last in the request-response cycle.
static java.lang.String SMTPHost()
          Gets the smtp server that will be used to send email.
 void takeValuesFromRequest(WORequest aRequest, WOContext aContext)
          Invoked to start the first phase of the request-response cycle, after all calls to awake() have been completed.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WOApplicationWillFinishLaunchingNotification

public static final java.lang.String WOApplicationWillFinishLaunchingNotification
See Also:
Constant Field Values

WOApplicationDidFinishLaunchingNotification

public static final java.lang.String WOApplicationDidFinishLaunchingNotification
See Also:
Constant Field Values

WOGarbageCollectionPeriodKey

public static final java.lang.String WOGarbageCollectionPeriodKey
See Also:
Constant Field Values
Constructor Detail

WOApplication

public WOApplication()
Method Detail

doGet

protected void doGet(javax.servlet.http.HttpServletRequest req,
                     javax.servlet.http.HttpServletResponse resp)
              throws javax.servlet.ServletException,
                     java.io.IOException
Dispatches the request and updates the specified response as appropriate. This implementation creates a new WORequest and WOContext from the request, sends the response to the appropriate WORequestHandler, and then updates the servlet response from the resulting WOResponse.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
java.io.IOException

doPost

protected void doPost(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse resp)
               throws javax.servlet.ServletException,
                      java.io.IOException
Handles post requests by calling doGet(), since the framework handles both gets and posts similarly. Override to handle post requests in a different manner.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
java.io.IOException

application

public static WOApplication application()
Returns the singleton instance of this application.


name

public java.lang.String name()
Returns the name of the application. This implementation returns the name the jar file or directory from which the class was loaded, with no extensions.


path

public java.lang.String path()
Returns the absolute path to the application on the local file system. Note that the application might be embedded inside of a jar file.


baseURL

public java.lang.String baseURL()
Returns the path to the application on the local file system relative to the server's document root.


allowsConcurrentRequestHandling

public boolean allowsConcurrentRequestHandling()
Returns whether this application allows request to be handled concurrently. This implementation returns true. Subclasses may override to return false to force single-threaded request handling, although this is not implemented.


adaptorsDispatchRequestsConcurrently

public boolean adaptorsDispatchRequestsConcurrently()
Returns whether this application allows request to be handled concurrently. This implementation returns true.


isConcurrentRequestHandlingEnabled

public boolean isConcurrentRequestHandlingEnabled()
Returns whether this application allows request to be handled concurrently. This implementation returns true.


awake

public void awake()
Invoked first in the request-response cycle. Override to perform any kind of initialization at the start of a request. This implementation does nothing.


takeValuesFromRequest

public void takeValuesFromRequest(WORequest aRequest,
                                  WOContext aContext)
Invoked to start the first phase of the request-response cycle, after all calls to awake() have been completed.


invokeAction

public WOActionResults invokeAction(WORequest aRequest,
                                    WOContext aContext)
Invoked to start the second phase of the request-response cycle, after all calls to takeValuesFromRequest have finished.


appendToResponse

public void appendToResponse(WOResponse aResponse,
                             WOContext aContext)
Invoked to start the third phase of the request-response cycle, after invokeAction() has completed and returned a WOResponse.


sleep

public void sleep()
Invoked last in the request-response cycle. Override to perform any kind of clean-up at the end of a request. This implementation does nothing.


dispatchRequest

public WOResponse dispatchRequest(WORequest aRequest)
Dispatches the request to the appropriate handler.


defaultRequestHandler

public WORequestHandler defaultRequestHandler()
Returns the default request handler used if the requested handler isn't specified or cannot be found. (This defaults to the WODirectActionRequestHandler.)


setDefaultRequestHandler

public void setDefaultRequestHandler(WORequestHandler aRequestHandler)
Sets the default request handler used if the requested handler isn't specified or cannot be found.


registerRequestHandler

public void registerRequestHandler(WORequestHandler aRequestHandler,
                                   java.lang.String aKey)
Registers the specified request handler for the specified key.


removeRequestHandlerForKey

public WORequestHandler removeRequestHandlerForKey(java.lang.String aKey)
Unregisters any existing request handler for the specified key returning the existing request handler, if any.


registeredRequestHandlerKeys

public net.wotonomy.foundation.NSArray registeredRequestHandlerKeys()
Returns the keys under which request handlers are registered.


requestHandlerForKey

public WORequestHandler requestHandlerForKey(java.lang.String aKey)
Returns the request handler registered for the specified key, or null if no request handler is registered for that key.


handlerForRequest

public WORequestHandler handlerForRequest(WORequest aRequest)
Returns the request handler that would best service the specified request.


handleSessionCreationErrorInContext

public WOResponse handleSessionCreationErrorInContext(WOContext aContext)

handleSessionRestorationErrorInContext

public WOResponse handleSessionRestorationErrorInContext(WOContext aContext)

handlePageRestorationErrorInContext

public WOResponse handlePageRestorationErrorInContext(WOContext aContext)

handleException

public WOResponse handleException(java.lang.Throwable aThrowable,
                                  WOContext aContext)

setPageCacheSize

public void setPageCacheSize(int aPositiveInt)
Sets the number of pages that will be retained in the user's session. Set to zero to disable page caching.


pageCacheSize

public int pageCacheSize()
Returns the number of pages that will be retained in the user's session. The default page cache size is 30.


permanentPageCacheSize

public int permanentPageCacheSize()
Returns the number of pages that will be retained in the longer-term "permanent" page cache in the user's session, which is typically used for navigation bars in frames, etc. The default permanent page cache size is 30.


setPermanentPageCacheSize

public void setPermanentPageCacheSize(int aPositiveInt)
Returns the number of pages that will be retained in the longer-term "permanent" page cache in the user's session, which is typically used for navigation bars in frames, etc. Set to zero to disable permanent page caching.


setPageRefreshOnBacktrackEnabled

public void setPageRefreshOnBacktrackEnabled(boolean enabled)
Returns whether a "backtrack" for an existing page should simply call generateResponse() on the existing page instance. If false, a new page is created instead. The default is true.


isPageRefreshOnBacktrackEnabled

public boolean isPageRefreshOnBacktrackEnabled()
Returns whether a "backtrack" for an existing page should simply call generateResponse() on the existing page instance. If false, a new page is created instead. The default is true.


setSessionStore

public void setSessionStore(WOSessionStore aSessionStore)
Sets the session store used by this application to persist sessions between request-response transactions.


sessionStore

public WOSessionStore sessionStore()
Returns the session store used by this application to persist sessions between request-response transactions.


saveSessionForContext

public void saveSessionForContext(WOContext aContext)
Called at the end of the request-response cycle to persist the current session until the user's next request.


restoreSessionWithID

public WOSession restoreSessionWithID(java.lang.String aSessionID,
                                      WOContext aContext)
Called at the beginning of the request-response cycle to obtain the current session from the user's last request. Returns null if no such session has been created. This method sets the context of the session to the specified context.


createSessionForRequest

public WOSession createSessionForRequest(WORequest aRequest)
Called to create a session for a new request. This implementation looks for a class in the same package as the application class called "Session" and failing that returns a WOSession.


pageWithName

public WOComponent pageWithName(java.lang.String aName,
                                WORequest aRequest)
Returns the page component with the specified name. A context is created with the specified request, along with a session if necessary.


pageWithName

public WOComponent pageWithName(java.lang.String aName,
                                WOContext aContext)
Called to retrieve a component for the specified context.


dynamicElementWithName

public WOElement dynamicElementWithName(java.lang.String anElementName,
                                        net.wotonomy.foundation.NSDictionary anAssociationMap,
                                        WOElement aBodyElement,
                                        java.util.List aLanguageList)
Returns either a dynamic element or a component for the specified name.


createResourceManager

public WOResourceManager createResourceManager()
Called to create the application's resource manager. Override to create a custom resource manager.


resourceManager

public WOResourceManager resourceManager()
Returns the application's current resource manager.


setResourceManager

public void setResourceManager(WOResourceManager aResourceManager)
Deprecated. Override createResourceManager() instead.

Installs a custom resource manager into the current application.


isDebuggingEnabled

public static boolean isDebuggingEnabled()
Returns whether the application is in "debug mode".


setDebuggingEnabled

public static void setDebuggingEnabled(boolean enabled)
Sets whether the application is in "debug mode".


setCachingEnabled

public static void setCachingEnabled(boolean enabled)
Sets whether templates are cached. If true, templates will only be read once per application lifetime. Otherwise, templates will be read each time this class is instantiated. Defaults to false.


isCachingEnabled

public static boolean isCachingEnabled()
Returns whether templates are cached. If true, templates are read once per application lifetime. Otherwise, templates are read each time this class is instantiated.


componentRequestHandlerKey

public static java.lang.String componentRequestHandlerKey()
Returns the component request handler key, which is defined by the system property _ComponentRequestHandlerKey. The default is "wo".


setComponentRequestHandlerKey

public static void setComponentRequestHandlerKey(java.lang.String aKey)
Deprecated. Set the system property _ComponentRequestHandlerKey.

Sets the component request handler key.


directActionRequestHandlerKey

public static java.lang.String directActionRequestHandlerKey()
Returns the direct action request handler key, which is defined by the system property _DirectActionRequestHandlerKey. The default is "wa".


setDirectActionRequestHandlerKey

public static void setDirectActionRequestHandlerKey(java.lang.String aKey)
Deprecated. Set the system property _DirectActionRequestHandlerKey.

Sets the direct action request handler key.


resourceRequestHandlerKey

public static java.lang.String resourceRequestHandlerKey()
Returns the resource request handler key, which is defined by the system property _ResourceRequestHandlerKey. The default is "wr".


setResourceRequestHandlerKey

public static void setResourceRequestHandlerKey(java.lang.String aKey)
Deprecated. Set the system property _ResourceRequestHandlerKey.

Sets the resource request handler key.


autoOpenInBrowser

public static boolean autoOpenInBrowser()
Returns whether this application should attempt to open a web browser on the host machine when launched standalone. The default is true.


setAutoOpenInBrowser

public static void setAutoOpenInBrowser(boolean autoOpen)
Sets whether this application should attempt to open a web browser on the host machine when launched standalone.


port

public static java.lang.Number port()
Gets the port used when run as a standalone server. Returns the value of the system property WOPort. By default, this is zero, which causes the application to automatically select an available port.


SMTPHost

public static java.lang.String SMTPHost()
Gets the smtp server that will be used to send email. Returns the system property WOSMTPHost.


setSMTPHost

public static void setSMTPHost(java.lang.String aHost)
Deprecated. Set the system property WOSMTPHost.

Sets the smtp server that will be used to send email.


main

public static void main(java.lang.String[] argv)
Main entry point for applications that do not subclass WOApplication.


main

public static void main(java.lang.String[] argv,
                        java.lang.Class subclass)
Subclasses may call this method to start a self-hosted web server to serve themselves directly (for testing).



Copyright © 2006 null. All Rights Reserved.