cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r643294 - in /cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow: WebContinuation.java javascript/fom/FOM_Cocoon.java javascript/fom/FOM_JavaScriptInterpreter.java javascript/fom/FOM_WebContinuation.java
Date Tue, 01 Apr 2008 06:20:55 GMT
Author: joerg
Date: Mon Mar 31 23:20:52 2008
New Revision: 643294

URL: http://svn.apache.org/viewvc?rev=643294&view=rev
Log:
remove LogEnabled from WebContinuation, change display() to toString(), logging is done "externally"

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/WebContinuation.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/WebContinuation.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/WebContinuation.java?rev=643294&r1=643293&r2=643294&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/WebContinuation.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/WebContinuation.java
Mon Mar 31 23:20:52 2008
@@ -20,10 +20,10 @@
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.commons.collections.iterators.IteratorEnumeration;
 import org.apache.commons.lang.StringUtils;
 
@@ -43,8 +43,7 @@
  * @since March 19, 2002
  * @version CVS $Id$
  */
-public class WebContinuation extends AbstractLogEnabled
-                             implements Comparable {
+public class WebContinuation implements Comparable, Cloneable {
 
     /**
      * The continuation this object represents.
@@ -355,13 +354,83 @@
     }
 
     /**
+     * Update the continuation in the
+     */
+    protected void updateLastAccessTime() {
+        lastAccessTime = System.currentTimeMillis();
+    }
+
+    /**
+     * Determines whether this continuation has expired
+     *
+     * @return a <code>boolean</code> value
+     */
+    public boolean hasExpired() {
+        long currentTime = System.currentTimeMillis();
+        long expireTime = this.getLastAccessTime() + this.timeToLive;
+        
+        return (currentTime > expireTime);
+    }
+
+    /**
+     * Dispose this continuation. Should be called on invalidation.
+     */
+    public void dispose() {
+        // Call possible implementation-specific clean-up on this continuation.
+        if (this.disposer != null) {
+            this.disposer.disposeContinuation(this);
+        }
+        // Remove continuation object - will also serve as "disposed" flag
+        this.continuation = null;
+    }
+
+    /**
+     * Return true if this continuation was disposed of
+     */
+    public boolean disposed() {
+        return this.continuation == null;
+    }
+    
+    public boolean interpreterMatches( String interpreterId ) {
+        return StringUtils.equals( this.interpreterId, interpreterId );
+    }
+
+    public void detachFromParent() {
+        if (getParentContinuation() != null)
+            getParentContinuation().getChildren().remove(this);
+    }
+    
+    /**
+     * Creates a clone of this WebContinuation without trying to clone the actual continuation,
the
+     * user object or the disposer.
+     * 
+     * TODO: Check continuation, user object, disposer for implementing {@link Cloneable}
or
+     *       {@link java.io.Serializable}.
+     */
+    public Object clone() {
+        
+        WebContinuation clone = new WebContinuation(id, continuation, null, timeToLive, interpreterId,
disposer);
+        // reset last access time
+        clone.lastAccessTime = this.lastAccessTime;
+        // recreate hierarchy recursively
+        for (Iterator iter = this.children.iterator(); iter.hasNext();) {
+            WebContinuation child = (WebContinuation) iter.next();
+            WebContinuation childClone = (WebContinuation) child.clone();
+            // relationships must be fixed manually
+            childClone.parentContinuation = clone;
+            clone.children.add(childClone);
+        }
+        return clone;
+    }
+    
+    /**
      * Debugging method.
      *
      * <p>Assumes the receiving instance as the root of a tree and
      * displays the tree of continuations.
      */
-    public void display() {
-        getLogger().debug("\nWK: Tree" + display(0));
+    public String toString() {
+        return "\nWK: Tree" + display(0);
     }
 
     /**
@@ -404,50 +473,4 @@
         return tree.toString();
     }
 
-    /**
-     * Update the continuation in the
-     */
-    protected void updateLastAccessTime() {
-        lastAccessTime = System.currentTimeMillis();
-    }
-
-    /**
-     * Determines whether this continuation has expired
-     *
-     * @return a <code>boolean</code> value
-     */
-    public boolean hasExpired() {
-        long currentTime = System.currentTimeMillis();
-        long expireTime = this.getLastAccessTime() + this.timeToLive;
-        
-        return (currentTime > expireTime);
-    }
-
-    /**
-     * Dispose this continuation. Should be called on invalidation.
-     */
-    public void dispose() {
-        // Call possible implementation-specific clean-up on this continuation.
-        if (this.disposer != null) {
-            this.disposer.disposeContinuation(this);
-        }
-        // Remove continuation object - will also serve as "disposed" flag
-        this.continuation = null;
-    }
-
-    /**
-     * Return true if this continuation was disposed of
-     */
-    public boolean disposed() {
-        return this.continuation == null;
-    }
-    
-    public boolean interpreterMatches( String interpreterId ) {
-        return StringUtils.equals( this.interpreterId, interpreterId );
-    }
-
-    public void detachFromParent() {
-        if (getParentContinuation() != null)
-            getParentContinuation().getChildren().remove(this);
-    }
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java?rev=643294&r1=643293&r2=643294&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
Mon Mar 31 23:20:52 2008
@@ -100,6 +100,7 @@
             this.lastContinuation = lastContinuation;
             if (lastContinuation != null) {
                 fwk = new FOM_WebContinuation(lastContinuation);
+                fwk.enableLogging(this.logger);
                 Scriptable scope = FOM_Cocoon.this.getParentScope();
                 fwk.setParentScope(scope);
                 fwk.setPrototype(getClassPrototype(scope, fwk.getClassName()));
@@ -667,7 +668,7 @@
         return currentCall.avalonContext;
     }
 
-    private Logger getLogger() {
+    protected Logger getLogger() {
         return currentCall.logger;
     }
 
@@ -735,14 +736,16 @@
     /**
      * Return this continuation if it is valid, or first valid parent
      */
-    private FOM_WebContinuation findValidParent(FOM_WebContinuation wk) {
+    private FOM_WebContinuation findValidParent(final FOM_WebContinuation wk) {
         if (wk != null) {
             WebContinuation wc = wk.getWebContinuation();
             while (wc != null && wc.disposed()) {
                 wc = wc.getParentContinuation();
             }
             if (wc != null) {
-                return new FOM_WebContinuation(wc);
+                FOM_WebContinuation parentWk = new FOM_WebContinuation(wc);
+                parentWk.enableLogging(getLogger());
+                return wk;
             }
         }
 
@@ -793,6 +796,7 @@
                                            getInterpreter().getInterpreterID(),
                                            null);
         FOM_WebContinuation result = new FOM_WebContinuation(wk);
+        result.enableLogging(getLogger());
         result.setParentScope(getParentScope());
         result.setPrototype(getClassPrototype(getParentScope(),
                                               result.getClassName()));

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java?rev=643294&r1=643293&r2=643294&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
Mon Mar 31 23:20:52 2008
@@ -833,6 +833,7 @@
                 }
                 cocoon.setParameters(parameters);
                 FOM_WebContinuation fom_wk = new FOM_WebContinuation(wk);
+                fom_wk.enableLogging(getLogger());
                 fom_wk.setParentScope(kScope);
                 fom_wk.setPrototype(ScriptableObject.getClassPrototype(kScope,
                                                                        fom_wk.getClassName()));

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java?rev=643294&r1=643293&r2=643294&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_WebContinuation.java
Mon Mar 31 23:20:52 2008
@@ -19,6 +19,8 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.components.flow.ContinuationsManager;
 import org.apache.cocoon.components.flow.WebContinuation;
@@ -35,10 +37,11 @@
  *
  * @version CVS $Id$
  */
-public class FOM_WebContinuation extends ScriptableObject {
+public class FOM_WebContinuation extends ScriptableObject implements LogEnabled {
 
     WebContinuation wk;
-
+    
+    private Logger logger;
 
     static class UserObject {
         boolean isBookmark;
@@ -62,6 +65,10 @@
         this.wk = wk;
     }
 
+    public void enableLogging(Logger logger) {
+        this.logger = logger;
+    }
+
     // new FOM_WebContinuation([Continuation] continuation,
     //                         [FOM_WebContinuation] parent,
     //                         [Number] timeToLive)
@@ -95,6 +102,7 @@
                                            cocoon.getInterpreterId(), 
                                            null);
         result = new FOM_WebContinuation(wk);
+        result.enableLogging(cocoon.getLogger());
         result.setParentScope(getTopLevelScope(scope));
         result.setPrototype(getClassPrototype(scope, result.getClassName()));
         return result;
@@ -140,6 +148,7 @@
         }
 
         FOM_WebContinuation pwk = new FOM_WebContinuation(parent);
+        pwk.enableLogging(logger);
         pwk.setParentScope(getParentScope());
         pwk.setPrototype(getClassPrototype(getParentScope(),
                                            pwk.getClassName()));
@@ -156,6 +165,7 @@
         for (int i = 0; iter.hasNext(); i++) {
             WebContinuation child = (WebContinuation)iter.next();
             FOM_WebContinuation cwk = new FOM_WebContinuation(child);
+            cwk.enableLogging(logger);
             cwk.setParentScope(getParentScope());
             cwk.setPrototype(getClassPrototype(getParentScope(),
                                                cwk.getClassName()));
@@ -175,7 +185,9 @@
     }
 
     public void jsFunction_display() {
-        wk.display();
+        if (this.logger.isDebugEnabled()) {
+            this.logger.debug(wk.toString());
+        }
     }
 
     public WebContinuation getWebContinuation() {
@@ -243,6 +255,7 @@
         }
 
         FOM_WebContinuation pwk = new FOM_WebContinuation(c);
+        pwk.enableLogging(logger);
         pwk.setParentScope(getParentScope());
         pwk.setPrototype(getClassPrototype(getParentScope(), pwk.getClassName()));
         return pwk;
@@ -254,4 +267,5 @@
     public String toString() {
         return "WC" + wk.getId();
     }
+
 }



Mime
View raw message