org.apache.batik.script.rhino

Class RhinoInterpreter

public class RhinoInterpreter extends Object implements Interpreter

A simple implementation of Interpreter interface to use Rhino ECMAScript interpreter.
Nested Class Summary
interfaceRhinoInterpreter.ArgumentsBuilder
To build an argument list.
protected static classRhinoInterpreter.Entry
Class to store cached compiled scripts.
protected classRhinoInterpreter.Factory
Factory for Context objects.
Field Summary
static StringBIND_NAME_WINDOW
Name of the "window" object when referenced by scripts
protected ClassShutterclassShutter
Class shutter.
protected LinkedListcompiledScripts
List of cached compiled scripts.
protected ContextFactorycontextFactory
Factory object for creating Contexts.
protected static Listcontexts
Context vector, to make sure we are not setting the security context too many times
protected ContextdefaultContext
Default Context for scripts.
protected ScriptableObjectglobalObject
The global object.
protected RhinoClassLoaderrhinoClassLoader
The Rhino 'security domain'.
protected SecurityControllersecurityController
The SecurityController implementation for Batik, which ensures scripts have access to the server they were downloaded from
static StringSOURCE_NAME_SVG
Constant used to describe an SVG source
protected static String[]TO_BE_IMPORTED
Java packages that will be imported into the scripting environment.
protected Windowwindow
The window object.
protected WrapFactorywrapFactory
Factory for Java wrapper objects.
Constructor Summary
RhinoInterpreter(URL documentURL)
Build a Interpreter for ECMAScript using Rhino.
Method Summary
voidbindObject(String name, Object object)
This method registers a particular Java Object in the environment of the interpreter.
protected ScriptableObjectcreateGlobalObject(Context ctx)
Creates the global object.
protected voiddefineGlobalWrapperClass(Scriptable global)
Defines the class for the global object.
voiddispose()
For RhinoInterpreter this method flushes the Rhino caches to avoid memory leaks.
Objectevaluate(Reader scriptreader)
This method evaluates a piece of ECMAScript.
Objectevaluate(Reader scriptReader, String description)
This method evaluates a piece of ECMAScript.
Objectevaluate(String scriptStr)
This method evaluates a piece of ECMA script.
StringformatMessage(String key, Object[] args)
Creates and returns a localized message, given the key of the message, 0, data.length in the resource bundle and the message parameters.
AccessControlContextgetAccessControlContext()
Returns the AccessControlContext associated with this Interpreter.
ContextFactorygetContextFactory()
Returns the ContextFactory for this interpreter.
protected ScriptableObjectgetGlobalObject()
This method returns the ECMAScript global object used by this interpreter.
LocalegetLocale()
Returns the current locale or null if the locale currently used is the default one.
WindowgetWindow()
Returns the window object for this interpreter.
voidsetLocale(Locale locale)
Provides a way to the user to specify a locale which override the default one.
voidsetOut(Writer out)
By default Rhino has no output method in its language.

Field Detail

BIND_NAME_WINDOW

public static final String BIND_NAME_WINDOW
Name of the "window" object when referenced by scripts

classShutter

protected ClassShutter classShutter
Class shutter.

compiledScripts

protected LinkedList compiledScripts
List of cached compiled scripts.

contextFactory

protected ContextFactory contextFactory
Factory object for creating Contexts.

contexts

protected static List contexts
Context vector, to make sure we are not setting the security context too many times

defaultContext

protected Context defaultContext
Default Context for scripts. This is used only for efficiency reasons.

globalObject

protected ScriptableObject globalObject
The global object.

rhinoClassLoader

protected RhinoClassLoader rhinoClassLoader
The Rhino 'security domain'. We use the RhinoClassLoader which will grant permissions to connect to the document URL.

securityController

protected SecurityController securityController
The SecurityController implementation for Batik, which ensures scripts have access to the server they were downloaded from

SOURCE_NAME_SVG

public static final String SOURCE_NAME_SVG
Constant used to describe an SVG source

TO_BE_IMPORTED

protected static String[] TO_BE_IMPORTED
Java packages that will be imported into the scripting environment.

window

protected Window window
The window object.

wrapFactory

protected WrapFactory wrapFactory
Factory for Java wrapper objects.

Constructor Detail

RhinoInterpreter

public RhinoInterpreter(URL documentURL)
Build a Interpreter for ECMAScript using Rhino.

Parameters: documentURL the URL for the document which references

See Also: Interpreter InterpreterPool

Method Detail

bindObject

public void bindObject(String name, Object object)
This method registers a particular Java Object in the environment of the interpreter.

Parameters: name the name of the script object to create object the Java object

createGlobalObject

protected ScriptableObject createGlobalObject(Context ctx)
Creates the global object.

defineGlobalWrapperClass

protected void defineGlobalWrapperClass(Scriptable global)
Defines the class for the global object.

dispose

public void dispose()
For RhinoInterpreter this method flushes the Rhino caches to avoid memory leaks.

evaluate

public Object evaluate(Reader scriptreader)
This method evaluates a piece of ECMAScript.

Parameters: scriptreader a java.io.Reader on the piece of script

Returns: if no exception is thrown during the call, should return the value of the last expression evaluated in the script.

evaluate

public Object evaluate(Reader scriptReader, String description)
This method evaluates a piece of ECMAScript.

Parameters: scriptReader a java.io.Reader on the piece of script description description which can be later used (e.g., for error messages).

Returns: if no exception is thrown during the call, should return the value of the last expression evaluated in the script.

evaluate

public Object evaluate(String scriptStr)
This method evaluates a piece of ECMA script. The first time a String is passed, it is compiled and evaluated. At next call, the piece of script will only be evaluated to prevent from recompiling it.

Parameters: scriptStr the piece of script

Returns: if no exception is thrown during the call, should return the value of the last expression evaluated in the script.

formatMessage

public String formatMessage(String key, Object[] args)
Creates and returns a localized message, given the key of the message, 0, data.length in the resource bundle and the message parameters. The messages in the resource bundle must have the syntax described in the java.text.MessageFormat class documentation.

Parameters: key The key used to retreive the message from the resource bundle. args The objects that compose the message.

Throws: MissingResourceException if the key is not in the bundle.

getAccessControlContext

public AccessControlContext getAccessControlContext()
Returns the AccessControlContext associated with this Interpreter.

See Also: RhinoClassLoader

getContextFactory

public ContextFactory getContextFactory()
Returns the ContextFactory for this interpreter.

getGlobalObject

protected ScriptableObject getGlobalObject()
This method returns the ECMAScript global object used by this interpreter.

getLocale

public Locale getLocale()
Returns the current locale or null if the locale currently used is the default one.

getWindow

public Window getWindow()
Returns the window object for this interpreter.

setLocale

public void setLocale(Locale locale)
Provides a way to the user to specify a locale which override the default one. If null is passed to this method, the used locale becomes the global one.

Parameters: locale The locale to set.

setOut

public void setOut(Writer out)
By default Rhino has no output method in its language. That's why this method does nothing.

Parameters: out the new out Writer.

Copyright B) 2007 Apache Software Foundation. All Rights Reserved.