You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by ca...@apache.org on 2008/10/03 07:12:02 UTC

svn commit: r701300 - in /xmlgraphics/batik/trunk/sources/org/apache/batik: bridge/ScriptingEnvironment.java script/rhino/RhinoClassShutter.java

Author: cam
Date: Thu Oct  2 22:12:02 2008
New Revision: 701300

URL: http://svn.apache.org/viewvc?rev=701300&view=rev
Log:
Fix Rhino class shutter issues with setTimeout() and setInterval() when
using Rhino 1.6R7 or later.

Modified:
    xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/ScriptingEnvironment.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/RhinoClassShutter.java

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/ScriptingEnvironment.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/ScriptingEnvironment.java?rev=701300&r1=701299&r2=701300&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/ScriptingEnvironment.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/ScriptingEnvironment.java Thu Oct  2 22:12:02 2008
@@ -728,6 +728,7 @@
             interpreter = interp;
             script = s;
         }
+
         public void run() {
             synchronized (this) {
                 if (error)
@@ -769,6 +770,7 @@
         public EvaluateRunnableRunnable(Runnable r) {
             runnable = r;
         }
+
         public void run() {
             synchronized (this) {
                 if (error)
@@ -796,6 +798,111 @@
     protected class Window implements org.apache.batik.script.Window {
 
         /**
+         * A <code>TimerTask</code> to invoke a
+         * <code>setInterval()</code>-scheduled function that is specified
+         * by a String.
+         */
+        protected class IntervalScriptTimerTask extends TimerTask {
+
+            protected EvaluateIntervalRunnable eir;
+
+            public IntervalScriptTimerTask(String script) {
+                eir = new EvaluateIntervalRunnable(script, interpreter);
+            }
+
+            public void run() {
+                synchronized (eir) {
+                    if (eir.count > 1)
+                        return;
+                    eir.count++;
+                }
+                synchronized (updateRunnableQueue.getIteratorLock()) {
+                    if (updateRunnableQueue.getThread() == null) {
+                        cancel();
+                        return;
+                    }
+                    updateRunnableQueue.invokeLater(eir);
+                }
+                synchronized (eir) {
+                    if (eir.error)
+                        cancel();
+                }
+            }
+        }
+
+        /**
+         * A <code>TimerTask</code> to invoke a
+         * <code>setInterval()</code>-scheduled function that is specified
+         * by a <code>Runnable</code>.
+         */
+        protected class IntervalRunnableTimerTask extends TimerTask {
+
+            protected EvaluateRunnableRunnable eihr;
+
+            public IntervalRunnableTimerTask(Runnable r) {
+                eihr = new EvaluateRunnableRunnable(r);
+            }
+
+            public void run() {
+                synchronized (eihr) {
+                    if (eihr.count > 1)
+                        return;
+                    eihr.count++;
+                }
+                updateRunnableQueue.invokeLater(eihr);
+                synchronized (eihr) {
+                    if (eihr.error)
+                        cancel();
+                }
+            }
+        }
+
+        /**
+         * A <code>TimerTask</code> to invoke a
+         * <code>setTimeout()</code>-scheduled function that is specified
+         * by a String.
+         */
+        protected class TimeoutScriptTimerTask extends TimerTask {
+            private String script;
+
+            public TimeoutScriptTimerTask(String script) {
+                this.script = script;
+            }
+
+            public void run() {
+                updateRunnableQueue.invokeLater
+                    (new EvaluateRunnable(script, interpreter));
+            }
+        }
+
+        /**
+         * A <code>TimerTask</code> to invoke a
+         * <code>setTimeout()</code>-scheduled function that is specified
+         * by a Runnable.
+         */
+        protected class TimeoutRunnableTimerTask extends TimerTask {
+            private Runnable r;
+
+            public TimeoutRunnableTimerTask(Runnable r) {
+                this.r = r;
+            }
+
+            public void run() {
+                updateRunnableQueue.invokeLater(new Runnable() {
+                        public void run() {
+                            try {
+                                r.run();
+                            } catch (Exception e) {
+                                if (userAgent != null) {
+                                    userAgent.displayError(e);
+                                }
+                            }
+                        }
+                    });
+            }
+        }
+
+        /**
          * The associated interpreter.
          */
         protected Interpreter interpreter;
@@ -818,29 +925,7 @@
          * org.apache.batik.script.Window#setInterval(String,long)}.
          */
         public Object setInterval(final String script, long interval) {
-            TimerTask tt = new TimerTask() {
-                    EvaluateIntervalRunnable eir =
-                        new EvaluateIntervalRunnable(script, interpreter);
-                    public void run() {
-                        synchronized (eir) {
-                            if (eir.count > 1)
-                                return;
-                            eir.count++;
-                        }
-                        synchronized (updateRunnableQueue.getIteratorLock()) {
-                            if (updateRunnableQueue.getThread() == null) {
-                                cancel();
-                                return;
-                            }
-                            updateRunnableQueue.invokeLater(eir);
-                        }
-                        synchronized (eir) {
-                            if (eir.error)
-                                cancel();
-                        }
-                    }
-                };
-
+            IntervalScriptTimerTask tt = new IntervalScriptTimerTask(script);
             timer.schedule(tt, interval, interval);
             return tt;
         }
@@ -850,23 +935,7 @@
          * org.apache.batik.script.Window#setInterval(Runnable,long)}.
          */
         public Object setInterval(final Runnable r, long interval) {
-            TimerTask tt = new TimerTask() {
-                    EvaluateRunnableRunnable eihr =
-                        new EvaluateRunnableRunnable(r);
-                    public void run() {
-                        synchronized (eihr) {
-                            if (eihr.count > 1)
-                                return;
-                            eihr.count++;
-                        }
-                        updateRunnableQueue.invokeLater(eihr);
-                        synchronized (eihr) {
-                            if (eihr.error)
-                                cancel();
-                        }
-                    }
-                };
-
+            IntervalRunnableTimerTask tt = new IntervalRunnableTimerTask(r);
             timer.schedule(tt, interval, interval);
             return tt;
         }
@@ -885,13 +954,7 @@
          * org.apache.batik.script.Window#setTimeout(String,long)}.
          */
         public Object setTimeout(final String script, long timeout) {
-            TimerTask tt = new TimerTask() {
-                    public void run() {
-                        updateRunnableQueue.invokeLater
-                            (new EvaluateRunnable(script, interpreter));
-                    }
-                };
-
+            TimeoutScriptTimerTask tt = new TimeoutScriptTimerTask(script);
             timer.schedule(tt, timeout);
             return tt;
         }
@@ -901,22 +964,7 @@
          * org.apache.batik.script.Window#setTimeout(Runnable,long)}.
          */
         public Object setTimeout(final Runnable r, long timeout) {
-            TimerTask tt = new TimerTask() {
-                    public void run() {
-                        updateRunnableQueue.invokeLater(new Runnable() {
-                                public void run() {
-                                    try {
-                                        r.run();
-                                    } catch (Exception e) {
-                                        if (userAgent != null) {
-                                            userAgent.displayError(e);
-                                        }
-                                    }
-                                }
-                            });
-                    }
-                };
-
+            TimeoutRunnableTimerTask tt = new TimeoutRunnableTimerTask(r);
             timer.schedule(tt, timeout);
             return tt;
         }

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/RhinoClassShutter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/RhinoClassShutter.java?rev=701300&r1=701299&r2=701300&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/RhinoClassShutter.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/script/rhino/RhinoClassShutter.java Thu Oct  2 22:12:02 2008
@@ -27,7 +27,7 @@
  * @version $Id$
  */
 public class RhinoClassShutter implements ClassShutter {
-    
+
     /*
     public RhinoClassShutter() {
         // I suspect that we might want to initialize this
@@ -46,7 +46,7 @@
         test("org.apache.batik.bridge.ScriptingEnvironment");
     }
     public void test(String cls) {
-        System.err.println("Test '" + cls + "': " + 
+        System.err.println("Test '" + cls + "': " +
                            visibleToScripts(cls));
     }
     */
@@ -60,7 +60,7 @@
             return false;
 
         if (fullClassName.startsWith("org.apache.batik.")) {
-            // Just get packge within batik.
+            // Just get package within batik.
             String batikPkg = fullClassName.substring(17);
 
             // Don't let them mess with Batik script internals.
@@ -71,13 +71,33 @@
             if (batikPkg.startsWith("apps"))
                 return false;
 
-            // Don't let them get Scripting stuff from bridge.
+            // Don't let them get scripting stuff from bridge, but specifically
+            // allow access to:
+            //
+            //   o.a.b.bridge.ScriptingEnvironment$Window$IntervalScriptTimerTask
+            //   o.a.b.bridge.ScriptingEnvironment$Window$IntervalRunnableTimerTask
+            //   o.a.b.bridge.ScriptingEnvironment$Window$TimeoutScriptTimerTask
+            //   o.a.b.bridge.ScriptingEnvironment$Window$TimeoutRunnableTimerTask
+            //
+            // since objects of these classes are returned by setInterval() and
+            // setTimeout().
             if (batikPkg.startsWith("bridge.")) {
-                
-                if (batikPkg.indexOf(".BaseScriptingEnvironment")!=-1)
+                String batikBridgeClass = batikPkg.substring(7);
+                if (batikBridgeClass.startsWith("ScriptingEnvironment")) {
+                    if (batikBridgeClass.startsWith("$Window$", 20)) {
+                        String c = batikBridgeClass.substring(28);
+                        if (c.equals("IntervalScriptTimerTask")
+                                || c.equals("IntervalRunnableTimerTask")
+                                || c.equals("TimeoutScriptTimerTask")
+                                || c.equals("TimeoutRunnableTimerTask")) {
+                            return true;
+                        }
+                    }
                     return false;
-                if (batikPkg.indexOf(".ScriptingEnvironment")!=-1)
+                }
+                if (batikBridgeClass.startsWith("BaseScriptingEnvironment")) {
                     return false;
+                }
             }
         }