biz.hammurapi.web
Class DispatchingServlet

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended bybiz.hammurapi.web.StylingServlet
              extended bybiz.hammurapi.web.DispatchingServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
ActionServlet, SelfDispatchingServlet

public abstract class DispatchingServlet
extends StylingServlet

Dispatching servlet dispatches requests to action methods. Action method is any method which takes 3 parameters: HttpServletRequest, HttpServletResponse, DispatchingServlet or two parameters HttpServletRequest and HttpServletResponse. Return value of action method is processed in the following way: a) If it is instance of Forward then forward is performed b) If it is instance of String then it is gets written to response output stream. c) Otherwise it is XML-ized and then styled.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class biz.hammurapi.web.StylingServlet
StylingServlet.TransformCommand
 
Field Summary
 
Fields inherited from class biz.hammurapi.web.StylingServlet
parameterizer
 
Constructor Summary
DispatchingServlet()
           
 
Method Summary
protected  void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Handles the HTTP GET method.
protected  void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Handles the HTTP POST method.
 java.lang.String executeAction(java.lang.String pathInfo, biz.hammurapi.config.Context ctx)
           
protected abstract  java.lang.Object getActionInstance(java.lang.String path)
          Extracts instance name from the path and returns instance for the path.
protected abstract  java.lang.String getActionName(java.lang.String path)
           
protected  biz.hammurapi.xml.dom.CompositeDomSerializer getDomSerializer()
          Override this method to return custom serializer if needed.
 void init(javax.servlet.ServletConfig config)
           
protected  void processRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 void style(java.lang.Object ret, java.lang.String styleName, biz.hammurapi.config.Context context, javax.xml.transform.Result result)
          Converts object returned from action to XML and applies style
 void style(java.lang.Object ret, java.lang.String styleName, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Converts object returned from action to XML and applies style
protected abstract  int styleSeparatorPosition()
           
protected  void verifyMethod(java.lang.reflect.Method method)
          Subclasses can override this method and throw an exception of methods which are not supposed to be dispatched to.
 
Methods inherited from class biz.hammurapi.web.StylingServlet
getSetParametersCallback, getTransformer, newDocumentBuilder
 
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, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DispatchingServlet

public DispatchingServlet()
Method Detail

getDomSerializer

protected biz.hammurapi.xml.dom.CompositeDomSerializer getDomSerializer()
Override this method to return custom serializer if needed.

Overrides:
getDomSerializer in class StylingServlet
Returns:
DomSerializer

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class StylingServlet
Throws:
javax.servlet.ServletException

getActionInstance

protected abstract java.lang.Object getActionInstance(java.lang.String path)
                                               throws HammurapiWebException
Extracts instance name from the path and returns instance for the path.

Returns:
Object to invoke action methods
Throws:
HammurapiWebException

getActionName

protected abstract java.lang.String getActionName(java.lang.String path)
                                           throws HammurapiWebException
Parameters:
path -
Returns:
Action method name
Throws:
HammurapiWebException

styleSeparatorPosition

protected abstract int styleSeparatorPosition()
Returns:
Position of "/" in the servlet path info which separates action name from style info.

verifyMethod

protected void verifyMethod(java.lang.reflect.Method method)
                     throws HammurapiWebException
Subclasses can override this method and throw an exception of methods which are not supposed to be dispatched to.

Parameters:
method -
Throws:
HammurapiWebException

doGet

protected void doGet(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
              throws javax.servlet.ServletException,
                     java.io.IOException
Handles the HTTP GET method.

Overrides:
doGet in class StylingServlet
Parameters:
request - servlet request
response - servlet response
Throws:
javax.servlet.ServletException
java.io.IOException

doPost

protected void doPost(javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response)
               throws javax.servlet.ServletException,
                      java.io.IOException
Handles the HTTP POST method.

Overrides:
doPost in class StylingServlet
Parameters:
request - servlet request
response - servlet response
Throws:
javax.servlet.ServletException
java.io.IOException

processRequest

protected void processRequest(javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
                       throws javax.servlet.ServletException,
                              java.io.IOException
Overrides:
processRequest in class StylingServlet
Throws:
javax.servlet.ServletException
java.io.IOException

executeAction

public java.lang.String executeAction(java.lang.String pathInfo,
                                      biz.hammurapi.config.Context ctx)
                               throws javax.servlet.ServletException,
                                      java.io.IOException
Throws:
javax.servlet.ServletException
java.io.IOException

style

public void style(java.lang.Object ret,
                  java.lang.String styleName,
                  javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws javax.xml.parsers.ParserConfigurationException,
                  javax.xml.parsers.FactoryConfigurationError,
                  javax.servlet.ServletException
Converts object returned from action to XML and applies style

Parameters:
ret - Object to be styled
styleName - Style name
request - request
response - response
Throws:
javax.xml.parsers.ParserConfigurationException
javax.xml.parsers.FactoryConfigurationError
javax.servlet.ServletException

style

public void style(java.lang.Object ret,
                  java.lang.String styleName,
                  biz.hammurapi.config.Context context,
                  javax.xml.transform.Result result)
           throws javax.xml.parsers.ParserConfigurationException,
                  HammurapiWebException
Converts object returned from action to XML and applies style

Parameters:
ret - Object to be styled
styleName - Style name
Throws:
javax.xml.parsers.ParserConfigurationException
javax.xml.parsers.FactoryConfigurationError
javax.servlet.ServletException
HammurapiWebException


Copyright © 2006 Hammurapi Group. All Rights Reserved.