org.sf.codejen.js
Class JsWorker

java.lang.Object
  extended by org.sf.codejen.js.JsWorker
Direct Known Subclasses:
JsFileNameGenerator, JsModelExtractor, JsTemplateProcessor

public abstract class JsWorker
extends Object

Common base for JavaScript processing. It compiles the JavaScript before the execution to improve the performance.

Author:
Shane Ng

Constructor Summary
JsWorker()
           
 
Method Summary
protected  Object exec(Object model, Class resultClass)
          Executes the script with the model.
 void setModelName(String modelName)
          Sets the name of the context variable.
 void setScript(String script)
          Sets the script(s) for execution.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsWorker

public JsWorker()
Method Detail

setModelName

public void setModelName(String modelName)
Sets the name of the context variable.

Parameters:
modelName - the name of context variable.

setScript

public void setScript(String script)
               throws Exception
Sets the script(s) for execution. It can be:

Parameters:
script - the script for execution.
Throws:
Exception - when error like IO error and compile error is encountered.

exec

protected Object exec(Object model,
                      Class resultClass)
Executes the script with the model.

Parameters:
model - the model to be used in the script.
resultClass - the class of the returning result.
Returns:
execution result of the script.