pnuts.ext
Class CachedScript

java.lang.Object
  extended by pnuts.lang.Pnuts
      extended by pnuts.ext.CachedScript
All Implemented Interfaces:
java.io.Serializable, Executable

public class CachedScript
extends Pnuts

Executable script that is automatically recompiled

See Also:
Serialized Form

Field Summary
protected  java.lang.String encoding
           
protected  long parsedTime
           
protected  Pnuts script
           
protected  java.net.URL scriptURL
           
 
Fields inherited from class pnuts.lang.Pnuts
pnuts_version, prompt, scriptSource, startNodes
 
Constructor Summary
CachedScript(java.net.URL scriptURL)
          Constructor
CachedScript(java.net.URL scriptURL, java.lang.String encoding, Context context)
          Constructor
 
Method Summary
 java.lang.Object accept(Visitor v, Context c)
          traverse the parsed tree with the specified Visitor and Context
protected  Compiler getCompiler()
          Returns a compiler.
protected  boolean needToUpdate()
          Determin if the script should be recompiled
 java.lang.Object run(Context c)
          Executes a Pnuts object with the specified Context
 java.lang.String unparse()
          Obtain the script code from a parsed object
protected  void update(Context context)
          Parse/compile the script and update the timestamp.
 
Methods inherited from class pnuts.lang.Pnuts
accept, createClassLoader, createClassLoader, eval, evalDepth, format, get, get, getDefaults, getResource, getScriptSource, isJava2, isVerbose, load, load, load, load, load, load, loadClass, loadFile, parse, parse, parse, parse, parse, parse, require, require, set, set, setDefaults, setPrompt, setScriptSource, setVerbose, unparse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scriptURL

protected java.net.URL scriptURL

parsedTime

protected long parsedTime

script

protected Pnuts script

encoding

protected java.lang.String encoding
Constructor Detail

CachedScript

public CachedScript(java.net.URL scriptURL)
             throws java.io.IOException,
                    ParseException
Constructor

Parameters:
scriptURL - the URL of the script
Throws:
java.io.IOException
ParseException

CachedScript

public CachedScript(java.net.URL scriptURL,
                    java.lang.String encoding,
                    Context context)
             throws java.io.IOException,
                    ParseException
Constructor

Parameters:
scriptURL - the URL of the script
encoding - the character encoding of the script. If null, the default encoding is used.
context - the context in which the script is first parsed/compiled.
Throws:
java.io.IOException
ParseException
Method Detail

unparse

public java.lang.String unparse()
Description copied from class: Pnuts
Obtain the script code from a parsed object

Overrides:
unparse in class Pnuts
Returns:
the script code

run

public java.lang.Object run(Context c)
Description copied from class: Pnuts
Executes a Pnuts object with the specified Context

Specified by:
run in interface Executable
Overrides:
run in class Pnuts
Parameters:
c - the Context
Returns:
the result

accept

public java.lang.Object accept(Visitor v,
                               Context c)
Description copied from class: Pnuts
traverse the parsed tree with the specified Visitor and Context

Overrides:
accept in class Pnuts
c - the Context
Returns:
the result

needToUpdate

protected boolean needToUpdate()
Determin if the script should be recompiled

Returns:
true if the script should be recompiled

getCompiler

protected Compiler getCompiler()
Returns a compiler. If this method returns null, script won't be compiled.


update

protected void update(Context context)
               throws java.io.IOException,
                      ParseException
Parse/compile the script and update the timestamp.

Parameters:
context - the context in which the script is compiled.
Throws:
java.io.IOException
ParseException