Package com.nomagic.magicreport.engine
Class AbstractTemplateEngine
java.lang.Object
java.util.Observable
com.nomagic.magicreport.engine.AbstractTemplateEngine
- All Implemented Interfaces:
com.nomagic.magicreport.engine.IRuntimeInstanceVelocityEngine,ITemplateEngine
- Direct Known Subclasses:
DefaultTemplateEngine
@OpenApiAll
public abstract class AbstractTemplateEngine
extends Observable
implements ITemplateEngine, com.nomagic.magicreport.engine.IRuntimeInstanceVelocityEngine
This class provides default implementations for the
ITemplateEngine Action interface. Standard
behaviors like the context and evaluate methods are defined here. The developer need only subclass this
abstract class and define the preProcess(Template), process(Template), and
postProcess(Template) method.- Since:
- Jun 11, 2007 10:45:01 PM
- Version:
- 1.0 Jun 11, 2007
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected IContextCurrent context of this engine.protected booleanTrue if this engine is canceled.protected FileLink to the output of pre-processing file.protected FileLink to the output of processing file.protected PropertiesContains properties from this engine. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Called by the application to abort current evaluation context.addContext(String name, Object value) Add a name/value pair into the context.voidAdd an invalid reference event handler to the engine.voidAdds an observer to the set of observers for this object, provided that it is not the same as some observer already in the set.voidAdd a reference insertion event handler to the engine.voiddestroy()Called by the application orTemplateEngineFactoryto inform this engine that it should destroy any resources that it has allocated.voidMerge a template with current context and rendered stream into the writer.voidevaluate(Template template, ITemplateEngine parentEngine) Merge a template with current context and rendered stream into the writer.Return context of this engine.org.apache.velocity.runtime.RuntimeInstanceGet (com.nomagic.magicreport.engine.velocity.ReportVelocityEngine.RuntimeInstance).Return aIInvalidReferenceHandlerof this engine.protected intReturn a process buffered size from configuration value.Returns the current properties of engine.getProperty(String key) Return an engine Runtime property.Return aIInvalidReferenceHandlerof this engine.protected booleanisMemoryMode(Template template) Tests if this template should process in memory mode.
This method is similar to code:voidnotifyObservers(Object event) OverridenotifyObserversby provide sequence of calling these methods.Return current observer object in this engine.protected abstract voidpostProcess(Template template) Perform a post-processing after the template has been evaluated.protected abstract voidpreProcess(Template template) Perform a pre-processing before evaluate the template.protected abstract voidProcess a template evaluation.protected abstract voidprocess(Template template, ITemplateEngine parentEngine) Process a template evaluation.voidprotected voidsetContext(IContext context) Replace current context with another context.voidsetCurrentRuntimeInstance(org.apache.velocity.runtime.RuntimeInstance currentRuntimeInstance) Set current RuntimeInstance (com.nomagic.magicreport.engine.velocity.ReportVelocityEngine.RuntimeInstance).voidsetProperty(String key, Object value) Set an engine Runtime property.Methods inherited from class java.util.Observable
clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, setChangedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.nomagic.magicreport.engine.ITemplateEngine
createTemplate, createTemplate, getFormatter
-
Field Details
-
context
Current context of this engine. -
properties
Contains properties from this engine. -
preProcessFile
Link to the output of pre-processing file. Null if engine running on [Memory] mode. -
processFile
Link to the output of processing file. Null if engine running on [Memory] mode. -
isAborted
protected boolean isAbortedTrue if this engine is canceled.
-
-
Constructor Details
-
AbstractTemplateEngine
public AbstractTemplateEngine()Default constructor.
-
-
Method Details
-
setContext
Replace current context with another context.- Parameters:
context- new context.
-
addContext
Add a name/value pair into the context. Before calling this method, programmer must make sure that context has been constructed or assigned bysetContext(IContext)method.- Specified by:
addContextin interfaceITemplateEngine- Parameters:
name- The name to key the provided value with.value- The corresponding value.- Returns:
- The old value or null if there was no old value.
- Throws:
NullPointerException- if context has not be constructed or assigned.
-
getContext
Return context of this engine.- Specified by:
getContextin interfaceITemplateEngine- Returns:
- context of engine
-
getProperty
Return an engine Runtime property.- Specified by:
getPropertyin interfaceITemplateEngine- Parameters:
key- the property key- Returns:
- the value in this property list with the specified key value.
- See Also:
-
setProperty
Set an engine Runtime property.- Specified by:
setPropertyin interfaceITemplateEngine- Parameters:
key- the key to be placed into this property list.value- the value corresponding to key.- See Also:
-
getProperties
Returns the current properties of engine.- Specified by:
getPropertiesin interfaceITemplateEngine- Returns:
- the engine properties
-
addReferenceInsertionHandler
Add a reference insertion event handler to the engine.- Specified by:
addReferenceInsertionHandlerin interfaceITemplateEngine- Parameters:
handler- ReferenceInsertionEventHandler
-
addInvalidReferenceHandler
Add an invalid reference event handler to the engine.- Specified by:
addInvalidReferenceHandlerin interfaceITemplateEngine- Parameters:
handler- IInvalidReferenceHandler
-
getInvalidReferenceHandler
Return aIInvalidReferenceHandlerof this engine.- Specified by:
getInvalidReferenceHandlerin interfaceITemplateEngine- Returns:
- invalid reference handler for this engine.
-
getReferenceInsertionHandler
Return aIInvalidReferenceHandlerof this engine.- Specified by:
getReferenceInsertionHandlerin interfaceITemplateEngine- Returns:
- reference insertion handler for this engine.
-
addObserver
Adds an observer to the set of observers for this object, provided that it is not the same as some observer already in the set. The order in which notifications will be delivered to multiple observers is not specified. See the class comment.- Overrides:
addObserverin classObservable- Parameters:
o- an observer to be added.- Throws:
NullPointerException- if the parameter o is null.
-
observers
Return current observer object in this engine.- Returns:
Iteratorof current observer object.
-
notifyObservers
OverridenotifyObserversby provide sequence of calling these methods.setChanged(); super.notifyObservers(event);- Overrides:
notifyObserversin classObservable- Parameters:
event- any object.- See Also:
-
isMemoryMode
Tests if this template should process in memory mode.
This method is similar to code:template.getSize() > properties.getProperty(TemplateConstants.TEMPLATE_PROCESS_SIZE, "0")- Parameters:
template- a test Template- Returns:
- true if template size is less than TEMPLATE_PROCESS_SIZE
-
getProcessSize
protected int getProcessSize()Return a process buffered size from configuration value. Default is 3,145,728 bytes.- Returns:
- a process buffered size
- Since:
- 17.0.4
-
evaluate
Merge a template with current context and rendered stream into the writer.- Specified by:
evaluatein interfaceITemplateEngine- Parameters:
template- Template being evaluated- Throws:
ParseErrorException- if a syntax or other error which prevents it from being parsed.InitializationEngineException- error while initializing engineTemplateException- other error while processing the template- See Also:
-
evaluate
Merge a template with current context and rendered stream into the writer.- Parameters:
template- Template being evaluatedparentEngine- an engine to shared a runtime instance for evaluate- Throws:
ParseErrorException- if a syntax or other error which prevents it from being parsed.InitializationEngineException- error while initializing engineTemplateException- other error while processing the template- See Also:
-
preProcess
Perform a pre-processing before evaluate the template.- Parameters:
template- template before evaluated.- Throws:
ParseErrorException- if a syntax or other error which prevents it from being parsed.InitializationEngineException- error while initializing engineTemplateException- other error while processing the template
-
process
Process a template evaluation.- Parameters:
template- template being evaluated.- Throws:
ParseErrorException- if a syntax or other error which prevents it from being parsed.InitializationEngineException- error while initializing engineTemplateException- other error while processing the template
-
process
protected abstract void process(Template template, ITemplateEngine parentEngine) throws TemplateException Process a template evaluation.- Parameters:
template- template being evaluated.parentEngine- an engine to shared a runtime instance for evaluate- Throws:
ParseErrorException- if a syntax or other error which prevents it from being parsed.InitializationEngineException- error while initializing engineTemplateException- other error while processing the template
-
postProcess
Perform a post-processing after the template has been evaluated.- Parameters:
template- template after evaluated.- Throws:
ParseErrorException- if a syntax or other error which prevents it from being parsed.InitializationEngineException- error while initializing engineTemplateException- other error while processing the template
-
destroy
public void destroy()Called by the application orTemplateEngineFactoryto inform this engine that it should destroy any resources that it has allocated.A subclass of engine should override this method if it has any operation that it wants to perform before it is destroyed.
- Specified by:
destroyin interfaceITemplateEngine
-
abort
public void abort()Called by the application to abort current evaluation context.- Specified by:
abortin interfaceITemplateEngine
-
getCurrentRuntimeInstance
public org.apache.velocity.runtime.RuntimeInstance getCurrentRuntimeInstance()Description copied from interface:com.nomagic.magicreport.engine.IRuntimeInstanceVelocityEngineGet (com.nomagic.magicreport.engine.velocity.ReportVelocityEngine.RuntimeInstance).- Specified by:
getCurrentRuntimeInstancein interfacecom.nomagic.magicreport.engine.IRuntimeInstanceVelocityEngine- Returns:
- current RuntimeInstance
-
setCurrentRuntimeInstance
public void setCurrentRuntimeInstance(org.apache.velocity.runtime.RuntimeInstance currentRuntimeInstance) Description copied from interface:com.nomagic.magicreport.engine.IRuntimeInstanceVelocityEngineSet current RuntimeInstance (com.nomagic.magicreport.engine.velocity.ReportVelocityEngine.RuntimeInstance).- Specified by:
setCurrentRuntimeInstancein interfacecom.nomagic.magicreport.engine.IRuntimeInstanceVelocityEngine- Parameters:
currentRuntimeInstance- current RuntimeInstance
-
setConcurrentToolException
-
getConcurrentToolException
-