Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.batik.script.rhino
Class RhinoInterpreter  view RhinoInterpreter download RhinoInterpreter.java

java.lang.Object
  extended byorg.apache.batik.script.rhino.RhinoInterpreter
All Implemented Interfaces:
org.apache.batik.script.Interpreter, org.apache.batik.i18n.Localizable

public class RhinoInterpreter
extends java.lang.Object
implements org.apache.batik.script.Interpreter

A simple implementation of Interpreter interface to use Rhino ECMAScript interpreter.

Version:
$Id: RhinoInterpreter.java,v 1.41 2005/03/29 10:48:02 deweese Exp $

Nested Class Summary
static interface RhinoInterpreter.ArgumentsBuilder
          To build an argument list.
private static class RhinoInterpreter.Entry
           
 class RhinoInterpreter.ExtendedContext
           
static class RhinoInterpreter.RhinoGetDelegate
          Class to act as 'get' delegate for Rhino.
 
Field Summary
static java.lang.String BIND_NAME_WINDOW
          Name of the "window" object when referenced by scripts
private  java.util.LinkedList compiledScripts
           
private  ScriptableObject globalObject
           
private static int MAX_CACHED_SCRIPTS
          store last 32 precompiled objects.
(package private)  java.util.Map objects
          HashTable to store properties bounds on the global object.
protected  RhinoClassLoader rhinoClassLoader
          The Rhino 'security domain'.
(package private) static java.lang.reflect.Method rhinoGetter
           
private  SecurityController securityController
          The SecurityController implementation for Batik, which ensures scripts have access to the server they were downloaded from
static java.lang.String SOURCE_NAME_SVG
          Constant used to describe an SVG source
private static java.lang.String[] TO_BE_IMPORTED
           
protected  org.apache.batik.script.Window window
          The window object
private  WrapFactory wrapFactory
           
 
Constructor Summary
RhinoInterpreter(java.net.URL documentURL)
          Build a Interpreter for ECMAScript using Rhino.
 
Method Summary
 void bindObject(java.lang.String name, java.lang.Object object)
          This method registers a particular Java Object in the environment of the interpreter.
(package private)  Scriptable buildEventTargetWrapper(org.w3c.dom.events.EventTarget obj)
          Build the wrapper for objects implement EventTarget.
(package private)  void callHandler(Function handler, java.lang.Object arg)
          To be used by EventTargetWrapper.
(package private)  void callHandler(Function handler, java.lang.Object[] args)
          To be used by WindowWrapper.
(package private)  void callHandler(Function handler, RhinoInterpreter.ArgumentsBuilder ab)
          To be used by WindowWrapper.
(package private)  void callMethod(ScriptableObject obj, java.lang.String methodName, RhinoInterpreter.ArgumentsBuilder ab)
          To be used by WindowWrapper.
 void dispose()
          For RhinoInterpreter this method flushes the Rhino caches to avoid memory leaks.
 Context enterContext()
          Implementation helper.
 java.lang.Object evaluate(java.io.Reader scriptreader)
          This method evaluates a piece of ECMAScript.
 java.lang.Object evaluate(java.io.Reader scriptreader, java.lang.String description)
          This method evaluates a piece of ECMAScript.
 java.lang.Object evaluate(java.lang.String scriptstr)
          This method evaluates a piece of ECMA script.
 java.lang.String formatMessage(java.lang.String key, java.lang.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.
 java.security.AccessControlContext getAccessControlContext()
          Returns the AccessControlContext associated with this Interpreter.
protected  ScriptableObject getGlobalObject()
          This method returns the ECMAScript global object used by this interpreter.
 java.util.Locale getLocale()
          Returns the current locale or null if the locale currently used is the default one.
 org.apache.batik.script.Window getWindow()
           
 void setLocale(java.util.Locale locale)
          Provides a way to the user to specify a locale which override the default one.
 void setOut(java.io.Writer out)
          By default Rhino has no output method in its language.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TO_BE_IMPORTED

private static java.lang.String[] TO_BE_IMPORTED

window

protected org.apache.batik.script.Window window
The window object


MAX_CACHED_SCRIPTS

private static final int MAX_CACHED_SCRIPTS
store last 32 precompiled objects.

See Also:
Constant Field Values

SOURCE_NAME_SVG

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

See Also:
Constant Field Values

BIND_NAME_WINDOW

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

See Also:
Constant Field Values

globalObject

private ScriptableObject globalObject

compiledScripts

private java.util.LinkedList compiledScripts

wrapFactory

private WrapFactory wrapFactory

rhinoClassLoader

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


securityController

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


objects

java.util.Map objects
HashTable to store properties bounds on the global object. So they don't end up in the JavaMethods static table.


rhinoGetter

static java.lang.reflect.Method rhinoGetter
Constructor Detail

RhinoInterpreter

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

Method Detail

getWindow

public org.apache.batik.script.Window getWindow()

getAccessControlContext

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


enterContext

public Context enterContext()
Implementation helper. Makes sure the proper security is set on the context.


getGlobalObject

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


evaluate

public java.lang.Object evaluate(java.io.Reader scriptreader)
                          throws org.apache.batik.script.InterpreterException,
                                 java.io.IOException
This method evaluates a piece of ECMAScript.

Specified by:
evaluate in interface org.apache.batik.script.Interpreter

evaluate

public java.lang.Object evaluate(java.io.Reader scriptreader,
                                 java.lang.String description)
                          throws org.apache.batik.script.InterpreterException,
                                 java.io.IOException
This method evaluates a piece of ECMAScript.

Specified by:
evaluate in interface org.apache.batik.script.Interpreter

evaluate

public java.lang.Object evaluate(java.lang.String scriptstr)
                          throws org.apache.batik.script.InterpreterException
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.

Specified by:
evaluate in interface org.apache.batik.script.Interpreter

dispose

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

Specified by:
dispose in interface org.apache.batik.script.Interpreter

bindObject

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

Specified by:
bindObject in interface org.apache.batik.script.Interpreter

callHandler

void callHandler(Function handler,
                 java.lang.Object arg)
           throws JavaScriptException
To be used by EventTargetWrapper.


callMethod

void callMethod(ScriptableObject obj,
                java.lang.String methodName,
                RhinoInterpreter.ArgumentsBuilder ab)
          throws JavaScriptException
To be used by WindowWrapper.


callHandler

void callHandler(Function handler,
                 java.lang.Object[] args)
           throws JavaScriptException
To be used by WindowWrapper.


callHandler

void callHandler(Function handler,
                 RhinoInterpreter.ArgumentsBuilder ab)
           throws JavaScriptException
To be used by WindowWrapper.


buildEventTargetWrapper

Scriptable buildEventTargetWrapper(org.w3c.dom.events.EventTarget obj)
Build the wrapper for objects implement EventTarget.


setOut

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

Specified by:
setOut in interface org.apache.batik.script.Interpreter

getLocale

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

Specified by:
getLocale in interface org.apache.batik.i18n.Localizable

setLocale

public void setLocale(java.util.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.

Specified by:
setLocale in interface org.apache.batik.i18n.Localizable

formatMessage

public java.lang.String formatMessage(java.lang.String key,
                                      java.lang.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.

Specified by:
formatMessage in interface org.apache.batik.i18n.Localizable