You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shale.apache.org by cr...@apache.org on 2006/09/03 01:57:10 UTC

svn commit: r439690 - in /shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy: LegacyDialogContext.java LegacyDialogManager.java Position.java

Author: craigmcc
Date: Sat Sep  2 16:57:10 2006
New Revision: 439690

URL: http://svn.apache.org/viewvc?rev=439690&view=rev
Log:
Obey serializable contracts on LegacyContextManager, LegacyContext, and
Position by maintaining only transient references to actual (or potential)
non-Serializable objects.

Modified:
    shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java
    shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java
    shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/Position.java

Modified: shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java
URL: http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java?rev=439690&r1=439689&r2=439690&view=diff
==============================================================================
--- shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java (original)
+++ shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java Sat Sep  2 16:57:10 2006
@@ -64,6 +64,7 @@
 
         this.manager = manager;
         this.dialog = dialog;
+        this.dialogName = dialog.getName();
         this.id = id;
 
         start(dialog);
@@ -87,15 +88,23 @@
 
 
     /**
-     * <p>The {@link Dialog} that this instance is executing.</p>
+     * <p>The {@link Dialog} that this instance is executing.  This value is
+     * transient and may need to be regenerated.</p>
      */
-    private Dialog dialog = null;
+    private transient Dialog dialog = null;
 
 
     /**
-     * <p><code>Map</code> of configured dialogs, keyed by logical name.</p>
+     * <p>The name of the {@link Dialog} that this instance is executing.</p>
      */
-    private Map dialogs = null;
+    private String dialogName = null;
+
+
+    /**
+     * <p><code>Map</code> of configured dialogs, keyed by logical name.  This value is
+     * transient and may need to be regenerated.</p>
+     */
+    private transient Map dialogs = null;
 
 
     /**
@@ -268,6 +277,22 @@
 
 
     // --------------------------------------------------------- Private Methods
+
+
+    /**
+     * <p>Return the {@link Dialog} instance for the dialog we are executing,
+     * regenerating it if necessary first.</p>
+     *
+     * @param context FacesContext for the current request
+     */
+    private Dialog dialog(FacesContext context) {
+
+        if (this.dialog == null) {
+            this.dialog = (Dialog) dialogs(context).get(this.dialogName);
+        }
+        return this.dialog;
+
+    }
 
 
     /**

Modified: shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java
URL: http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java?rev=439690&r1=439689&r2=439690&view=diff
==============================================================================
--- shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java (original)
+++ shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogManager.java Sat Sep  2 16:57:10 2006
@@ -42,9 +42,10 @@
 
     /**
      * <p><code>Map</code> of {@link Dialog} configurations, keyed
-     * by dialog name.  This value is lazily instantiated.</p>
+     * by dialog name.  This value is lazily instantiated, and is also
+     * transient and may need to be regenerated.</p>
      */
-    private Map dialogs = null;
+    private transient Map dialogs = null;
 
 
     /**

Modified: shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/Position.java
URL: http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/Position.java?rev=439690&r1=439689&r2=439690&view=diff
==============================================================================
--- shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/Position.java (original)
+++ shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/Position.java Sat Sep  2 16:57:10 2006
@@ -16,6 +16,9 @@
 
 package org.apache.shale.dialog2.legacy;
 
+import java.io.Serializable;
+import java.util.Map;
+import javax.faces.context.FacesContext;
 import org.apache.shale.dialog2.legacy.model.Dialog;
 import org.apache.shale.dialog2.legacy.model.State;
 
@@ -23,7 +26,7 @@
  * <p>JavaBean that represents the current {@link State} within
  * a {@link Dialog}.</p>
  */
-class Position {
+class Position implements Serializable {
     
 
     // ------------------------------------------------------------ Constructors
@@ -49,8 +52,8 @@
         if (dialog == null) {
             throw new IllegalArgumentException("Dialog cannot be null");
         }
-        this.dialog = dialog;
-        this.state = state;
+        setDialog(dialog);
+        setState(state);
     }
 
 
@@ -58,16 +61,32 @@
 
 
     /**
-     * <p>The {@link Dialog} within which this {@link Position} is reported.</p>
+     * <p>The {@link Dialog} within which this {@link Position} is reported.
+     * This value is transient, and may need to be regenerated.</p>
      */
-    private Dialog dialog = null;
+    private transient Dialog dialog = null;
+
 
+    /**
+     * <p>The name of the {@link Dialog} within which this {@link Position}
+     * is reported.</p>
+     */
+    private String dialogName = null;
 
+    
     /**
      * <p>The {@link State} that represents the current position within the
-     * {@link Dialog} that is being executed.</p>
+     * {@link Dialog} that is being executed.  This value is transient, and
+     * may need to be regenerated.</p>
      */
-    private State state = null;
+    private transient State state = null;
+
+
+    /**
+     * <p>The name of the {@link State} that represents the current position
+     * within the {@link Dialog} that is being executed.</p>
+     */
+    private String stateName = null;
 
 
     // ------------------------------------------------------ Package Properties
@@ -78,11 +97,28 @@
      * {@link Position}.</p>
      */
     Dialog getDialog() {
+        if (this.dialog != null) {
+            return this.dialog;
+        }
+        Map map = (Map)
+          FacesContext.getCurrentInstance().getExternalContext().
+          getApplicationMap().get(Globals.DIALOGS);
+        this.dialog = (Dialog) map.get(this.dialogName);
         return this.dialog;
     }
 
 
     /**
+     * <p>Set the {@link Dialog} whose execution is being tracked by this
+     * {@link Position}.</p>
+     */
+    private void setDialog(Dialog dialog) {
+        this.dialog = dialog;
+        this.dialogName = dialog.getName();
+    }
+
+
+    /**
      * <p>Return the {@link State} representing the current execution position
      * within the owning {@link Dialog}.</p>
      */
@@ -98,7 +134,13 @@
      * @param state The new {@link State}
      */
     void setState(State state) {
-        this.state = state;
+        if (state == null) {
+            this.state = null;
+            this.stateName = null;
+        } else {
+            this.state = state;
+            this.stateName = state.getName();
+        }
     }
 
 
@@ -109,10 +151,11 @@
      * <p>Return a String representation of this object.</p>
      */
     public String toString() {
-        if (state == null) {
-            return "Position[dialog=" + dialog.getName() + "]";
+        if (getState() == null) {
+            return "Position[dialog=" + getDialog().getName() + "]";
         } else {
-            return "Position[dialog=" + dialog.getName() + ",state=" + state.getName() + "]";
+            return "Position[dialog=" + getDialog().getName()
+                   + ",state=" + getState().getName() + "]";
         }
     }