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 Details

    • context

      protected IContext context
      Current context of this engine.
    • properties

      protected Properties properties
      Contains properties from this engine.
    • preProcessFile

      protected File preProcessFile
      Link to the output of pre-processing file. Null if engine running on [Memory] mode.
    • processFile

      protected File processFile
      Link to the output of processing file. Null if engine running on [Memory] mode.
    • isAborted

      protected boolean isAborted
      True if this engine is canceled.
  • Constructor Details

    • AbstractTemplateEngine

      public AbstractTemplateEngine()
      Default constructor.
  • Method Details

    • setContext

      protected void setContext(IContext context)
      Replace current context with another context.
      Parameters:
      context - new context.
    • addContext

      public Object addContext(String name, Object value)
      Add a name/value pair into the context. Before calling this method, programmer must make sure that context has been constructed or assigned by setContext(IContext) method.
      Specified by:
      addContext in interface ITemplateEngine
      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

      public IContext getContext()
      Return context of this engine.
      Specified by:
      getContext in interface ITemplateEngine
      Returns:
      context of engine
    • getProperty

      public Object getProperty(String key)
      Return an engine Runtime property.
      Specified by:
      getProperty in interface ITemplateEngine
      Parameters:
      key - the property key
      Returns:
      the value in this property list with the specified key value.
      See Also:
    • setProperty

      public void setProperty(String key, Object value)
      Set an engine Runtime property.
      Specified by:
      setProperty in interface ITemplateEngine
      Parameters:
      key - the key to be placed into this property list.
      value - the value corresponding to key.
      See Also:
    • getProperties

      public Properties getProperties()
      Returns the current properties of engine.
      Specified by:
      getProperties in interface ITemplateEngine
      Returns:
      the engine properties
    • addReferenceInsertionHandler

      public void addReferenceInsertionHandler(IReferenceInsertionHandler handler)
      Add a reference insertion event handler to the engine.
      Specified by:
      addReferenceInsertionHandler in interface ITemplateEngine
      Parameters:
      handler - ReferenceInsertionEventHandler
    • addInvalidReferenceHandler

      public void addInvalidReferenceHandler(IInvalidReferenceHandler handler)
      Add an invalid reference event handler to the engine.
      Specified by:
      addInvalidReferenceHandler in interface ITemplateEngine
      Parameters:
      handler - IInvalidReferenceHandler
    • getInvalidReferenceHandler

      public List<IInvalidReferenceHandler> getInvalidReferenceHandler()
      Return a IInvalidReferenceHandler of this engine.
      Specified by:
      getInvalidReferenceHandler in interface ITemplateEngine
      Returns:
      invalid reference handler for this engine.
    • getReferenceInsertionHandler

      public List<IReferenceInsertionHandler> getReferenceInsertionHandler()
      Return a IInvalidReferenceHandler of this engine.
      Specified by:
      getReferenceInsertionHandler in interface ITemplateEngine
      Returns:
      reference insertion handler for this engine.
    • addObserver

      public void addObserver(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. The order in which notifications will be delivered to multiple observers is not specified. See the class comment.
      Overrides:
      addObserver in class Observable
      Parameters:
      o - an observer to be added.
      Throws:
      NullPointerException - if the parameter o is null.
    • observers

      public Iterator<Observer> observers()
      Return current observer object in this engine.
      Returns:
      Iterator of current observer object.
    • notifyObservers

      public void notifyObservers(Object event)
      Override notifyObservers by provide sequence of calling these methods.
      
       setChanged();
       super.notifyObservers(event);
       
      Overrides:
      notifyObservers in class Observable
      Parameters:
      event - any object.
      See Also:
    • isMemoryMode

      protected boolean isMemoryMode(Template template)
      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

      public void evaluate(Template template) throws TemplateException
      Merge a template with current context and rendered stream into the writer.
      Specified by:
      evaluate in interface ITemplateEngine
      Parameters:
      template - Template being evaluated
      Throws:
      ParseErrorException - if a syntax or other error which prevents it from being parsed.
      InitializationEngineException - error while initializing engine
      TemplateException - other error while processing the template
      See Also:
    • evaluate

      public void evaluate(Template template, ITemplateEngine parentEngine) throws TemplateException
      Merge a template with current context and rendered stream into the writer.
      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 engine
      TemplateException - other error while processing the template
      See Also:
    • preProcess

      protected abstract void preProcess(Template template) throws TemplateException
      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 engine
      TemplateException - other error while processing the template
    • process

      protected abstract void process(Template template) throws TemplateException
      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 engine
      TemplateException - 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 engine
      TemplateException - other error while processing the template
    • postProcess

      protected abstract void postProcess(Template template) throws TemplateException
      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 engine
      TemplateException - other error while processing the template
    • destroy

      public void destroy()
      Called by the application or 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.

      Specified by:
      destroy in interface ITemplateEngine
    • abort

      public void abort()
      Called by the application to abort current evaluation context.
      Specified by:
      abort in interface ITemplateEngine
    • getCurrentRuntimeInstance

      public org.apache.velocity.runtime.RuntimeInstance getCurrentRuntimeInstance()
      Description copied from interface: com.nomagic.magicreport.engine.IRuntimeInstanceVelocityEngine
      Get (com.nomagic.magicreport.engine.velocity.ReportVelocityEngine.RuntimeInstance).
      Specified by:
      getCurrentRuntimeInstance in interface com.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.IRuntimeInstanceVelocityEngine
      Set current RuntimeInstance (com.nomagic.magicreport.engine.velocity.ReportVelocityEngine.RuntimeInstance).
      Specified by:
      setCurrentRuntimeInstance in interface com.nomagic.magicreport.engine.IRuntimeInstanceVelocityEngine
      Parameters:
      currentRuntimeInstance - current RuntimeInstance
    • setConcurrentToolException

      public void setConcurrentToolException(Exception e)
    • getConcurrentToolException

      public Exception getConcurrentToolException()