PageMixer API - 3.1

jp.ne.dti.lares.foozy.pagemixer.mixer
Class Filter

java.lang.Object
  |
  +--jp.ne.dti.lares.foozy.pagemixer.mixer.Filter
All Implemented Interfaces:
Consumer
Direct Known Subclasses:
DefaultFilter, EventCheckFilter, FilterPipeline, SequenceEditFilter, TokenEditFilter, TrimFilter

public abstract class Filter
extends java.lang.Object
implements Consumer

Abstract implementation of consumer to "filter" token stream.

One Consumer should not do all things to create final HTML page image, because of modulality, re-usability, testability, consistency and so on. Processing should be divided in small, simple, mono-function units like as many UNIX commands.

This class provides abstraction to "filter" of token stream.

On input side, this behaves as same as Consumer, and on output side, this behaves as "producer" of another Consumer to which this is connected by connectTo(Consumer).

This mechanism makes it easy to insert additional funcionality after all.

You must concretize below method(s) to have this function.

And you should register cleanup procedure to clear internal status at invocation of clear().


Inner Class Summary
static interface Filter.Factory
          Factory interface to create "Filter".
 
Constructor Summary
Filter()
          Construct filter.
 
Method Summary
protected  void addCleanup(java.lang.Runnable cleanup)
          Add custom clean up procedure as Runnable.
 void clear()
          Clear internal status to reuse itself.
 void connectTo(Consumer consumer)
          Connect token stream "output" to specified consumer.
abstract  void consume(ConsumerContext context, Token token)
          Consume token with specified context.
abstract  void flush(ConsumerContext context)
          Finalize with specified context.
protected  Consumer getConsumer()
          Get consumer to which it is connected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Filter

public Filter()
Construct filter.

This registers cleanup procedure to invoke clear() of connected one.

Method Detail

connectTo

public final void connectTo(Consumer consumer)
Connect token stream "output" to specified consumer.
Parameters:
consumer - this object is connected to.

getConsumer

protected final Consumer getConsumer()
Get consumer to which it is connected.
Returns:
consumer this object is connected to.

addCleanup

protected final void addCleanup(java.lang.Runnable cleanup)
Add custom clean up procedure as Runnable.

This method adds specified Runnable instance to cleanup procedure list, and invokes them at invocation of own clear() method.

This allows you to extend cleanup procedure unless method overriding with invocation of "super.cleanup()".

For example:

 public class CustomFilter
     extends Filter // or other derived class
 {
     // Constructor
     pubilc CustomFilter(){
           :
           :
         Runnable cleanup = new Runnable(){
             public void run(){
                 // custom clean up procedure
             }
         };
         addCleanup(cleanup);
         cleanup.run();
     }
 }
 

In above example, "cleanup.run()" is invoked instead of clear(), because the later causes invocation of all registrated cleanup procedures but only custom class local cleanup is required in this situation (base class cleanup procedures should be invoked in their own constructors).

Parameters:
cleanup - procedure as Runnable.

consume

public abstract void consume(ConsumerContext context,
                             Token token)
                      throws MixingIOException
Consume token with specified context.
Specified by:
consume in interface Consumer
Parameters:
context - on which consuming processing depends
token - to be processed
Throws:
MixingIOException - IOException is thrown

flush

public abstract void flush(ConsumerContext context)
                    throws MixingIOException
Finalize with specified context.

This method indicate end of token stream, in other word, works like "consume(context, EOF)".

Implementation class should clear internal status on completion of invocation.

Specified by:
flush in interface Consumer
Parameters:
context - on which consuming processing depends on
Throws:
MixingIOException - IOException is thrown

clear

public void clear()
Clear internal status to reuse itself.

This invokes registrated procedures(as Runnable) one by one.

Specified by:
clear in interface Consumer
Since:
PageMixer 3.0
See Also:
addCleanup(Runnable)

PageMixer API - 3.1