net.wgen.op.http.filter
Class ParamTriggerFilter

java.lang.Object
  extended bynet.wgen.op.http.filter.ParamTriggerFilter
All Implemented Interfaces:
javax.servlet.Filter

public class ParamTriggerFilter
extends java.lang.Object
implements javax.servlet.Filter

An HttpFilter that evaluates the request parameters and triggers specific behavior. Param names in the filter's config that start with "initializer" should have values that are the fully-qualified java class names of classes that implement the TriggerInitializer interface. These objects, once instantiated and invoked, will register their ParamTriggers in this filter. When acting on HttpServletRequests, the filter evaluates the request parameter names and fires triggers that respond to the parameter names. ParamTriggerListeners that are registered with the ParamTriggers are then notified when the ParamTrigger fires in response to the presence of the parameter. Some ParamTriggers may also set values in the HttpSession.

Version:
$Id: ParamTriggerFilter.html,v 1.2 2007/01/28 04:09:37 paulfeuer Exp $
Author:
Paul Feuer, Wireless Generation, Inc.

Field Summary
private  javax.servlet.FilterConfig _filterConfig
           
private  java.util.Map _triggers
           
private static org.apache.log4j.Logger LOG
           
 
Constructor Summary
ParamTriggerFilter()
           
 
Method Summary
 void destroy()
           
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain filterChain)
          Perform the filter by unpacking the request parameters, evaluating each, adding anything from the session, continuing with the filterChain, and then once back, telling the WebAppStats that the request is finished.
 javax.servlet.FilterConfig getFilterConfig()
          The configuration available for usage by TraceTriggerInitializers.
private  void handleParam(java.lang.String paramName, java.lang.String paramValue, ParamTriggerState triggerState, javax.servlet.http.HttpServletRequest request)
          Check whether or not any of the listeners responds to the parameter name, and if a trigger does, fire it.
 void init(javax.servlet.FilterConfig filterConfig)
          Check the filter's parameters for property names that start with "initializer" and try to instantiate and invoke those TriggerInitializer instances to register triggers in the filter.
private  void processTriggerStoredSessionValues(ParamTriggerState triggerState, javax.servlet.http.HttpServletRequest request)
          After processing each param, tell each trigger to fire any session-stored information it cares about.
 void registerTrigger(ParamTrigger trigger)
          Add a trigger to the filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final org.apache.log4j.Logger LOG

_triggers

private java.util.Map _triggers

_filterConfig

private javax.servlet.FilterConfig _filterConfig
Constructor Detail

ParamTriggerFilter

public ParamTriggerFilter()
Method Detail

init

public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
Check the filter's parameters for property names that start with "initializer" and try to instantiate and invoke those TriggerInitializer instances to register triggers in the filter.

Specified by:
init in interface javax.servlet.Filter
Parameters:
filterConfig -
Throws:
javax.servlet.ServletException - if the initializer class cannot be instantiated, or if the object instantiated does not implement the TriggerInitializer interface

getFilterConfig

public javax.servlet.FilterConfig getFilterConfig()
The configuration available for usage by TraceTriggerInitializers.

Returns:
the filter configuration

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain filterChain)
              throws java.io.IOException,
                     javax.servlet.ServletException
Perform the filter by unpacking the request parameters, evaluating each, adding anything from the session, continuing with the filterChain, and then once back, telling the WebAppStats that the request is finished.

By the time the filterChain continuation is invoked, there will be a TraceKey in the request attributes, and if any triggers fired, the TraceKey userData will have the options that were set by those triggers registered at the ParamTriggerState.TRACE_KEY_USER_DATA_KEY key.

Once back, all that remains to be done is to notify the WebAppStats that the request is complete.

Specified by:
doFilter in interface javax.servlet.Filter
Parameters:
request -
response -
filterChain -
Throws:
java.io.IOException
javax.servlet.ServletException

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Filter

processTriggerStoredSessionValues

private void processTriggerStoredSessionValues(ParamTriggerState triggerState,
                                               javax.servlet.http.HttpServletRequest request)
After processing each param, tell each trigger to fire any session-stored information it cares about.

Parameters:
triggerState -
request -
See Also:
ParamTrigger.fireSessionStoredAttribs(ParamTriggerState, javax.servlet.http.HttpServletRequest)

handleParam

private void handleParam(java.lang.String paramName,
                         java.lang.String paramValue,
                         ParamTriggerState triggerState,
                         javax.servlet.http.HttpServletRequest request)
Check whether or not any of the listeners responds to the parameter name, and if a trigger does, fire it.

Parameters:
paramName - the parameter name
paramValue - the value of the parameter
triggerState - the state object containing which triggers have fired and what options have been set
request - the request being evaluated by the filter

registerTrigger

public void registerTrigger(ParamTrigger trigger)
Add a trigger to the filter.

Parameters:
trigger -