org.helma.javascript
Class ReloadableScript

java.lang.Object
  extended by org.helma.javascript.ReloadableScript

public class ReloadableScript
extends java.lang.Object

This class represents a JavaScript Resource.

Author:
Hannes Wallnoefer

Constructor Summary
ReloadableScript(Repository repository, RhinoEngine engine)
          Construct a Script from the given script repository, munging all contained script resources into one module.
ReloadableScript(Resource resource, RhinoEngine engine)
          Construct a Script from the given script resource.
 
Method Summary
 java.lang.Object evaluate(org.mozilla.javascript.Scriptable prototype, org.mozilla.javascript.Context cx)
          Evaluate the script on a module scope and return the result
protected  org.mozilla.javascript.Script getMultiScript(org.mozilla.javascript.Context cx)
          Get the a script composed out of multiple scripts.
 org.mozilla.javascript.Script getScript(org.mozilla.javascript.Context cx)
          Get the actual compiled script.
protected  boolean isUpToDate()
          Checks if the main file or any of the files it includes were updated since the script was last parsed and evaluated.
 org.mozilla.javascript.Scriptable load(org.mozilla.javascript.Scriptable prototype, org.mozilla.javascript.Context cx)
          Get a module scope loaded with this script
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReloadableScript

public ReloadableScript(Resource resource,
                        RhinoEngine engine)
Construct a Script from the given script resource.

Parameters:
resource - the JavaScript resource to be applied to this prototype.
engine - the rhino engine

ReloadableScript

public ReloadableScript(Repository repository,
                        RhinoEngine engine)
Construct a Script from the given script repository, munging all contained script resources into one module.

Parameters:
repository - the script repository.
engine - the rhino engine
Method Detail

getScript

public org.mozilla.javascript.Script getScript(org.mozilla.javascript.Context cx)
                                        throws org.mozilla.javascript.JavaScriptException,
                                               java.io.IOException
Get the actual compiled script.

Parameters:
cx - the current Context
Returns:
the compiled and up-to-date script
Throws:
org.mozilla.javascript.JavaScriptException - if an error occurred compiling the script code
java.io.IOException - if an error occurred reading the script file

getMultiScript

protected org.mozilla.javascript.Script getMultiScript(org.mozilla.javascript.Context cx)
                                                throws org.mozilla.javascript.JavaScriptException,
                                                       java.io.IOException
Get the a script composed out of multiple scripts. This is a bit of a hack we have in order to support helma 1 like one-directory-per-prototype like compilation mode.

Parameters:
cx - the current Context
Returns:
the compiled and up-to-date script
Throws:
org.mozilla.javascript.JavaScriptException - if an error occurred compiling the script code
java.io.IOException - if an error occurred reading the script file

evaluate

public java.lang.Object evaluate(org.mozilla.javascript.Scriptable prototype,
                                 org.mozilla.javascript.Context cx)
                          throws org.mozilla.javascript.JavaScriptException,
                                 java.io.IOException
Evaluate the script on a module scope and return the result

Parameters:
prototype - the parent scope for the module
cx - the rhino context
Returns:
the result of the evaluation
Throws:
org.mozilla.javascript.JavaScriptException - if an error occurred evaluating the script file
java.io.IOException - if an error occurred reading the script file

load

public org.mozilla.javascript.Scriptable load(org.mozilla.javascript.Scriptable prototype,
                                              org.mozilla.javascript.Context cx)
                                       throws org.mozilla.javascript.JavaScriptException,
                                              java.io.IOException
Get a module scope loaded with this script

Parameters:
prototype - the parent scope for the module
cx - the rhino context
Returns:
a new module scope
Throws:
org.mozilla.javascript.JavaScriptException - if an error occurred evaluating the script file
java.io.IOException - if an error occurred reading the script file

isUpToDate

protected boolean isUpToDate()
                      throws java.io.IOException
Checks if the main file or any of the files it includes were updated since the script was last parsed and evaluated.

Returns:
true if none of the included files has been updated since we last checked.
Throws:
java.io.IOException - an I/O exception occurred during the check