Author: rahul
Date: Mon Dec 11 19:46:29 2006
New Revision: 486006

URL: http://svn.apache.org/viewvc?view=rev&rev=486006
Log:
More debug/trace logging for shale-dialog-scxml
SHALE-350

Also added a 'started' flag (and related IllegalStateExceptions) matching 
behavior of the basic impl.

Modified:
    
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
    
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogManager.java
    
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/action/RedirectAction.java
    
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/action/ViewAction.java

Modified: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java?view=diff&rev=486006&r1=486005&r2=486006
==============================================================================
--- 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
 (original)
+++ 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
 Mon Dec 11 19:46:29 2006
@@ -28,6 +28,8 @@
 import javax.faces.context.FacesContext;
 import javax.faces.el.ValueBinding;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.commons.scxml.Context;
 import org.apache.commons.scxml.SCXMLExecutor;
 import org.apache.commons.scxml.SCXMLListener;
@@ -96,6 +98,11 @@
         this.executor.setRootContext(rootCtx);
         this.executor.addListener(statemachine, new DelegatingSCXMLListener());
 
+        if (log().isDebugEnabled()) {
+            log().debug("Constructor(id=" + id + ", name="
+                      + name + ")");
+        }
+
         // TODO - Consider adding an explicit root context backed by either the
         // request or session map for greater EL capacities in the SCXML
         // document describing this dialog
@@ -161,6 +168,12 @@
 
 
     /**
+     * <p>Flag indicating that execution has started for this dialog.</p>
+     */
+    private boolean started = false;
+
+
+    /**
      * <p>The current SCXML state ID for this dialog instance, maintained
      * to reinitialize the transient [EMAIL PROTECTED] SCXMLExecutor} driving 
this
      * dialog instance.</p>
@@ -168,6 +181,13 @@
     private String stateId = null;
 
 
+    /**
+     * <p>The <code>Log</code> instance for this dialog context.
+     * This value is lazily created (or recreated) as necessary.</p>
+     */
+    private transient Log log = null;
+
+
     // ----------------------------------------------------- DialogContext 
Properties
 
 
@@ -233,10 +253,24 @@
     /** [EMAIL PROTECTED] */
     public void advance(FacesContext context, String outcome) {
 
+        if (!started) {
+            throw new IllegalStateException("Dialog instance '"
+                    + getId() + "' for dialog name '"
+                    + getName() + "' has not yet been started");
+        }
+
+        if (log().isDebugEnabled()) {
+            log().debug("advance(id=" + getId() + ", name=" + getName()
+                      + ", outcome=" + outcome + ")");
+        }
+
         // If the incoming outcome is null, we want to stay in the same
         // (view) state *without* recreating it, which would destroy
         // any useful information that components might have stored
         if (outcome == null) {
+            if (log().isTraceEnabled()) {
+                log().trace("advance(outcome is null, stay in same view)");
+            }
             return;
         }
 
@@ -270,6 +304,18 @@
     /** [EMAIL PROTECTED] */
     public void start(FacesContext context) {
 
+        if (started) {
+            throw new IllegalStateException("Dialog instance '"
+                    + getId() + "' for dialog name '"
+                    + getName() + "' has already been started");
+        }
+        started = true;
+
+        if (log().isDebugEnabled()) {
+            log().debug("start(id=" + getId() + ", name="
+                      + getName() + ")");
+        }
+
         // inform listeners we're good to go
         fireOnStart();
 
@@ -322,7 +368,18 @@
     /** [EMAIL PROTECTED] */
     public void stop(FacesContext context) {
 
-        // TODO: Complete (add started flag like legacy impl, here and in 
other places)
+        if (!started) {
+            throw new IllegalStateException("Dialog instance '"
+                    + getId() + "' for dialog name '"
+                    + getName() + "' has not yet been started");
+        }
+        started = false;
+
+        if (log().isDebugEnabled()) {
+            log().debug("stop(id=" + getId() + ", name="
+                      + getName() + ")");
+        }
+
         deactivate();
         manager.remove(this);
 
@@ -376,6 +433,13 @@
         if (!viewId.startsWith("/")) {
             viewId = "/" + viewId;
         }
+
+        // The public API is advance, so thats part of the message
+        if (log().isDebugEnabled()) {
+            log().debug("advance(id=" + getId() + ", name=" + getName()
+                      + ", navigating to view: '" + viewId + "')");
+        }
+
         ViewHandler vh = context.getApplication().getViewHandler();
         if (dp.isNextRedirect()) {
             // clear redirect flag
@@ -426,6 +490,20 @@
         }
 
         return this.executor;
+    }
+
+
+    /**
+     * <p>Return the <code>Log</code> instance for this dialog context,
+     * creating one if necessary.</p>
+     */
+    private Log log() {
+
+        if (log == null) {
+            log = LogFactory.getLog(SCXMLDialogContext.class);
+        }
+        return log;
+
     }
 
 

Modified: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogManager.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogManager.java?view=diff&rev=486006&r1=486005&r2=486006
==============================================================================
--- 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogManager.java
 (original)
+++ 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogManager.java
 Mon Dec 11 19:46:29 2006
@@ -134,6 +134,12 @@
         }
         
context.getExternalContext().getRequestMap().put(Constants.CONTEXT_BEAN, 
instance);
         fireOnCreate(instance);
+
+        if (log().isDebugEnabled()) {
+            log().debug("create(Created DialogContext instance with ID '"
+                + instance.getId() + "' for dialog with name '" + name + "'");
+        }
+
         return instance;
     }
 
@@ -147,12 +153,20 @@
     /** [EMAIL PROTECTED] */
     public void remove(DialogContext instance) {
         boolean found = false;
+        // Cache ID in case any of the listeners destroy instance onRemove()
+        String id = instance.getId();
         synchronized (map) {
-            found = map.remove(instance.getId()) == instance;
+            found = map.remove(id) == instance;
         }
         if (found) {
             ((SCXMLDialogContext) instance).deactivate();
             fireOnRemove(instance);
+
+            if (log().isDebugEnabled()) {
+                log().debug("remove(Removed DialogContext instance with ID '"
+                    + id + "'");
+            }
+
         }
     }
 

Modified: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/action/RedirectAction.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/action/RedirectAction.java?view=diff&rev=486006&r1=486005&r2=486006
==============================================================================
--- 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/action/RedirectAction.java
 (original)
+++ 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/action/RedirectAction.java
 Mon Dec 11 19:46:29 2006
@@ -20,6 +20,7 @@
 import java.util.Collection;
 
 import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.commons.scxml.ErrorReporter;
 import org.apache.commons.scxml.EventDispatcher;
 import org.apache.commons.scxml.SCInstance;
@@ -59,6 +60,32 @@
             get(Globals.DIALOG_PROPERTIES);
         dp.setNextRedirect(true);
 
+        if (log().isDebugEnabled()) {
+            log().debug("<redirect>: Next view will be issued via a redirect");
+        }
+
+    }
+
+
+    // --------------------------------------------------------------- Logging
+
+    /**
+     * <p>The <code>Log</code> instance for this class.  This value is lazily
+     * instantiated, and is also transient and may need to be regenerated.</p>
+     */
+    private transient Log log = null;
+
+
+    /**
+     * <p>Return the <code>Log</code> instance for this instance.</p>
+     *
+     * @return The [EMAIL PROTECTED] Log} instance used by this manager
+     */
+    private Log log() {
+        if (this.log == null) {
+            this.log = LogFactory.getLog(RedirectAction.class);
+        }
+        return this.log;
     }
 
 }

Modified: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/action/ViewAction.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/action/ViewAction.java?view=diff&rev=486006&r1=486005&r2=486006
==============================================================================
--- 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/action/ViewAction.java
 (original)
+++ 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/action/ViewAction.java
 Mon Dec 11 19:46:29 2006
@@ -20,6 +20,7 @@
 import java.util.Collection;
 
 import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.commons.scxml.ErrorReporter;
 import org.apache.commons.scxml.EventDispatcher;
 import org.apache.commons.scxml.SCInstance;
@@ -59,6 +60,10 @@
             get(Globals.DIALOG_PROPERTIES);
         dp.setNextViewId(viewId);
 
+        if (log().isDebugEnabled()) {
+            log().debug("<view>: Setting next view ID to '" + viewId + "'");
+        }
+
     }
 
     /**
@@ -83,6 +88,27 @@
      */
     public void setViewId(String viewId) {
         this.viewId = viewId;
+    }
+
+    // --------------------------------------------------------------- Logging
+
+    /**
+     * <p>The <code>Log</code> instance for this class.  This value is lazily
+     * instantiated, and is also transient and may need to be regenerated.</p>
+     */
+    private transient Log log = null;
+
+
+    /**
+     * <p>Return the <code>Log</code> instance for this instance.</p>
+     *
+     * @return The [EMAIL PROTECTED] Log} instance used by this manager
+     */
+    private Log log() {
+        if (this.log == null) {
+            this.log = LogFactory.getLog(ViewAction.class);
+        }
+        return this.log;
     }
 
 }


Reply via email to