deweese     2003/07/10 05:01:21

  Modified:    sources/org/apache/batik/bridge BridgeContext.java
               sources/org/apache/batik/gvt/event AWTEventDispatcher.java
               sources/org/apache/batik/script/rhino RhinoInterpreter.java
               sources/org/apache/batik/swing/svg JSVGComponent.java
               test-resources/org/apache/batik/swing unitTesting.xml
               test-sources/org/apache/batik/swing JSVGInterruptTest.java
  Log:
  1) Fixed a memory leak when scripts reference elements globally.
  2) Improved event queuing in AWTEventDispatcher.
  3) Interperters now have dispose called when BridgeContext is disposed of.
  4) removeNotify on JSVGComponent now clears document.
  
  Revision  Changes    Path
  1.68      +8 -1      xml-batik/sources/org/apache/batik/bridge/BridgeContext.java
  
  Index: BridgeContext.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeContext.java,v
  retrieving revision 1.67
  retrieving revision 1.68
  diff -u -r1.67 -r1.68
  --- BridgeContext.java        10 Jul 2003 02:01:26 -0000      1.67
  +++ BridgeContext.java        10 Jul 2003 12:01:18 -0000      1.68
  @@ -994,6 +994,13 @@
                   svgDocument.setCSSEngine(null);
               }
           }
  +        Iterator iter = interpreterMap.values().iterator();
  +        while (iter.hasNext()) {
  +            Interpreter interpreter = (Interpreter)iter.next();
  +            interpreter.dispose();
  +        }
  +        interpreterMap.clear();
  +
           if (focusManager != null) {
               focusManager.dispose();
           }
  
  
  
  1.16      +28 -4     
xml-batik/sources/org/apache/batik/gvt/event/AWTEventDispatcher.java
  
  Index: AWTEventDispatcher.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/gvt/event/AWTEventDispatcher.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- AWTEventDispatcher.java   10 Jul 2003 02:01:26 -0000      1.15
  +++ AWTEventDispatcher.java   10 Jul 2003 12:01:18 -0000      1.16
  @@ -82,8 +82,13 @@
        * These are used to queue events while a rendering event
        * is in progress.
        */
  -    protected List eventQueue = new LinkedList();
  +    protected List    eventQueue = new LinkedList();
       protected boolean eventDispatchEnabled = true;
  +    protected int     eventQueueMaxSize = MAX_QUEUE_SIZE;
  +    /**
  +     * default max size of the event queue.
  +     */
  +    final static int MAX_QUEUE_SIZE = 10;
   
       private int nodeIncrementEventID = KeyEvent.KEY_PRESSED;
       private int nodeIncrementEventCode = KeyEvent.VK_TAB;
  @@ -104,6 +109,8 @@
        * @param root the root node
        */
       public void setRootNode(GraphicsNode root) {
  +        if (this.root != root)
  +            eventQueue.clear(); // new root so clear 'old' events.
           this.root = root;
       }
   
  @@ -121,6 +128,11 @@
        * @param t the affine transform
        */
       public void setBaseTransform(AffineTransform t) {
  +        if ((baseTransform != t) &&
  +            ((baseTransform == null) || (!baseTransform.equals(t))))
  +            // new Display transform so events are not where user
  +            // thinks they were.
  +            eventQueue.clear(); 
           baseTransform = t;
       }
   
  @@ -309,16 +321,28 @@
               }
           }
       }
  +    public void setEventQueueMaxSize(int n) {
  +        eventQueueMaxSize = n;
  +        if (n == 0) eventQueue.clear();
  +        while(eventQueue.size() > eventQueueMaxSize)
  +            eventQueue.remove(0);
  +    }
   
       /**
        * Dispatches the specified AWT event.
        * @param evt the event to dispatch
        */
       public void dispatchEvent(EventObject evt) {
  -        if (root == null) 
  +        if (root == null) // No root do not store anything.
               return;
           if (!eventDispatchEnabled) {
  -            eventQueue.add(evt);
  +            if (eventQueueMaxSize > 0) {
  +                eventQueue.add(evt);
  +                while (eventQueue.size() > eventQueueMaxSize)
  +                    // Limit how many events we queue - don't want
  +                    // user waiting forever for them to clear.
  +                    eventQueue.remove(0); 
  +            }
               return;
           }
           if (evt instanceof MouseEvent) {
  
  
  
  1.30      +75 -73    
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.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- RhinoInterpreter.java     10 Jul 2003 02:01:26 -0000      1.29
  +++ RhinoInterpreter.java     10 Jul 2003 12:01:20 -0000      1.30
  @@ -212,7 +212,6 @@
   
           Object rv = null;
           final Context ctx = enterContext();
  -
           try {
               rv = ctx.evaluateReader(globalObject,
                                       scriptreader,
  @@ -258,75 +257,80 @@
        */
       public Object evaluate(final String scriptstr)
           throws InterpreterException {
  -
  +        Object rv = null;
           final Context ctx = enterContext();
  +        try {
  +            Script script = null;
  +            Entry et = null;
  +            Iterator it = compiledScripts.iterator();
  +            // between nlog(n) and log(n) because it is
  +            // an AbstractSequentialList
  +            while (it.hasNext()) {
  +                if ((et = (Entry)(it.next())).str.equals(scriptstr)) {
  +                    // if it is not at the end, remove it because
  +                    // it will change from place (it is faster
  +                    // to remove it now)
  +                    script = et.script;
  +                    it.remove();
  +                    break;
  +                }
  +            }
   
  -        Script script = null;
  -        Entry et = null;
  -        Iterator it = compiledScripts.iterator();
  -        // between nlog(n) and log(n) because it is
  -        // an AbstractSequentialList
  -        while (it.hasNext()) {
  -            if ((et = (Entry)(it.next())).str.equals(scriptstr)) {
  -                // if it is not at the end, remove it because
  -                // it will change from place (it is faster
  -                // to remove it now)
  -                script = et.script;
  -                it.remove();
  -                break;
  +            if (script == null) {
  +                // this script has not been compiled yet or has been forgotten
  +                // since the compilation:
  +                // compile it and store it for future use.
  +
  +                script = (Script)AccessController.doPrivileged
  +                    (new PrivilegedAction() {
  +                            public Object run() {
  +                                try {
  +                                    return ctx.compileReader
  +                                        (globalObject, 
  +                                         new StringReader(scriptstr),
  +                                         SOURCE_NAME_SVG,
  +                                         1, rhinoClassLoader);
  +                                } catch (IOException io) {
  +                                    // Should never happen: using a string
  +                                    throw new Error();
  +                                }
  +                            }
  +                        });
  +
  +                if (compiledScripts.size()+1 > MAX_CACHED_SCRIPTS) {
  +                    // too many cached items - we should delete the
  +                    // oldest entry.  all of this is very fast on
  +                    // linkedlist
  +                    compiledScripts.removeFirst();
  +                }
  +                // stroring is done here:
  +                compiledScripts.addLast(new Entry(scriptstr, script));
  +            } else {
  +                // this script has been compiled before,
  +                // just update it's index so it won't get deleted soon.
  +                compiledScripts.addLast(et);
               }
  -        }
   
  -        if (script == null) {
  -            // this script has not been compiled yet or has been forgotten
  -            // since the compilation:
  -            // compile it and store it for future use.
  -
  -            script = (Script)AccessController.doPrivileged(new PrivilegedAction() {
  -                    public Object run() {
  -                        try {
  -                            return ctx.compileReader(globalObject,
  -                                                     new StringReader(scriptstr),
  -                                                     SOURCE_NAME_SVG,
  -                                                     1, rhinoClassLoader);
  -                        } catch (IOException io) {
  -                            // Should never happen: we are using a string
  -                            throw new Error();
  -                        }
  -                    }
  -                });
  -
  -            if (compiledScripts.size()+1 > MAX_CACHED_SCRIPTS) {
  -                // too many cached items - we should delete the oldest entry.
  -                // all of this is very fast on linkedlist
  -                compiledScripts.removeFirst();
  +            try {
  +                rv = script.exec(ctx, globalObject);
  +            } catch (JavaScriptException e) {
  +                // exception from JavaScript (possibly wrapping a Java Ex)
  +                if (e.getValue() instanceof Exception) {
  +                    Exception ex = (Exception)e.getValue();
  +                    throw new InterpreterException(ex, ex.getMessage(), -1,-1);
  +                } else
  +                    throw new InterpreterException(e, e.getMessage(), -1, -1);
  +            } catch (WrappedException we) {
  +                // main Rhino RuntimeException
  +                throw
  +                    new InterpreterException
  +                    ((Exception)we.getWrappedException(),
  +                     we.getWrappedException().getMessage(), -1, -1);
  +            } catch (RuntimeException re) {
  +                // other RuntimeExceptions
  +                throw new InterpreterException(re, re.getMessage(), -1, -1);
               }
  -            // stroring is done here:
  -            compiledScripts.addLast(new Entry(scriptstr, script));
  -        } else {
  -            // this script has been compiled before,
  -            // just update it's index so it won't get deleted soon.
  -            compiledScripts.addLast(et);
  -        }
  -        Object rv = null;
  -        try {
  -            rv = script.exec(ctx, globalObject);
  -        } catch (JavaScriptException e) {
  -            // exception from JavaScript (possibly wrapping a Java Ex)
  -            if (e.getValue() instanceof Exception) {
  -                Exception ex = (Exception)e.getValue();
  -                throw new InterpreterException(ex, ex.getMessage(), -1, -1);
  -            } else
  -                throw new InterpreterException(e, e.getMessage(), -1, -1);
  -        } catch (WrappedException we) {
  -            // main Rhino RuntimeException
  -            throw
  -                new InterpreterException((Exception)we.getWrappedException(),
  -                                         we.getWrappedException().getMessage(),
  -                                         -1, -1);
  -        } catch (RuntimeException re) {
  -            // other RuntimeExceptions
  -            throw new InterpreterException(re, re.getMessage(), -1, -1);
  +        
           } finally {
               Context.exit();
           }
  @@ -337,6 +341,8 @@
        * For <code>RhinoInterpreter</code> this method does nothing.
        */
       public void dispose() {
  +        Context.setCachingEnabled(false);
  +        Context.setCachingEnabled(true);
       }
   
       /**
  @@ -347,7 +353,7 @@
        */
       public void bindObject(String name, Object object) {
           Context ctx = enterContext();
  -
  +        
           try {
               if (name.equals(BIND_NAME_WINDOW) && object instanceof Window) {
                   window = (Window)object;
  @@ -413,7 +419,6 @@
                        Object arg)
           throws JavaScriptException {
           Context ctx = enterContext();
  -
           try {
               arg = Context.toObject(arg, globalObject);
               Object[] args = {arg};
  @@ -431,7 +436,6 @@
                       ArgumentsBuilder ab)
           throws JavaScriptException {
           Context ctx = enterContext();
  -
           try {
               ScriptableObject.callMethod(obj, methodName, ab.buildArguments());
           } finally {
  @@ -446,7 +450,6 @@
                        Object[] args)
           throws JavaScriptException {
           Context ctx = enterContext();
  -
           try {
               handler.call(ctx, globalObject, globalObject, args);
           } finally {
  @@ -460,10 +463,9 @@
       void callHandler(Function handler,
                        ArgumentsBuilder ab)
           throws JavaScriptException {
  -        Context ctx = enterContext();
  -
  +        Context ctx = enterContext(); 
           try {
  -            handler.call(ctx, globalObject, globalObject, ab.buildArguments());
  +           handler.call(ctx, globalObject, globalObject, ab.buildArguments());
           } finally {
               Context.exit();
           }
  
  
  
  1.75      +6 -1      xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java
  
  Index: JSVGComponent.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java,v
  retrieving revision 1.74
  retrieving revision 1.75
  diff -u -r1.74 -r1.75
  --- JSVGComponent.java        10 Jul 2003 02:01:27 -0000      1.74
  +++ JSVGComponent.java        10 Jul 2003 12:01:20 -0000      1.75
  @@ -341,6 +341,11 @@
           addSVGLoadEventDispatcherListener((SVGListener)listener);
       }
   
  +    public void removeNotify() {
  +        setSVGDocument(null);
  +        super.removeNotify();
  +    }
  +
       /**
        * Tells whether the component use dynamic features to
        * process the current document.
  
  
  
  1.6       +3 -2      xml-batik/test-resources/org/apache/batik/swing/unitTesting.xml
  
  Index: unitTesting.xml
  ===================================================================
  RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/swing/unitTesting.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- unitTesting.xml   10 Jul 2003 02:01:27 -0000      1.5
  +++ unitTesting.xml   10 Jul 2003 12:01:21 -0000      1.6
  @@ -30,6 +30,7 @@
     <testGroup id="swing.interrupt" 
                class="org.apache.batik.swing.JSVGInterruptTest">
       <test id="samples/anne.svg" />
  -<!--    <test id="samples/mines.svg" /> -->
  +    <test id="samples/sydney.svg" />
  +    <test id="samples/mines.svg" />
     </testGroup>
   </testSuite>
  
  
  
  1.2       +2 -2      
xml-batik/test-sources/org/apache/batik/swing/JSVGInterruptTest.java
  
  Index: JSVGInterruptTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/test-sources/org/apache/batik/swing/JSVGInterruptTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JSVGInterruptTest.java    10 Jul 2003 02:01:27 -0000      1.1
  +++ JSVGInterruptTest.java    10 Jul 2003 12:01:21 -0000      1.2
  @@ -55,7 +55,7 @@
       final static int COMPLETE  = 1;
       final static int CANCELLED = 2;
       final static int FAILED    = 4;
  -    final static int MAX_WAIT  = 20000;
  +    final static int MAX_WAIT  = 40000;
   
       public JSVGCanvasHandler createHandler() {
           return new JSVGCanvasHandler(this, this) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to