fmpp.localdatabuilders
Class CachingLocalDataBuilder

java.lang.Object
  extended by fmpp.localdatabuilders.CachingLocalDataBuilder
All Implemented Interfaces:
LocalDataBuilder, ProgressListener
Direct Known Subclasses:
TddHashLocalDataBuilder

public abstract class CachingLocalDataBuilder
extends java.lang.Object
implements LocalDataBuilder, ProgressListener

Stores the returned Map, and reuses it build(Engine, TemplateEnvironment) is invoked again during the same processing session. This is useful when the building of the local data is an expensive operation, and the builder is used for multiple source files.

The stored Map will be deleted at the end of the processing session.


Field Summary
 
Fields inherited from interface fmpp.ProgressListener
EVENT_BEGIN_FILE_PROCESSING, EVENT_BEGIN_PROCESSING_SESSION, EVENT_END_FILE_PROCESSING, EVENT_END_PROCESSING_SESSION, EVENT_IGNORING_DIR, EVENT_SOURCE_NOT_MODIFIED, EVENT_WARNING
 
Constructor Summary
CachingLocalDataBuilder()
           
 
Method Summary
protected abstract  java.util.Map build(Engine eng)
          Override this method in your local data builder class.
 java.util.Map build(Engine eng, TemplateEnvironment env)
          Takes care of caching, and calls build(Engine) if no cached result is available.
 void notifyProgressEvent(Engine engine, int event, java.io.File src, int pMode, java.lang.Throwable error, java.lang.Object param)
          Discards the cached result on ProgressListener.EVENT_END_PROCESSING_SESSION.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingLocalDataBuilder

public CachingLocalDataBuilder()
Method Detail

build

public final java.util.Map build(Engine eng,
                                 TemplateEnvironment env)
                          throws java.lang.Exception
Takes care of caching, and calls build(Engine) if no cached result is available.

Specified by:
build in interface LocalDataBuilder
Returns:
the variables to add to the local data. Can be null. The returned map will not be modified (although technically, badly behaved 3rd party code can modify the values soted in the map...).
Throws:
java.lang.Exception

notifyProgressEvent

public void notifyProgressEvent(Engine engine,
                                int event,
                                java.io.File src,
                                int pMode,
                                java.lang.Throwable error,
                                java.lang.Object param)
                         throws java.lang.Exception
Discards the cached result on ProgressListener.EVENT_END_PROCESSING_SESSION.

The TemplateEnvironment is not passed, to ensure that the returned Map doesn't depend on the source file the builder is used for, so reusing the result for other source files is safe.

Specified by:
notifyProgressEvent in interface ProgressListener
Parameters:
engine - The engine instance where the event has occured.
event - The code of the envent: an EVENT_... constant. As new event types can be introduced with new FMPP versions (even if it happens very seldom), a progress listener implementation should survive events that it does not understand. That is, it must not stop with an error, but it should silently ignore the event.
src - Depending on event the source file or null.
pMode - Depending on event the proccessing mode (Engine.PMODE_... constant) or Engine.PMODE_NONE. Note that new processing modes may be added as FMPP evolvers, so values that are not known be the progress listener should be handler nicely, and never cause error.
error - The error, or null if there was no error.
param - Extra information about the event. The class and meaning of object depends on the concrete event:
  • For EVENT_WARNING it is a String that describles the reason of warning.
Throws:
java.lang.Exception

build

protected abstract java.util.Map build(Engine eng)
                                throws java.lang.Exception
Override this method in your local data builder class.

Throws:
java.lang.Exception