org.xfp
Class Filter

java.lang.Object
  extended byorg.xfp.AttributeContainer
      extended byorg.xfp.Filter
Direct Known Subclasses:
AntTask, BeanCollectionSorter, BeanInstance, BeanXMLDecoder, BeanXMLEncoder, ByteArrayToInputStream, CheckAlreadyFiltered, CodecBinaryDecoder, CodecBinaryEncoder, CodecStringDecoder, CodecStringEncoder, DateGenerator, DeleteFile, DOMParser, FileReader, FileWriter, FOProcessor, FTPAbstractFilter, HTTPGet, InputStreamToByteArray, InputStreamToString, Iterator, JNDIAbstractFilter, JXPathAbstractFilter, ListGenerator, MapGenerator, MapIterator, PassThru, PatternMatcher, ReaderToString, StringToInputStream, XPathAbstractFilter, XSLTransformer

public abstract class Filter
extends AttributeContainer

Base class for all filters. Subclasses must provide a public method named 'execute' accepting 0 or 1 arguments of any type (but primitives) and returning any type (but primitives) or void. Example:

public List execute(String input)

Filters are parameterized by using JavaBeans setter methods.

Any Exception occurred during filter execution should not be trapped, the container takes care of handling exceptions.

Subclasses do not need to call super() constructor, since it is empty.

Filter instances are reused by the container, so make sure to correctly reset the Filter status in the reset method. Filters are never used concurrently by multiple threads, a Filter implementation does not have to be thread-safe.

TODO manage primitives in execute method. TODO discuss superclasses in signatures

Version:
$Id: Filter.java,v 1.1 2004/03/19 15:56:42 flaviotordini Exp $
Author:
Flavio Tordini

Nested Class Summary
static class Filter.OnErrorEnum
          OnError typesafe enumeration.
static class Filter.OnLoopErrorEnum
          OnLoopError typesafe enumeration.
 
Field Summary
 
Fields inherited from class org.xfp.AttributeContainer
name, parentContainer
 
Constructor Summary
Filter()
           
 
Method Summary
protected  Filter.OnErrorEnum getOnError()
          Gets the onError attribute of the Filter object.
 void initialize()
          Initializes the filter.
protected  void log(java.lang.String message)
          Subclasses can use this method to log for debugging purposes.
protected static Filter newInstance(org.w3c.dom.Node filternode, org.w3c.dom.xpath.XPathEvaluator evaluator, java.lang.Class inputtype, AttributeContainer parent, org.apache.log4j.spi.LoggerRepository loggerRepository)
          Instantiates and initializes a Filter.
 void perform(org.xfp.FilterContext context, java.lang.Object parentoutput)
          Performing a filter consists of: provide filter attributes set filter properties invoke the 'execute' method call the 'release' method perform children filters release filter attributes Filter developers never call this method!
abstract  void reset()
          Resets filter status after execution.
 java.lang.String toString()
           
 
Methods inherited from class org.xfp.AttributeContainer
configureAttributes, disposeAttributes, getAttributes, getFullName, getName, initializeAttributes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Filter

public Filter()
Method Detail

initialize

public void initialize()
                throws java.lang.Exception
Initializes the filter. Called by the container to let the filter initialize properly. The default implementation is a no-op. Override this method to initialize your Filter.

Throws:
java.lang.Exception - Description of the Exception
See Also:
Initializable.initialize()

reset

public abstract void reset()
Resets filter status after execution. This method is called after execute(), even in case of exceptions. Since a Filter instance may be reused (and actually is), you must use this method to reset all your class members to their default value.


toString

public final java.lang.String toString()
See Also:
Object.toString()

perform

public final void perform(org.xfp.FilterContext context,
                          java.lang.Object parentoutput)
                   throws java.lang.Exception
Performing a filter consists of:
  1. provide filter attributes
  2. set filter properties
  3. invoke the 'execute' method
  4. call the 'release' method
  5. perform children filters
  6. release filter attributes
Filter developers never call this method!

Parameters:
parentoutput - output of the parent filter
context - Description of the Parameter
Throws:
java.lang.Exception - Description of the Exception

getOnError

protected final Filter.OnErrorEnum getOnError()
Gets the onError attribute of the Filter object. This value determines what to do in case of exception during filter execution.

Returns:
The onError value (one of the OnErrorEnum constants)

log

protected final void log(java.lang.String message)
Subclasses can use this method to log for debugging purposes.

Parameters:
message - Description of the Parameter

newInstance

protected static final Filter newInstance(org.w3c.dom.Node filternode,
                                          org.w3c.dom.xpath.XPathEvaluator evaluator,
                                          java.lang.Class inputtype,
                                          AttributeContainer parent,
                                          org.apache.log4j.spi.LoggerRepository loggerRepository)
                                   throws java.lang.Exception
Instantiates and initializes a Filter. Always use this method to get new instances, rather than directly instantiating a Filter impl. Filter developers never call this method!

Parameters:
filternode - Node representing a filter in XML configuration
evaluator - XPath Evaluator
inputtype - the input data type this filter will process (i.e. the parent filter output data type)
Returns:
Filter an initialized Filter instance
Throws:
java.lang.Exception - Description of the Exception


Copyright 2003-2004 XFP Team. All Rights Reserved.