se.lu.thep.waf
Class AbstractAction

java.lang.Object
  extended by se.lu.thep.waf.AbstractAction
All Implemented Interfaces:
java.lang.Cloneable

public abstract class AbstractAction
extends java.lang.Object
implements java.lang.Cloneable

Actions are steps in an event. Each action should set a valid template or Layout for the response or define a list of actionIds for the ActionServlet to process.

Author:
gregory

Field Summary
protected  java.lang.String actionId
           
protected  org.apache.log4j.Logger log
          Logger used in this action.
 
Constructor Summary
AbstractAction()
          Should be called by all subclasses as it creates the logger.
 
Method Summary
 java.lang.Object clone()
           
 Event getEvent()
          All actions should be part of an event.
 AbstractAction getForwardTo()
          Used by the ActionServlet to chain actions together.
 java.lang.String getId()
          Get the id of this action, the id should be set by the ActionFactory
 Layout getLayout()
          Get the layout create by this action.
 java.security.Principal getLoggedInUser()
          If a user has logged on then the principal of that user is returned
 javax.servlet.http.HttpServletRequest getRequest()
           
 javax.servlet.http.HttpServletResponse getResponse()
           
protected  java.lang.Boolean getSessionAttribute(VBoolean param)
          Returns a Boolean value defined by the VBoolean param from the HttpRequest session for the given parameter.
protected  java.lang.Integer getSessionAttribute(VInteger param)
           
protected  java.lang.String getSessionAttribute(VString param)
          Adapter method for getRequest().getSession().getAttribute(name)
protected  java.util.List<java.lang.Integer> getSessionAttributeList(VInteger param)
          Adapter method for getRequest().getSession().getAttribute(name) when retrieving a list of Integer values.
 java.lang.String getTemplate()
          Returns the template that should be displayed.
 void init()
          Called by the ActionServlet prior to action.run() and used to validate initial state of an action.
abstract  void run()
           
protected  void setAttribute(java.lang.String name, java.lang.Object value)
          Adapter method for getRequest().setAttribute(name, value)
 void setEvent(Event actionRequest)
          Associates this action with the given event.
protected  void setForwardTo(AbstractAction forwardTo)
          Set next action to run
 void setId(java.lang.String actionId)
          Set the id of this action.
<T extends Layout>
T
setLayout(T layout)
          Register the layout that should be displayed.
 void setLoggedInUser(java.security.Principal loggedInUser)
          Set the authenticated principal of this action
protected  void setSessionAttribute(java.lang.String name, java.lang.Object value)
          Adapter method for getRequest().getSession().setAttribute(name, value).
 void setTemplate(java.lang.String template)
          Register a template path which the ActionServlet can display when an event has no more actions in the queue.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected org.apache.log4j.Logger log
Logger used in this action. To initiate this logger each subclass constructor should call super() or not define any constructor.


actionId

protected java.lang.String actionId
Constructor Detail

AbstractAction

public AbstractAction()
Should be called by all subclasses as it creates the logger.

Method Detail

getLayout

public Layout getLayout()
Get the layout create by this action.

Returns:
the layout to display or null if no layout was set.

setLayout

public <T extends Layout> T setLayout(T layout)
Register the layout that should be displayed.

Type Parameters:
T - Any layout that extends Layout
Parameters:
layout - to be displayed
Returns:
the layout that was registered

init

public void init()
          throws ActionException
Called by the ActionServlet prior to action.run() and used to validate initial state of an action. If this method is overriden you should call super.init()

Throws:
ActionException

run

public abstract void run()
                  throws ActionException
Throws:
ActionException

getTemplate

public java.lang.String getTemplate()
Returns the template that should be displayed.

Returns:
the template that should be displayed or null if no template has been set

setTemplate

public void setTemplate(java.lang.String template)
Register a template path which the ActionServlet can display when an event has no more actions in the queue.

Parameters:
template -

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Returns:
the servlet request of associated with this action

setAttribute

protected void setAttribute(java.lang.String name,
                            java.lang.Object value)
Adapter method for getRequest().setAttribute(name, value)

Parameters:
name - of attribute
value - of attribute

setSessionAttribute

protected void setSessionAttribute(java.lang.String name,
                                   java.lang.Object value)
Adapter method for getRequest().getSession().setAttribute(name, value).

Parameters:
name -
value -

getSessionAttribute

protected java.lang.Boolean getSessionAttribute(VBoolean param)
Returns a Boolean value defined by the VBoolean param from the HttpRequest session for the given parameter.

Parameters:
param - to look for in the session
Returns:
a Boolean or null if the param doesn't exist.

getSessionAttribute

protected java.lang.String getSessionAttribute(VString param)
Adapter method for getRequest().getSession().getAttribute(name)

Parameters:
param - valid parameter
Returns:
Object from current session

getSessionAttribute

protected java.lang.Integer getSessionAttribute(VInteger param)

getSessionAttributeList

protected java.util.List<java.lang.Integer> getSessionAttributeList(VInteger param)
Adapter method for getRequest().getSession().getAttribute(name) when retrieving a list of Integer values. The name of the VInteger parameter argument is used as name for the session attribute, while the type of the argument indicates that the list will contain Integer values.

Parameters:
param - VInteger The valid parameter coupled to the session attribute.
Returns:
List The list of Integer values obtained from the session attribute or null if list is not found.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Returns:
the servlet response associtated with this action

getForwardTo

public AbstractAction getForwardTo()
Used by the ActionServlet to chain actions together.

Returns:
Next axtion to run

setForwardTo

protected void setForwardTo(AbstractAction forwardTo)
Set next action to run

Parameters:
forwardTo -

getLoggedInUser

public java.security.Principal getLoggedInUser()
If a user has logged on then the principal of that user is returned

Returns:
the user principal or null if this is an anonymous request.

setLoggedInUser

public void setLoggedInUser(java.security.Principal loggedInUser)
Set the authenticated principal of this action

Parameters:
loggedInUser -

getId

public java.lang.String getId()
Get the id of this action, the id should be set by the ActionFactory

Returns:
the id of this action

setId

public void setId(java.lang.String actionId)
Set the id of this action. The ActionFactory sets the id of each action. The id cannot be changed.

Parameters:
actionId -

getEvent

public Event getEvent()
All actions should be part of an event.

Returns:
the event this action is associated with

setEvent

public void setEvent(Event actionRequest)
Associates this action with the given event.

Parameters:
actionRequest -

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object