pnuts.ext
Class CachedPnutsImpl

java.lang.Object
  extended by pnuts.lang.Runtime
      extended by pnuts.lang.PnutsImpl
          extended by pnuts.ext.CachedPnutsImpl
All Implemented Interfaces:
Executable, Implementation

public class CachedPnutsImpl
extends PnutsImpl

PnutsImpl which caches parsed (compiled) scripts and reuse them. This class is useful when same scripts are executed over and over, e.g. servlet scripts.

See Also:
PnutsImpl

Nested Class Summary
static class CachedPnutsImpl.ScriptCacheEntry
           
 
Nested classes/interfaces inherited from class pnuts.lang.Runtime
Runtime.Accessor, Runtime.Break, Runtime.Continue, Runtime.FunctionSerializer, Runtime.TypeMap
 
Field Summary
 
Fields inherited from class pnuts.lang.PnutsImpl
properties
 
Fields inherited from class pnuts.lang.Runtime
BOOLEAN_SYMBOL, BYTE_SYMBOL, CHAR_SYMBOL, CLONE, DOUBLE_SYMBOL, EXCEPTOIN_FIELD_SYMBOL, FLOAT_SYMBOL, INT_SYMBOL, LONG_SYMBOL, SHORT_SYMBOL, VOID_SYMBOL
 
Constructor Summary
CachedPnutsImpl()
           
CachedPnutsImpl(boolean useCompiler)
           
CachedPnutsImpl(boolean useCompiler, boolean useDynamicProxy, boolean includeLineNo)
           
CachedPnutsImpl(boolean useCompiler, boolean useDynamicProxy, boolean includeLineNo, org.pnuts.util.Cache cache)
           
 
Method Summary
protected static org.pnuts.util.Cache createCache()
           
 java.lang.Object eval(java.lang.String script, Context context)
          Evaluate an expreesion
protected  CachedPnutsImpl.ScriptCacheEntry getCachedCode(java.lang.Object key)
           
 void includeLineNo(boolean flag)
           
 java.lang.Object load(java.net.URL scriptURL, Context context)
          Load a script file from a URL
protected  void putCachedCode(java.lang.Object key, CachedPnutsImpl.ScriptCacheEntry entry)
           
 void reset()
          Reset the cache entries
 
Methods inherited from class pnuts.lang.PnutsImpl
accept, getDefault, load, loadFile, popFile, provide, pushFile, queryProperty, revoke, setProperties, setProperty
 
Methods inherited from class pnuts.lang.Runtime
_callConstructor, _callMethod, add, add, add1, add1, addImport, addStaticMembers, and, and, applyGenerator, arraydim, arrayType, call, call, callConstructor, callFunction, callMethod, cast, catchException, checkException, checkException, compareObjects, compareTo, compareTo, createList, createMap, defineTopLevelFunction, defineUnboundFunction, divide, divide, eq, eq, escape, exec, execute, fileToURL, findCallableMethod, format, format, ge, ge, getArrayLength, getBeanProperty, getBeanProperty, getBeanProperty, getBeanPropertyType, getBeginColumn, getBeginLine, getBottomType, getCompiledScript, getConstructors, getElement, getElementAt, getEndLine, getField, getField, getFunction, getFunction, getFunctions, getMessage, getMethods, getProperty, getRange, getRuntime, getScriptReader, getScriptSource, getScriptURL, getStaticField, getThreadContext, gt, gt, isArray, isGenerator, jump, le, le, loadNode, lt, lt, makeArray, matchType, mod, mod, multiply, multiply, ne, ne, negate, negate, newInstance, not, not, or, or, parseChar, parseFloat, parseInt, parseString, primitive, printError, putField, putStaticField, quantity, replaceChar, run, saveNode, setBeanProperty, setBeanProperty, setBeanProperty, setElement, setExitHook, setLine, setLine, setPackage, setRange, setThreadContext, shiftArithmetic, shiftArithmetic, shiftLeft, shiftLeft, shiftRight, shiftRight, subtract, subtract, subtract1, subtract1, throwException, toBoolean, toEnumeration, transform, transform, unparse, xor, xor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedPnutsImpl

public CachedPnutsImpl()

CachedPnutsImpl

public CachedPnutsImpl(boolean useCompiler)
Parameters:
useCompiler - true if compiler is used (default)

CachedPnutsImpl

public CachedPnutsImpl(boolean useCompiler,
                       boolean useDynamicProxy,
                       boolean includeLineNo)
Parameters:
useCompiler - true if the compiler is used (default)
useDynamicProxy - true if the compiler generates dynamic proxy.
includeLineNo - true if the compiler generates line number information.

CachedPnutsImpl

public CachedPnutsImpl(boolean useCompiler,
                       boolean useDynamicProxy,
                       boolean includeLineNo,
                       org.pnuts.util.Cache cache)
Parameters:
useCompiler - true if the compiler is used (default)
useDynamicProxy - true if the compiler generates dynamic proxy.
includeLineNo - true if the compiler generates line number information.
cache - a cache object to reuse compiled code
Method Detail

includeLineNo

public void includeLineNo(boolean flag)

createCache

protected static org.pnuts.util.Cache createCache()

reset

public void reset()
Reset the cache entries


getCachedCode

protected CachedPnutsImpl.ScriptCacheEntry getCachedCode(java.lang.Object key)

putCachedCode

protected void putCachedCode(java.lang.Object key,
                             CachedPnutsImpl.ScriptCacheEntry entry)

load

public java.lang.Object load(java.net.URL scriptURL,
                             Context context)
Load a script file from a URL

Specified by:
load in interface Implementation
Overrides:
load in class PnutsImpl
Parameters:
scriptURL - the URL of the script
context - the context in which the script is executed
Returns:
the result of the evaluation

eval

public java.lang.Object eval(java.lang.String script,
                             Context context)
Description copied from class: PnutsImpl
Evaluate an expreesion

Specified by:
eval in interface Implementation
Overrides:
eval in class PnutsImpl
Parameters:
script - the expression to be evaluated
context - the context in which the expression is evaluated
Returns:
the result of the evaluation