shared
Class HelperBaseCh4

java.lang.Object
  extended by shared.HelperBaseCh4
Direct Known Subclasses:
ControllerHelper, HelperBaseCh5

public abstract class HelperBaseCh4
extends java.lang.Object

HelperBase class that is used in Chapter 4. It is also the super class for all the other helper base classes.


Nested Class Summary
protected static class HelperBaseCh4.SessionData
          Enumeration to describe if the data should be read from the session.
 
Field Summary
protected  org.apache.log4j.Logger logger
          Member variable for the logger object
protected  javax.servlet.http.HttpServletRequest request
          Member variable for the request object
protected  javax.servlet.http.HttpServletResponse response
          Member variable for the response object
 
Constructor Summary
HelperBaseCh4(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Initialise the request, response and logger.
 
Method Summary
 void addHelperToSession(java.lang.String name, boolean checkSession)
          Overridden method that accepts a boolean value.
 void addHelperToSession(java.lang.String name, HelperBaseCh4.SessionData state)
          Test if the old helper data should be retrieved.
protected abstract  void copyFromSession(java.lang.Object helper)
          Abstract method that must be defined in the controller helper.
protected  void doGet()
          Default doGet method that prints a warning message, if called.
protected  void doPost()
          Default doPost method that prints a warning message, if called.
protected  java.lang.String executeButtonMethod()
          Find the method associated with a button name.
protected  java.lang.String executeButtonMethod(java.lang.Class clazz, boolean searchForDefault)
          Overridden method that accepts the parent class of the class heirarchy for the current object.
 void fillBeanFromRequest(java.lang.Object data)
          Copy the request data to the bean.
protected  java.lang.String invokeButtonMethod(java.lang.reflect.Method buttonMethod)
          Execute the found method.
static void writeError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String title, java.lang.Exception ex)
          Write an error page, instead of calling a JSP.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

request

protected javax.servlet.http.HttpServletRequest request
Member variable for the request object


response

protected javax.servlet.http.HttpServletResponse response
Member variable for the response object


logger

protected org.apache.log4j.Logger logger
Member variable for the logger object

Constructor Detail

HelperBaseCh4

public HelperBaseCh4(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
Initialise the request, response and logger.

Parameters:
request - Request information encapsulated in a Java object
response - Response information encapsulated in a Java object
Method Detail

doGet

protected void doGet()
              throws javax.servlet.ServletException,
                     java.io.IOException
Default doGet method that prints a warning message, if called.

Throws:
javax.servlet.ServletException
java.io.IOException

doPost

protected void doPost()
               throws javax.servlet.ServletException,
                      java.io.IOException
Default doPost method that prints a warning message, if called.

Throws:
javax.servlet.ServletException
java.io.IOException

copyFromSession

protected abstract void copyFromSession(java.lang.Object helper)
Abstract method that must be defined in the controller helper. The base class calls this method when it needs to know how to copy the old helper data that is in the session into the current helper.

Parameters:
helper - The old helper from the session

addHelperToSession

public void addHelperToSession(java.lang.String name,
                               HelperBaseCh4.SessionData state)
Test if the old helper data should be retrieved. If so, then try to get the old helper from the session; if there is data, then call the abstract copyFromSession method. Always adds the current helper to the session, releasing the previous helper from the session.

Parameters:
name - The name to use to store the helper in the session
state - Whether to read the old data or to ignore it

addHelperToSession

public void addHelperToSession(java.lang.String name,
                               boolean checkSession)
Overridden method that accepts a boolean value.

Parameters:
name - The name to use to store the helper in the session
checkSession - Whether to read the old data or to ignore it. True means read, false means ignore

executeButtonMethod

protected java.lang.String executeButtonMethod()
                                        throws javax.servlet.ServletException,
                                               java.io.IOException
Find the method associated with a button name.

Returns:
Throws:
javax.servlet.ServletException
java.io.IOException

executeButtonMethod

protected java.lang.String executeButtonMethod(java.lang.Class clazz,
                                               boolean searchForDefault)
                                        throws java.lang.IllegalAccessException,
                                               java.lang.reflect.InvocationTargetException
Overridden method that accepts the parent class of the class heirarchy for the current object.

Parameters:
clazz - The most extended class for this object.
searchForDefault - If the default method has not been found, continue to search for it.
Returns:
The address of the next JSP.
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

invokeButtonMethod

protected java.lang.String invokeButtonMethod(java.lang.reflect.Method buttonMethod)
                                       throws java.lang.IllegalAccessException,
                                              java.lang.reflect.InvocationTargetException
Execute the found method. Log all errors.

Parameters:
buttonMethod - The method to execute
Returns:
Address of the next JSP.
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

fillBeanFromRequest

public void fillBeanFromRequest(java.lang.Object data)
Copy the request data to the bean. Catch errors and log them.

Parameters:
data - The bean to fill.

writeError

public static void writeError(javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response,
                              java.lang.String title,
                              java.lang.Exception ex)
                       throws java.io.IOException,
                              javax.servlet.ServletException
Write an error page, instead of calling a JSP.

Parameters:
request - Request information encapsulated in a Java object
response - Response information encapsulated in a Java object
title - The title of the generated page
ex - The exception that caused the error
Throws:
java.io.IOException
javax.servlet.ServletException