org.apache.beehive.netui.pageflow
Class AutoRegisterActionServlet

Object
  extended by GenericServlet
      extended by HttpServlet
          extended by ActionServlet
              extended by AutoRegisterActionServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig
Direct Known Subclasses:
PageFlowActionServlet

public class AutoRegisterActionServlet
extends ActionServlet

ActionServlet that dynamically registers requested modules based on registered module configuration file locators. The user may specify AutoRegisterActionServlet.ModuleConfigLocator classes in web.xml, using the "moduleConfigLocators" init-parameter; this allows the user to define patterns for auto-registered Struts modules.

See Also:
Serialized Form

Nested Class Summary
static interface AutoRegisterActionServlet.ModuleConfigLocator
          Interface for specifying alternate locations for auto-registered Struts modules.
 
Field Summary
static String MODULE_CONFIG_LOCATOR_CLASS_ATTR
           
 
Fields inherited from class ActionServlet
config, configDigester, convertNull, dataSources, debug, internal, internalName, log, processor, registrations, servletMapping, servletName
 
Constructor Summary
AutoRegisterActionServlet()
           
 
Method Summary
 void clearRegisteredModules()
          Clear the internal map of registered modules.
 void destroy()
           
protected  void destroyDataSources()
           
 ModuleConfig ensureModuleRegistered(String modulePath, ServletRequest request)
          Ensures that the Struts module for the given path is registered (dynamically, if necessary).
protected  AutoRegisterActionServlet.ModuleConfigLocator[] getDefaultModuleConfigLocators()
          Get the base list of ModuleConfigLocators, to specify locations for auto-registered Struts modules.
 String getInitParameter(String s)
           
 Enumeration getInitParameterNames()
           
protected  ModuleConfig getModuleConfig(String modulePath, ServletRequest request, ServletResponse response)
          Get the Struts ModuleConfig for the given module path.
 AutoRegisterActionServlet.ModuleConfigLocator[] getModuleConfigLocators()
          Get the current list of registered ModuleConfigLocators.
 String getModuleConfPath(String modulePath)
          Get the webapp-relative path to the Struts module configration file for a given module path, based on registered ModuleConfigLocators.
 void init(ServletConfig config)
           
protected  Digester initConfigDigester()
           
protected  ModuleConfig initModuleConfig(String prefix, String paths)
          This method is almost exactly the same as the base class initModuleConfig.
protected  void initModuleDataSources(ModuleConfig config)
           
protected  void process(HttpServletRequest request, HttpServletResponse response)
          This override of the base class process() registers a Struts module on the fly if the config file can be found in our standard place (named in our standard way), regardless of whether the module is configured in web.xml.
protected  ModuleConfig registerModule(String modulePath, String configFilePath)
          Register a Struts module, initialized by the given configuration file.
 
Methods inherited from class ActionServlet
addServletMapping, destroyApplications, destroyConfigDigester, destroyInternal, destroyModules, doGet, doPost, findDataSource, findFormBean, findForward, findMapping, getApplicationConfig, getDebug, getInternal, getModuleConfig, getRequestProcessor, getResources, init, initApplicationConfig, initApplicationDataSources, initApplicationMessageResources, initApplicationPlugIns, initDataSources, initInternal, initModuleMessageResources, initModulePlugIns, initOther, initServlet, log
 
Methods inherited from class HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class GenericServlet
getServletConfig, getServletContext, getServletInfo, getServletName, log, log
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODULE_CONFIG_LOCATOR_CLASS_ATTR

public static String MODULE_CONFIG_LOCATOR_CLASS_ATTR
Constructor Detail

AutoRegisterActionServlet

public AutoRegisterActionServlet()
Method Detail

init

public void init(ServletConfig config)
          throws ServletException
Specified by:
init in interface Servlet
Overrides:
init in class GenericServlet
Throws:
ServletException

getDefaultModuleConfigLocators

protected AutoRegisterActionServlet.ModuleConfigLocator[] getDefaultModuleConfigLocators()
Get the base list of ModuleConfigLocators, to specify locations for auto-registered Struts modules. By default, this list is empty; derived classes may override to provide locators, or the user may specify them using the "moduleConfigLocators" init-parameter. When an unrecognized Struts module is requested, each registered ModuleConfigLocator is queried for a possible path to the configuration file for the module. If the configuration file is found, the module is auto-registered against the file.


getModuleConfigLocators

public AutoRegisterActionServlet.ModuleConfigLocator[] getModuleConfigLocators()
Get the current list of registered ModuleConfigLocators.

Returns:
an array of registered ModuleConfigLocators.
See Also:
getDefaultModuleConfigLocators()

getModuleConfPath

public String getModuleConfPath(String modulePath)
Get the webapp-relative path to the Struts module configration file for a given module path, based on registered ModuleConfigLocators.

Parameters:
modulePath - the Struts module path.
Returns:
a String that is the path to the Struts configuration file, relative to the web application root, or null if no appropriate configuration file is found.
See Also:
getDefaultModuleConfigLocators()

getInitParameter

public String getInitParameter(String s)
Specified by:
getInitParameter in interface ServletConfig
Overrides:
getInitParameter in class GenericServlet

getInitParameterNames

public Enumeration getInitParameterNames()
Specified by:
getInitParameterNames in interface ServletConfig
Overrides:
getInitParameterNames in class GenericServlet

initModuleDataSources

protected void initModuleDataSources(ModuleConfig config)
                              throws ServletException
Overrides:
initModuleDataSources in class ActionServlet
Throws:
ServletException

destroyDataSources

protected void destroyDataSources()
Overrides:
destroyDataSources in class ActionServlet

initModuleConfig

protected ModuleConfig initModuleConfig(String prefix,
                                        String paths)
                                 throws ServletException
This method is almost exactly the same as the base class initModuleConfig. The only difference is that it does not throw an UnavailableException if a module configuration file is missing or invalid.

Overrides:
initModuleConfig in class ActionServlet
Throws:
ServletException

registerModule

protected ModuleConfig registerModule(String modulePath,
                                      String configFilePath)
                               throws ServletException
Register a Struts module, initialized by the given configuration file.

Parameters:
modulePath - the module path, starting at the webapp root, e.g., "/info/help".
configFilePath - the path, starting at the webapp root, to the module configuration file (e.g., "/WEB-INF/my-generated-struts-config-info-help.xml").
Returns:
the Struts ModuleConfig that was initialized.
Throws:
ServletException

process

protected void process(HttpServletRequest request,
                       HttpServletResponse response)
                throws IOException,
                       ServletException
This override of the base class process() registers a Struts module on the fly if the config file can be found in our standard place (named in our standard way), regardless of whether the module is configured in web.xml.

Overrides:
process in class ActionServlet
Throws:
IOException
ServletException

initConfigDigester

protected Digester initConfigDigester()
                               throws ServletException
Overrides:
initConfigDigester in class ActionServlet
Throws:
ServletException

destroy

public void destroy()
Specified by:
destroy in interface Servlet
Overrides:
destroy in class ActionServlet

getModuleConfig

protected ModuleConfig getModuleConfig(String modulePath,
                                       ServletRequest request,
                                       ServletResponse response)
                                throws IOException,
                                       ServletException
Get the Struts ModuleConfig for the given module path.

Parameters:
modulePath - the module path, from the request URI.
request - the current ServletRequest
response - the current HttpServletResponse
Returns:
the Struts ModuleConfig that corresponds with modulePath
Throws:
IOException
ServletException

ensureModuleRegistered

public ModuleConfig ensureModuleRegistered(String modulePath,
                                           ServletRequest request)
                                    throws IOException,
                                           ServletException
Ensures that the Struts module for the given path is registered (dynamically, if necessary).

Parameters:
modulePath - the module path, from the request URI.
request - the current ServletRequest
Throws:
IOException
ServletException

clearRegisteredModules

public void clearRegisteredModules()
Clear the internal map of registered modules.