Author: craigmcc
Date: Fri Apr 29 20:22:58 2005
New Revision: 165377
URL: http://svn.apache.org/viewcvs?rev=165377&view=rev
Log:
Support local and global transition definitions, analogous to how Struts 1.x
supports local and global action forward definitions.
PR: Bugzilla #34650.
Submitted By: David Geary <dgeary AT apache.org>
Modified:
struts/shale/trunk/core-library/src/conf/dialog.dtd
struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/Dialog.java
struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/DialogNavigationHandler.java
struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/package.html
Modified: struts/shale/trunk/core-library/src/conf/dialog.dtd
URL:
http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/conf/dialog.dtd?rev=165377&r1=165376&r2=165377&view=diff
==============================================================================
--- struts/shale/trunk/core-library/src/conf/dialog.dtd (original)
+++ struts/shale/trunk/core-library/src/conf/dialog.dtd Fri Apr 29 20:22:58 2005
@@ -52,7 +52,7 @@
start Name of the starting state for this dialog.
-->
-<!ELEMENT dialog ((action|end|subdialog|view)*)>
+<!ELEMENT dialog ((transition|action|end|subdialog|view)*)>
<!ATTLIST dialog name CDATA #REQUIRED>
<!ATTLIST dialog start CDATA #REQUIRED>
Modified:
struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/Dialog.java
URL:
http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/Dialog.java?rev=165377&r1=165376&r2=165377&view=diff
==============================================================================
---
struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/Dialog.java
(original)
+++
struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/Dialog.java
Fri Apr 29 20:22:58 2005
@@ -27,6 +27,12 @@
* threads may be processing states or transitions through this dialog).
* Therefore, access to configuration information is not synchronized.</p>
*
+ * <p>The set of [EMAIL PROTECTED] Transition}s associated with a [EMAIL
PROTECTED] Dialog} are
+ * global defaults that are scoped to the execution of the [EMAIL PROTECTED]
Dialog}.
+ * Logic that manages state transitions should always check for an appropriate
+ * [EMAIL PROTECTED] Transition} owned by the origin [EMAIL PROTECTED] State}
first, then consult
+ * the global [EMAIL PROTECTED] Transition}s associated with the [EMAIL
PROTECTED] Dialog}.</p>
+ *
* $Id$
*/
public class Dialog {
@@ -69,6 +75,15 @@
private Map states = new HashMap();
+ /**
+ * <p>The global [EMAIL PROTECTED] Transition}s owned by this [EMAIL
PROTECTED] Dialog}, keyed by
+ * outcome. Logic that performs transition management should first check
+ * for a [EMAIL PROTECTED] Transition} associated with the origin [EMAIL
PROTECTED] State}, then
+ * consult the [EMAIL PROTECTED] Dialog} for a global definition.</p>
+ */
+ private Map transitions = new HashMap();
+
+
// --------------------------------------------------------------
Properties
@@ -135,6 +150,19 @@
/**
+ * <p>Return the global [EMAIL PROTECTED] Transition} for the specified
logical outcome,
+ * if any; otherwise, return <code>null</code>.</p>
+ *
+ * @param outcome Logical outcome for which to return a [EMAIL PROTECTED]
Transition}
+ */
+ public Transition findTransition(String outcome) {
+
+ return (Transition) transitions.get(outcome);
+
+ }
+
+
+ /**
* <p>Render a printable version of this instance.</p>
*/
public String toString() {
@@ -167,6 +195,23 @@
/**
+ * <p>Add the specified [EMAIL PROTECTED] Transition} to the global [EMAIL
PROTECTED] Transition}s
+ * associated with this [EMAIL PROTECTED] Dialog}.</p>
+ *
+ * @param transition [EMAIL PROTECTED] Transition} to be added
+ *
+ * @exception IllegalArgumentException if the specified [EMAIL PROTECTED]
Transition}
+ * cannot be added to this [EMAIL PROTECTED] State}
+ */
+ void addTransition(Transition transition) {
+
+ // FIXME - addTransition() - ignore duplicate outcomes for now
+ transitions.put(transition.getOutcome(), transition);
+
+ }
+
+
+ /**
* <p>Remove the specified [EMAIL PROTECTED] State} from the [EMAIL
PROTECTED] State}s owned by
* this [EMAIL PROTECTED] Dialog}, if it is currently registered.
Otherwise,
* do nothing.</p>
@@ -176,6 +221,20 @@
void removeState(State state) {
states.remove(state.getName());
+
+ }
+
+
+ /**
+ * <p>Remove the specified [EMAIL PROTECTED] Transition} from the global
+ * [EMAIL PROTECTED] Transition}s associated with this [EMAIL PROTECTED]
Dialog}, if it is
+ * currently registered. Otherwise, do nothing.</p>
+ *
+ * @param transition [EMAIL PROTECTED] Transition} to be removed
+ */
+ void removeTransition(Transition transition) {
+
+ transitions.remove(transition.getOutcome());
}
Modified:
struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/DialogNavigationHandler.java
URL:
http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/DialogNavigationHandler.java?rev=165377&r1=165376&r2=165377&view=diff
==============================================================================
---
struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/DialogNavigationHandler.java
(original)
+++
struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/DialogNavigationHandler.java
Fri Apr 29 20:22:58 2005
@@ -433,7 +433,10 @@
/**
* <p>Transition from the specified [EMAIL PROTECTED] State} to a new
[EMAIL PROTECTED] State}
* based on the specified logical outcome, and return the new [EMAIL
PROTECTED] State}.
- * </p>
+ * When trying to identify an appropriate [EMAIL PROTECTED] Transition},
first check
+ * for a [EMAIL PROTECTED] Transition} directly owned by the origin [EMAIL
PROTECTED] State};
+ * if there is none, check for a global [EMAIL PROTECTED] Transition}
associated with
+ * the [EMAIL PROTECTED] Dialog} that owns the origin [EMAIL PROTECTED]
State}.</p>
*
* <p><strong>NOTE</strong> For consistency with standard JavaServer Faces
* navigation, transition from a [EMAIL PROTECTED] ViewState} with a
<code>null</code>
@@ -462,6 +465,9 @@
// Identify the appropriate Transition
Transition transition = state.findTransition(outcome);
+ if (transition == null) {
+ transition = state.getDialog().findTransition(outcome);
+ }
if (transition == null) {
throw new IllegalArgumentException
(status.peek().toString() + ",outcome=" + outcome);
Modified:
struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/package.html
URL:
http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/package.html?rev=165377&r1=165376&r2=165377&view=diff
==============================================================================
---
struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/package.html
(original)
+++
struts/shale/trunk/core-library/src/java/org/apache/shale/dialog/package.html
Fri Apr 29 20:22:58 2005
@@ -99,6 +99,15 @@
</ul></li>
</ul>
+<p>A particular <a href="State.html">State</a> has a set of
+<a href="Transition.html">Transitions</a> owned by it that are always
+consulted first when a transition is being processed. However, it is also
+possible to associate global <a href="Transition.html">Transitions</a> with
+the owning <a href="Dialog.html">Dialog</a> so that transition definitions
+do not have to be repeated for every state. This is analogous to the way
+that Struts 1.x supports both local and global <code>ActionForward</code>
+definitions.</p>
+
<p>In addition to managing state transitions, the dialog management
framework maintains a variable of type <a href="Status.html">Status</a>,
stored in session scope under a key that defaults to <code>dialog</code>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]