org.norther.tammi.spray.filter
Class DefaultPipe

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.spray.filter.DefaultFilter
          extended by org.norther.tammi.spray.filter.DefaultPipe
All Implemented Interfaces:
Serializable, NotificationBroadcaster, NotificationEmitter, Filter, Manageable, MBeanDelegate, Pipe

public class DefaultPipe
extends DefaultFilter
implements Pipe

A default implementation of Pipe invoking a series of filters that have been configured to be called in order.

Version:
$Id: DefaultPipe.java,v 1.15 2009/09/28 15:08:26 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Constructor Summary
DefaultPipe()
          Constructs a new pipe.
 
Method Summary
 void addFilterName(int index, ObjectName name)
          Adds a new filter to the given location.
 void addFilterName(ObjectName name)
          Adds a new filter to the end of the pipe.
 void clearFilterNames()
          Clears all filters from the pipe.
 boolean containsFilterName(ObjectName filter)
          Checks whether the specified filter is in the pipe.
 void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
          Causes the specified request and response to be processed by the filters associated with this pipe, until one of these filters causes the response to be created and returned.
 ObjectName getFilterName(int index)
          Gets the indexed filter in the pipe.
 List<ObjectName> getFilterNames()
          Gets filters in the pipe.
 FilterReference.FilterState getFilterState(ObjectName filter)
          Gets the state of the named filter.
 FilterReference.FilterState getFilterState(ObjectName filter, int index)
          Gets the state of the indexed filter.
 Filter getFirstFilter()
          Gets the first registered filter in the pipe.
<F extends Filter>
F
getFirstFilter(Class<F> clazz)
          Gets the first registered filter of the specified class in the pipe.
 Filter getLastFilter()
          Gets the last registered filter in the pipe.
<F extends Filter>
F
getLastFilter(Class<F> clazz)
          Gets the last registered filter of the specified class in the pipe.
 Filter getNextFilter(int index)
          Gets the next registered filter following the given location.
<F extends Filter>
F
getNextFilter(int index, Class<F> clazz)
          Gets the next registered filter of the specified class following the given location.
 Filter getPreviousFilter(int index)
          Gets the previous registered filter preceding the given location.
<F extends Filter>
F
getPreviousFilter(int index, Class<F> clazz)
          Gets the previous registered filter of the specified class preceding the given location.
protected  int locate(ObjectName filter, FilterHandle<?>[] list, int start)
          Locates the specified filter in the filter list from the given location.
<F extends Filter>
int
locateFilter(Class<F> clazz)
          Locates the first registered filter of the specified class in the pipe.
<F extends Filter>
int
locateFilter(int index, Class<F> clazz)
          Locates the next registered filter of the specified class following the given location.
 int locateNamedFilter(ObjectName filter)
          Locates the named filter in the pipe.
 int locateNamedFilter(ObjectName filter, int index)
          Locates the named filter in the pipe from the given location.
 Filter queryFilter(String pattern)
          Queries for a specified filter in the pipe.
 void removeFilterName(int index)
          Removes the indexed filter from the pipe.
 void removeFilterName(ObjectName name)
          Removes the first filter with the specified name from the pipe.
 void setFilterName(int index, ObjectName name)
          Sets the indexed filter in the pipe.
 void setFilterNames(List<ObjectName> names)
          Sets filters in the pipe.
 void setFilterState(ObjectName filter, FilterReference.FilterState state)
          Sets the state of the named filter.
 void setFilterState(ObjectName filter, int index, FilterReference.FilterState state)
          Sets the state of the indexed filter.
 
Methods inherited from class org.norther.tammi.spray.filter.DefaultFilter
destroy, getFilterConfig, getRequestMap, getSessionMap, init
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unmanaged, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.Filter
destroy, init
 

Constructor Detail

DefaultPipe

public DefaultPipe()
Constructs a new pipe.

Method Detail

getFilterNames

public List<ObjectName> getFilterNames()
Description copied from interface: Pipe
Gets filters in the pipe.

Specified by:
getFilterNames in interface Pipe
Returns:
a list of object names of filters.

setFilterNames

public void setFilterNames(List<ObjectName> names)
Description copied from interface: Pipe
Sets filters in the pipe.

Specified by:
setFilterNames in interface Pipe
Parameters:
names - a list of object names of filters.

containsFilterName

public boolean containsFilterName(ObjectName filter)
Description copied from interface: Pipe
Checks whether the specified filter is in the pipe.

Specified by:
containsFilterName in interface Pipe
Parameters:
filter - the object name of the filter.
Returns:
true, if the filter is found.

getFilterName

public ObjectName getFilterName(int index)
Description copied from interface: Pipe
Gets the indexed filter in the pipe.

Specified by:
getFilterName in interface Pipe
Parameters:
index - the index of the location.
Returns:
the object name of the filter.

setFilterName

public void setFilterName(int index,
                          ObjectName name)
Description copied from interface: Pipe
Sets the indexed filter in the pipe.

Specified by:
setFilterName in interface Pipe
Parameters:
index - the index of the location.
name - the object name of the filter.

addFilterName

public void addFilterName(ObjectName name)
Description copied from interface: Pipe
Adds a new filter to the end of the pipe.

Specified by:
addFilterName in interface Pipe
Parameters:
name - the object name of the new filter.

addFilterName

public void addFilterName(int index,
                          ObjectName name)
Description copied from interface: Pipe
Adds a new filter to the given location.

Specified by:
addFilterName in interface Pipe
Parameters:
index - the index of the location.
name - the object name of the new filter.

removeFilterName

public void removeFilterName(ObjectName name)
Description copied from interface: Pipe
Removes the first filter with the specified name from the pipe.

Specified by:
removeFilterName in interface Pipe
Parameters:
name - the object name of the filter.

removeFilterName

public void removeFilterName(int index)
Description copied from interface: Pipe
Removes the indexed filter from the pipe.

Specified by:
removeFilterName in interface Pipe
Parameters:
index - the index of the location.

clearFilterNames

public void clearFilterNames()
Description copied from interface: Pipe
Clears all filters from the pipe.

Specified by:
clearFilterNames in interface Pipe

locateNamedFilter

public int locateNamedFilter(ObjectName filter)
Description copied from interface: Pipe
Locates the named filter in the pipe.

Specified by:
locateNamedFilter in interface Pipe
Parameters:
filter - the object name of the filter.
Returns:
the index of the filter or -1.

locateNamedFilter

public int locateNamedFilter(ObjectName filter,
                             int index)
Description copied from interface: Pipe
Locates the named filter in the pipe from the given location.

Specified by:
locateNamedFilter in interface Pipe
Parameters:
filter - the object name of the filter.
index - the start index of the location.
Returns:
the index of the filter or -1.

locateFilter

public <F extends Filter> int locateFilter(Class<F> clazz)
Description copied from interface: Pipe
Locates the first registered filter of the specified class in the pipe.

Specified by:
locateFilter in interface Pipe
Type Parameters:
F - the filter type.
Parameters:
clazz - the class or interface.
Returns:
the index of the filter or -1.

locateFilter

public <F extends Filter> int locateFilter(int index,
                                           Class<F> clazz)
Description copied from interface: Pipe
Locates the next registered filter of the specified class following the given location. The filter in the given location is included in the search.

Specified by:
locateFilter in interface Pipe
Type Parameters:
F - the filter type.
Parameters:
index - the start index of the location.
clazz - the class or interface.
Returns:
the index of the filter or -1.

queryFilter

public Filter queryFilter(String pattern)
Description copied from interface: Pipe
Queries for a specified filter in the pipe.

Specified by:
queryFilter in interface Pipe
Parameters:
pattern - the name pattern.
Returns:
the found filter or null.

getFirstFilter

public Filter getFirstFilter()
Description copied from interface: Pipe
Gets the first registered filter in the pipe.

Specified by:
getFirstFilter in interface Pipe
Returns:
the found filter or null.

getLastFilter

public Filter getLastFilter()
Description copied from interface: Pipe
Gets the last registered filter in the pipe.

Specified by:
getLastFilter in interface Pipe
Returns:
the found filter or null.

getNextFilter

public Filter getNextFilter(int index)
Description copied from interface: Pipe
Gets the next registered filter following the given location. The filter in the given location is included in the search.

Specified by:
getNextFilter in interface Pipe
Parameters:
index - the index of the location.
Returns:
the found filter or null.

getPreviousFilter

public Filter getPreviousFilter(int index)
Description copied from interface: Pipe
Gets the previous registered filter preceding the given location. The filter in the given location is included in the search.

Specified by:
getPreviousFilter in interface Pipe
Parameters:
index - the index the location.
Returns:
the found filter or null.

getFirstFilter

public <F extends Filter> F getFirstFilter(Class<F> clazz)
Description copied from interface: Pipe
Gets the first registered filter of the specified class in the pipe.

Specified by:
getFirstFilter in interface Pipe
Type Parameters:
F - the filter type.
Parameters:
clazz - the class or interface.
Returns:
the found filter or null.

getLastFilter

public <F extends Filter> F getLastFilter(Class<F> clazz)
Description copied from interface: Pipe
Gets the last registered filter of the specified class in the pipe.

Specified by:
getLastFilter in interface Pipe
Type Parameters:
F - the filter type.
Parameters:
clazz - the class or interface.
Returns:
the found filter or null.

getNextFilter

public <F extends Filter> F getNextFilter(int index,
                                          Class<F> clazz)
Description copied from interface: Pipe
Gets the next registered filter of the specified class following the given location. The filter in the given location is included in the search.

Specified by:
getNextFilter in interface Pipe
Type Parameters:
F - the filter type.
Parameters:
index - the index of the location.
clazz - the class or interface.
Returns:
the found filter or null.

getPreviousFilter

public <F extends Filter> F getPreviousFilter(int index,
                                              Class<F> clazz)
Description copied from interface: Pipe
Gets the previous registered filter of the specified class preceding the given location. The filter in the given location is included in the search.

Specified by:
getPreviousFilter in interface Pipe
Type Parameters:
F - the filter type.
Parameters:
index - the index of the location.
clazz - the class or interface.
Returns:
the found filter or null.

getFilterState

public FilterReference.FilterState getFilterState(ObjectName filter)
Description copied from interface: Pipe
Gets the state of the named filter.

Specified by:
getFilterState in interface Pipe
Parameters:
filter - the object name of the filter.
Returns:
the state of the filter or null if missing.

setFilterState

public void setFilterState(ObjectName filter,
                           FilterReference.FilterState state)
Description copied from interface: Pipe
Sets the state of the named filter.

Specified by:
setFilterState in interface Pipe
Parameters:
filter - the object name of the filter.
state - the state of the filter.

getFilterState

public FilterReference.FilterState getFilterState(ObjectName filter,
                                                  int index)
Description copied from interface: Pipe
Gets the state of the indexed filter.

Specified by:
getFilterState in interface Pipe
Parameters:
filter - the object name of the filter.
index - the start index of the location.
Returns:
the state of the filter or null if missing.

setFilterState

public void setFilterState(ObjectName filter,
                           int index,
                           FilterReference.FilterState state)
Description copied from interface: Pipe
Sets the state of the indexed filter.

Specified by:
setFilterState in interface Pipe
Parameters:
filter - the object name of the filter.
index - the start index of the location.
state - the state of the filter.

doFilter

public void doFilter(ServletRequest request,
                     ServletResponse response,
                     FilterChain chain)
              throws ServletException,
                     IOException
Description copied from interface: Pipe
Causes the specified request and response to be processed by the filters associated with this pipe, until one of these filters causes the response to be created and returned. The implementation must ensure that multiple simultaneous requests (on different threads) can be processed through the same pipe without interfering with each other's filter chain.

Note that changes to the list of filters in the pipe during one request will be effective only for forthcoming requests.

Specified by:
doFilter in interface Filter
Specified by:
doFilter in interface Pipe
Overrides:
doFilter in class DefaultFilter
Parameters:
request - the request to process.
response - the response to return.
chain - the filter chain from preceding pipes.
Throws:
ServletException - for servlet errors.
IOException - for general errors.

locate

protected int locate(ObjectName filter,
                     FilterHandle<?>[] list,
                     int start)
Locates the specified filter in the filter list from the given location.

Parameters:
filter - the object name of the filter.
list - the list of filter references.
start - the start index of the location.
Returns:
the index of the filter or -1.
Throws:
IndexOutOfBoundsException - for an incorrect index.


Copyright © 2004 The Norther Organization. All rights reserved.