You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by cj...@apache.org on 2001/04/17 16:57:03 UTC

cvs commit: xml-batik/sources/org/apache/batik/script/rhino RhinoInterpreter.java

cjolif      01/04/17 07:57:03

  Modified:    sources/org/apache/batik/script/rhino RhinoInterpreter.java
  Log:
  give access to some internals to subclasses
  
  Revision  Changes    Path
  1.5       +27 -12    xml-batik/sources/org/apache/batik/script/rhino/RhinoInterpreter.java
  
  Index: RhinoInterpreter.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/script/rhino/RhinoInterpreter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RhinoInterpreter.java	2001/03/19 11:10:43	1.4
  +++ RhinoInterpreter.java	2001/04/17 14:56:59	1.5
  @@ -24,18 +24,16 @@
   import org.mozilla.javascript.Function;
   import org.mozilla.javascript.NativeJavaPackage;
   import org.mozilla.javascript.Scriptable;
  +import org.mozilla.javascript.ScriptableObject;
   import org.mozilla.javascript.WrappedException;
   
   /**
    * A simple implementation of <code>Interpreter</code> interface to use
    * Rhino ECMAScript interpreter.
    * @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
  - * @version $Id: RhinoInterpreter.java,v 1.4 2001/03/19 11:10:43 cjolif Exp $
  + * @version $Id: RhinoInterpreter.java,v 1.5 2001/04/17 14:56:59 cjolif Exp $
    */
   public class RhinoInterpreter implements Interpreter {
  -    private Scriptable scope = null;
  -    private Context context = null;
  -
       private static String[] TO_BE_IMPORTED = {
           "java.lang",
           "org.w3c.dom",
  @@ -47,6 +45,9 @@
           "org.w3c.dom.views"
       };
   
  +    private Context context = null;
  +    private ScriptableObject globalObject = null;
  +
       /**
        * Build a <code>Interpreter</code> for ECMAScript using Rhino.
        * @see org.apache.batik.script.Interpreter
  @@ -58,19 +59,33 @@
           try {
               // init std object with an importer
               ImporterTopLevel importer = new ImporterTopLevel();
  -            scope = context.initStandardObjects(importer);
  +            globalObject = (ScriptableObject)context.initStandardObjects(importer);
               // import Java lang package & DOM Level 2 & SVG DOM packages
               NativeJavaPackage[] p= new NativeJavaPackage[TO_BE_IMPORTED.length];
               for (int i = 0; i < TO_BE_IMPORTED.length; i++) {
                   p[i] = new NativeJavaPackage(TO_BE_IMPORTED[i]);
               }
  -            importer.importPackage(context, scope, p, null);
  +            importer.importPackage(context, globalObject, p, null);
               context.setWrapHandler(new EventTargetWrapHandler(this));
           } finally {
               Context.exit();
           }
       }
   
  +    /**
  +     * This method returns the ECMAScript global object used by this interpreter.
  +     */
  +    protected ScriptableObject getGlobalObject() {
  +        return globalObject;
  +    }
  +
  +    /**
  +     * This method returns the default context in which the interpreter runs.
  +     */
  +    protected Context getContext() {
  +        return context;
  +    }
  +
       // org.apache.batik.script.Intepreter implementation
   
       /**
  @@ -84,7 +99,7 @@
           Object rv = null;
           Context ctx = Context.enter(context);
           try {
  -            rv = ctx.evaluateReader(scope,
  +            rv = ctx.evaluateReader(globalObject,
                                       scriptreader,
                                       "<SVG>",
                                       1, null);
  @@ -123,8 +138,8 @@
        * @param object the Java object
        */
       public void bindObject(String name, Object object) {
  -        Scriptable jsObject =  Context.toObject(object, scope);
  -        scope.put(name, scope, jsObject);
  +        Scriptable jsObject =  Context.toObject(object, globalObject);
  +        globalObject.put(name, globalObject, jsObject);
       }
   
       /**
  @@ -135,9 +150,9 @@
           throws JavaScriptException {
           Context ctx = Context.enter(context);
           try {
  -            arg = Context.toObject(arg, scope);
  +            arg = Context.toObject(arg, globalObject);
               Object[] args = {arg};
  -            handler.call(ctx, scope, scope, args);
  +            handler.call(ctx, globalObject, globalObject, args);
           } finally {
               Context.exit();
           }
  @@ -147,7 +162,7 @@
        * Build the wrapper for objects implement <code>EventTarget</code>.
        */
       Scriptable buildEventTargetWrapper(EventTarget obj) {
  -        return new EventTargetWrapper(scope, obj, this);
  +        return new EventTargetWrapper(globalObject, obj, this);
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org