shocks.client
Class FilterSupport

java.lang.Object
  extended byshocks.client.FilterSupport
All Implemented Interfaces:
Action
Direct Known Subclasses:
Example, I18N

public abstract class FilterSupport
extends java.lang.Object
implements Action

Filters are a special type of Action, designed to add crosscutting functionality to the system. The basic idea behind a Filter is that it executes logic which crosscuts other actions in the system.

More specifically, the concerns of Filter components crosscut the entire application. Internationalization (i18n), action-level security, OR mappings, metrics and tracking, custom error handling, alerts--these are things which potentially affect every action in the sytem.

And the system is trained to assemble sequences of filters which perform these crosscutting concerns on actions, as specified in the workflow descriptor at the time a module is loaded into the application.

When the concerns change, a new module can be assembled which alters the filtration mechanisms to reflect the new process.

In all other regards, filters are just another type of Action object. They have access to the same information that target actions have access to, but the information they pass back to the workflow components can actually interrupt the flow of control and prevent it from reaching a target action at all. For example, a security filter can interrupt the workflow before it ever reaches the target action (which would otherwise call the database). Or, a logging filter can track the number of times certain target actions are performed, allowing the system to gather metrics data. Another filter could negotiate Locale information from the browser and retrieve information from resource bundles.

So, filters allow the introduction of system-level concerns which can be applied in any order on the way into or out of a workflow sequence.


Field Summary
 java.lang.String FAILURE
          Tells the enclosing Filter to terminate the workflow sequence and return an error to the WorkflowProcessor.
 java.lang.String SUCCESS
          Tells the enclosing Filter to proceed with the workflow sequence.
 
Constructor Summary
FilterSupport()
           
 
Method Summary
protected abstract  java.lang.String execute(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Developers are required to override this method when writing crosscutting actions.
 DataSource execute(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext ctx)
          This method is final and cannot be overridden by the user.
protected  java.lang.String getFilterName()
          Returns the name of the enclosing Filter object.
protected  java.lang.String getFilterVersion()
          Returns the version of the enclosing Filter object.
protected  javax.servlet.ServletContext getServletContext()
          Provides access to the ServletContext.
 void setFilterMetadata(DataSource metadata)
          Staffs the filter with metadata from its enclosing Filter object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUCCESS

public final java.lang.String SUCCESS
Tells the enclosing Filter to proceed with the workflow sequence.

See Also:
Constant Field Values

FAILURE

public final java.lang.String FAILURE
Tells the enclosing Filter to terminate the workflow sequence and return an error to the WorkflowProcessor.

See Also:
Constant Field Values
Constructor Detail

FilterSupport

public FilterSupport()
Method Detail

getFilterName

protected java.lang.String getFilterName()
Returns the name of the enclosing Filter object.

Returns:
String

getFilterVersion

protected java.lang.String getFilterVersion()
Returns the version of the enclosing Filter object.

Returns:
String

setFilterMetadata

public void setFilterMetadata(DataSource metadata)
Staffs the filter with metadata from its enclosing Filter object.

Parameters:
metadata -

getServletContext

protected javax.servlet.ServletContext getServletContext()
Provides access to the ServletContext.

Returns:
ServletContext

execute

public DataSource execute(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response,
                          javax.servlet.ServletContext ctx)

This method is final and cannot be overridden by the user. It is specifically designed for use by the container. The method the user should concern themselves with is below.

This method is called by the enclosing Filter object. Its purpose is to staff the action with a request & response pair, and a reference to the current servlet context. It also allows the designers of the framework to change the Action interface at a later time without forcing the users to alter the actions they've already built.

Specified by:
execute in interface Action
Returns:
DataSource

execute

protected abstract java.lang.String execute(javax.servlet.http.HttpServletRequest request,
                                            javax.servlet.http.HttpServletResponse response)

Developers are required to override this method when writing crosscutting actions. They may perform operations on the request and response objects, make use of the servlet context, get relevant data about the workflow sequence currently in progress, and pass data back and forth between filter components by using the FilterResult object.

This method must return a command string to its enclosing Filter object. There are two standard results which are allowed by the framework: SUCCESS and FAILURE. An example of their use follows:

return SUCCESS;

This tells the workflow processor that execution of the FilterSupport class has been successful and that it should proceed to the next step in the workflow sequence. If any string value other than SUCCESS is returned to the container, it will assume that the workflow sequence has been terminated and return control to the WorkflowController.

Parameters:
request -
response -
Returns:
String