@OpenApiAll public abstract class AbstractTemplateEngine extends java.util.Observable implements ITemplateEngine, IRuntimeInstanceVelocityEngine
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.Modifier and Type | Field and Description |
---|---|
protected IContext |
context
Current context of this engine.
|
protected boolean |
isAborted
True if this engine is canceled.
|
protected java.io.File |
preProcessFile
Link to the output of pre-processing file.
|
protected java.io.File |
processFile
Link to the output of processing file.
|
protected java.util.Properties |
properties
Contains properties from this engine.
|
Constructor and Description |
---|
AbstractTemplateEngine()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Called by the application to abort current evaluation context.
|
java.lang.Object |
addContext(java.lang.String name,
java.lang.Object value)
Add a name/value pair into the context.
|
void |
addInvalidReferenceHandler(IInvalidReferenceHandler handler)
Add an invalid reference event handler to the engine.
|
void |
addObserver(java.util.Observer o)
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.
|
void |
addReferenceInsertionHandler(IReferenceInsertionHandler handler)
Add a reference insertion event handler to the engine.
|
void |
destroy()
Called by the application or
TemplateEngineFactory to inform this engine
that it should destroy any resources that it has allocated. |
void |
evaluate(Template template)
Merge a template with current context and rendered stream into the writer.
|
void |
evaluate(Template template,
ITemplateEngine parentEngine)
Merge a template with current context and rendered stream into the writer.
|
java.lang.Exception |
getConcurrentToolException() |
IContext |
getContext()
Return context of this engine.
|
org.apache.velocity.runtime.RuntimeInstance |
getCurrentRuntimeInstance()
Get (com.nomagic.magicreport.engine.velocity.ReportVelocityEngine.RuntimeInstance).
|
java.util.List<IInvalidReferenceHandler> |
getInvalidReferenceHandler()
Return a
IInvalidReferenceHandler of this engine. |
protected int |
getProcessSize()
Return a process buffered size from configuration value.
|
java.util.Properties |
getProperties()
Returns the current properties of engine.
|
java.lang.Object |
getProperty(java.lang.String key)
Return an engine Runtime property.
|
java.util.List<IReferenceInsertionHandler> |
getReferenceInsertionHandler()
Return a
IInvalidReferenceHandler of this engine. |
protected boolean |
isMemoryMode(Template template)
Tests if this template should process in memory mode.
This method is similar to code: |
void |
notifyObservers(java.lang.Object event)
Override
notifyObservers by provide sequence of calling these methods. |
java.util.Iterator<java.util.Observer> |
observers()
Return current observer object in this engine.
|
protected abstract void |
postProcess(Template template)
Perform a post-processing after the template has been evaluated.
|
protected abstract void |
preProcess(Template template)
Perform a pre-processing before evaluate the template.
|
protected abstract void |
process(Template template)
Process a template evaluation.
|
protected abstract void |
process(Template template,
ITemplateEngine parentEngine)
Process a template evaluation.
|
void |
setConcurrentToolException(java.lang.Exception e) |
protected void |
setContext(IContext context)
Replace current context with another context.
|
void |
setCurrentRuntimeInstance(org.apache.velocity.runtime.RuntimeInstance currentRuntimeInstance)
Set current RuntimeInstance (com.nomagic.magicreport.engine.velocity.ReportVelocityEngine.RuntimeInstance).
|
void |
setProperty(java.lang.String key,
java.lang.Object value)
Set an engine Runtime property.
|
clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, setChanged
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createTemplate, createTemplate, getFormatter
protected IContext context
protected java.util.Properties properties
protected java.io.File preProcessFile
protected java.io.File processFile
protected boolean isAborted
protected void setContext(IContext context)
context
- new context.public java.lang.Object addContext(java.lang.String name, java.lang.Object value)
setContext(IContext)
method.addContext
in interface ITemplateEngine
name
- The name to key the provided value with.value
- The corresponding value.java.lang.NullPointerException
- if context has not be constructed or assigned.public IContext getContext()
getContext
in interface ITemplateEngine
public java.lang.Object getProperty(java.lang.String key)
getProperty
in interface ITemplateEngine
key
- the property keyITemplateEngine.setProperty(String, Object)
public void setProperty(java.lang.String key, java.lang.Object value)
setProperty
in interface ITemplateEngine
key
- the key to be placed into this property list.value
- the value corresponding to key.ITemplateEngine.getProperty(String)
public java.util.Properties getProperties()
getProperties
in interface ITemplateEngine
public void addReferenceInsertionHandler(IReferenceInsertionHandler handler)
addReferenceInsertionHandler
in interface ITemplateEngine
handler
- ReferenceInsertionEventHandlerpublic void addInvalidReferenceHandler(IInvalidReferenceHandler handler)
addInvalidReferenceHandler
in interface ITemplateEngine
handler
- IInvalidReferenceHandlerpublic java.util.List<IInvalidReferenceHandler> getInvalidReferenceHandler()
IInvalidReferenceHandler
of this engine.getInvalidReferenceHandler
in interface ITemplateEngine
public java.util.List<IReferenceInsertionHandler> getReferenceInsertionHandler()
IInvalidReferenceHandler
of this engine.getReferenceInsertionHandler
in interface ITemplateEngine
public void addObserver(java.util.Observer o)
addObserver
in class java.util.Observable
o
- an observer to be added.java.lang.NullPointerException
- if the parameter o is null.public java.util.Iterator<java.util.Observer> observers()
Iterator
of current observer object.public void notifyObservers(java.lang.Object event)
notifyObservers
by provide sequence of calling these methods.
setChanged();
super.notifyObservers(event);
notifyObservers
in class java.util.Observable
event
- any object.Observable.clearChanged()
,
Observable.hasChanged()
,
Observer.update(java.util.Observable, java.lang.Object)
protected boolean isMemoryMode(Template template)
template.getSize() > properties.getProperty(TemplateConstants.TEMPLATE_PROCESS_SIZE, "0")
template
- a test Templateprotected int getProcessSize()
public void evaluate(Template template) throws TemplateException
evaluate
in interface ITemplateEngine
template
- Template being evaluatedParseErrorException
- if a syntax or other error which prevents it from being
parsed.InitializationEngineException
- error while initializing engineTemplateException
- other error while processing the templateITemplateEngine.evaluate(Template)
public void evaluate(Template template, ITemplateEngine parentEngine) throws TemplateException
template
- Template being evaluatedparentEngine
- an engine to shared a runtime instance for evaluateParseErrorException
- if a syntax or other error which prevents it from being
parsed.InitializationEngineException
- error while initializing engineTemplateException
- other error while processing the templateITemplateEngine.evaluate(Template)
protected abstract void preProcess(Template template) throws TemplateException
template
- template before evaluated.ParseErrorException
- if a syntax or other error which prevents it from being
parsed.InitializationEngineException
- error while initializing engineTemplateException
- other error while processing the templateprotected abstract void process(Template template) throws TemplateException
template
- template being evaluated.ParseErrorException
- if a syntax or other error which prevents it from being
parsed.InitializationEngineException
- error while initializing engineTemplateException
- other error while processing the templateprotected abstract void process(Template template, ITemplateEngine parentEngine) throws TemplateException
template
- template being evaluated.parentEngine
- an engine to shared a runtime instance for evaluateParseErrorException
- if a syntax or other error which prevents it from being
parsed.InitializationEngineException
- error while initializing engineTemplateException
- other error while processing the templateprotected abstract void postProcess(Template template) throws TemplateException
template
- template after evaluated.ParseErrorException
- if a syntax or other error which prevents it from being
parsed.InitializationEngineException
- error while initializing engineTemplateException
- other error while processing the templatepublic void destroy()
TemplateEngineFactory
to 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.
destroy
in interface ITemplateEngine
public void abort()
abort
in interface ITemplateEngine
public org.apache.velocity.runtime.RuntimeInstance getCurrentRuntimeInstance()
IRuntimeInstanceVelocityEngine
getCurrentRuntimeInstance
in interface IRuntimeInstanceVelocityEngine
public void setCurrentRuntimeInstance(org.apache.velocity.runtime.RuntimeInstance currentRuntimeInstance)
IRuntimeInstanceVelocityEngine
setCurrentRuntimeInstance
in interface IRuntimeInstanceVelocityEngine
currentRuntimeInstance
- current RuntimeInstancepublic void setConcurrentToolException(java.lang.Exception e)
public java.lang.Exception getConcurrentToolException()
Copyright © 2010 - No Magic Asia