Author: craigmcc
Date: Sun Sep 10 17:13:09 2006
New Revision: 442044
URL: http://svn.apache.org/viewvc?view=rev&rev=442044
Log:
Enhance usability of the legacy dialog2 implementation by allowing the dialog
metadata to specify a FQCN of a JavaBean class to be instantiated as the
initial "data" property for a particular named dialog. In many scenarios,
this will eliminate the need for a starting action state where the only
responsibility was to create such a data object and call setData() with it.
In order to use the new capability, you will need to switch to version 1.1
of the corresponding DTD (also included in this commit).
Also, refactored the internal implementation of LegacyDialogContext to use
a single stack of positions, instead of parallel stacks of positions and
data object references. This should have no impact on any application
currently using these APIs.
Added:
shale/sandbox/shale-dialog2-legacy/src/main/resources/org/apache/shale/dialog2/dialog2-config_1_1.dtd
(with props)
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/Position.java
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/config/ConfigurationParser.java
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/config/DialogImpl.java
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/model/Dialog.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?view=diff&rev=442044&r1=442043&r2=442044
==============================================================================
---
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
Sun Sep 10 17:13:09 2006
@@ -84,7 +84,7 @@
/**
* <p>Generic data object containing state information for this
instance.</p>
*/
- private Object data = null;
+// private Object data = null;
/**
@@ -128,14 +128,6 @@
/**
- * <p>References to data objects that are associated with the
- * Position instances at corresponding indexes in the
- * <code>positions</code> list.</p>
- */
- private List references = new ArrayList();
-
-
- /**
* <p>An empty parameter list to pass to the action method called by
* a method binding expression.</p>
*/
@@ -163,13 +155,12 @@
/** [EMAIL PROTECTED] */
public Object getData() {
- // Locks on "positions" for consistency
synchronized (positions) {
int index = positions.size() - 1;
if (index < 0) {
return null;
}
- return references.get(index);
+ return ((Position) positions.get(index)).getData();
}
}
@@ -185,7 +176,7 @@
if (index < 0) {
throw new IllegalStateException("Cannot set data when no
positions are stacked");
}
- references.set(index, data);
+ ((Position) positions.get(index)).setData(data);
}
}
@@ -363,7 +354,6 @@
throw new IllegalStateException("No position to be popped");
}
positions.remove(index);
- references.remove(index);
if (index > 0) {
return (Position) positions.get(index - 1);
} else {
@@ -387,7 +377,6 @@
}
synchronized (positions) {
positions.add(position);
- references.add(null);
}
}
@@ -401,6 +390,7 @@
*/
private void start(Dialog dialog) {
+ // Look up the initial state for the specified dialog
State state = dialog.findState(dialog.getStart());
if (state == null) {
throw new IllegalStateException
@@ -408,7 +398,19 @@
+ dialog.getStart()
+ "' for dialog '" + dialog.getName() + "'");
}
- push(new Position(dialog, state));
+
+ // Construct an appropriate data object for the specified dialog
+ Object data = null;
+ try {
+ data = dialog.getDataClass().newInstance();
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new FacesException(e);
+ }
+
+ // Push a Position and corresponding data object to our stacks
+ push(new Position(dialog, state, data));
}
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?view=diff&rev=442044&r1=442043&r2=442044
==============================================================================
---
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
Sun Sep 10 17:13:09 2006
@@ -17,6 +17,7 @@
package org.apache.shale.dialog2.legacy;
import java.io.Serializable;
+import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.apache.shale.dialog2.legacy.model.Dialog;
@@ -33,27 +34,21 @@
/**
- * <p>Construct a new [EMAIL PROTECTED] Position} representing the starting
- * [EMAIL PROTECTED] State} for the specified [EMAIL PROTECTED]
Dialog}.</p>
- */
- Position(Dialog dialog) {
- this(dialog, null);
- }
-
-
- /**
* <p>Construct a new [EMAIL PROTECTED] Position} representing the
specified
- * [EMAIL PROTECTED] State} for the specified [EMAIL PROTECTED]
Dialog}.</p>
+ * [EMAIL PROTECTED] State} for the specified [EMAIL PROTECTED] Dialog},
and associated
+ * with the specified <code>data</code> instance.</p>
*
* @param dialog [EMAIL PROTECTED] Dialog} to be recorded
* @param state [EMAIL PROTECTED] State} to be recorded
+ * @param data Data instance to be recorded
*/
- Position(Dialog dialog, State state) {
+ Position(Dialog dialog, State state, java.lang.Object data) {
if (dialog == null) {
throw new IllegalArgumentException("Dialog cannot be null");
}
setDialog(dialog);
setState(state);
+ setData(data);
}
@@ -61,6 +56,13 @@
/**
+ * <p>The data instance for the dialog execution represeented by this
+ * [EMAIL PROTECTED] Position}.</p>
+ */
+ private Object data = null;
+
+
+ /**
* <p>The [EMAIL PROTECTED] Dialog} within which this [EMAIL PROTECTED]
Position} is reported.
* This value is transient, and may need to be regenerated.</p>
*/
@@ -93,6 +95,24 @@
/**
+ * <p>Return the data object associated with this dialog execution.</p>
+ */
+ Object getData() {
+ return this.data;
+ }
+
+
+ /**
+ * <p>Set the data object associated with this dialog execution.</p>
+ *
+ * @param data The new data object
+ */
+ void setData(Object data) {
+ this.data = data;
+ }
+
+
+ /**
* <p>Return the [EMAIL PROTECTED] Dialog} whose execution is tracked by
this
* [EMAIL PROTECTED] Position}.</p>
*/
@@ -152,10 +172,12 @@
*/
public String toString() {
if (getState() == null) {
- return "Position[dialog=" + getDialog().getName() + "]";
+ return "Position[dialog=" + getDialog().getName()
+ + ",data=" + getData() + "]";
} else {
return "Position[dialog=" + getDialog().getName()
- + ",state=" + getState().getName() + "]";
+ + ",state=" + getState().getName()
+ + ",data=" + getData() + "]";
}
}
Modified:
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/config/ConfigurationParser.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/config/ConfigurationParser.java?view=diff&rev=442044&r1=442043&r2=442044
==============================================================================
---
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/config/ConfigurationParser.java
(original)
+++
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/config/ConfigurationParser.java
Sun Sep 10 17:13:09 2006
@@ -51,7 +51,9 @@
*/
private static final String REGISTRATIONS[] =
{ "-//Apache Software Foundation//DTD Shale Dialog2 Configuration 1.0//EN",
- "/org/apache/shale/dialog2/dialog2-config_1_0.dtd" };
+ "/org/apache/shale/dialog2/dialog2-config_1_0.dtd",
+ "-//Apache Software Foundation//DTD Shale Dialog2 Configuration 1.1//EN",
+ "/org/apache/shale/dialog2/dialog2-config_1_1.dtd" };
// --------------------------------------------------------------
Properties
Modified:
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/config/DialogImpl.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/config/DialogImpl.java?view=diff&rev=442044&r1=442043&r2=442044
==============================================================================
---
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/config/DialogImpl.java
(original)
+++
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/config/DialogImpl.java
Sun Sep 10 17:13:09 2006
@@ -35,6 +35,14 @@
/**
+ * <p>The class of a JavaBean to be instantiated as the initial
+ * value of the <code>data</code> property of a newly instantiated
+ * <code>DialogContext</code>.</p>
+ */
+ private Class dataClass = HashMap.class;
+
+
+ /**
* <p>Name of this [EMAIL PROTECTED] Dialog}.</p>
*/
private String name = null;
@@ -66,6 +74,18 @@
/**
+ * <p>Return the class of a JavaBean to be instantiated as the initial
+ * value of the <code>data</code> property of a newly instantiated
+ * <code>DialogContext</code>.</p>
+ */
+ public Class getDataClass() {
+
+ return this.dataClass;
+
+ }
+
+
+ /**
* <p>Return the name of this [EMAIL PROTECTED] Dialog}.</p>
*/
public String getName() {
@@ -188,6 +208,31 @@
// FIXME - addTransition() - ignore duplicate outcomes for now
transitions.put(transition.getOutcome(), transition);
+
+ }
+
+
+ /**
+ * <p>Set the data class name for the <code>data</code> property
+ * of a newly instantiated <code>DialogContext</code>.</p>
+ *
+ * @param dataClassName New data class name
+ *
+ * @exception Exception if the specified class name cannot be loaded
+ */
+ public void setDataClassName(String dataClassName) {
+
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if (loader == null) {
+ loader = DialogImpl.class.getClassLoader();
+ }
+ try {
+ this.dataClass = loader.loadClass(dataClassName);
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
}
Modified:
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/model/Dialog.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/model/Dialog.java?view=diff&rev=442044&r1=442043&r2=442044
==============================================================================
---
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/model/Dialog.java
(original)
+++
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/model/Dialog.java
Sun Sep 10 17:13:09 2006
@@ -46,6 +46,22 @@
/**
+ * <p>Return the class of a JavaBean to be instantiated as the initial
+ * value of the <code>data</code> property of a newly instantiated
+ * <code>DialogContext</code>.</p>
+ *
+ * <p>If not explicitly specified in the configuration metadata, this
+ * should default to <code>java.util.HashMap</code> to provide convenient
+ * name/value pair storage.</p>
+ *
+ * <p><strong>IMPLEMENTATION NOTE</strong> - Because the <code>data</code>
+ * object of <code>DialogContext</code> instances is stored in session
+ * scope, the <code>Class</code> specified here should be serializable.</p>
+ */
+ public Class getDataClass();
+
+
+ /**
* <p>Return the name of this [EMAIL PROTECTED] Dialog}.</p>
*/
public String getName();
Added:
shale/sandbox/shale-dialog2-legacy/src/main/resources/org/apache/shale/dialog2/dialog2-config_1_1.dtd
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-legacy/src/main/resources/org/apache/shale/dialog2/dialog2-config_1_1.dtd?view=auto&rev=442044
==============================================================================
---
shale/sandbox/shale-dialog2-legacy/src/main/resources/org/apache/shale/dialog2/dialog2-config_1_1.dtd
(added)
+++
shale/sandbox/shale-dialog2-legacy/src/main/resources/org/apache/shale/dialog2/dialog2-config_1_1.dtd
Sun Sep 10 17:13:09 2006
@@ -0,0 +1,204 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+
+ Copyright 2006 The Apache Software Foundation.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+
+<!--
+
+ DTD for dialog definitions used by the "org.apache.shale.dialog2" package.
+ To support validation of your configuration file, include the following
+ DOCTYPE element at the beginning (after the "xml" declaration):
+
+ <!DOCTYPE dialogs PUBLIC
+ "-//Apache Software Foundation//DTD Shale Dialog2 Configuration 1.1//EN"
+ "http://shale.apache.org/dtds/dialog2-config_1_1.dtd">
+
+-->
+
+
+<!-- ====================== Top Level Elements =============================
-->
+
+
+<!-- The "dialogs" element is the root of a single configuration file, and
+ contains zero or more "dialog" elements defining the states and
transitions
+ for a particular dialog.
+-->
+<!ELEMENT dialogs (dialog*)>
+
+
+<!-- The "dialog" element defines the states for a particular reusable dialog,
+ which itself consists of zero or more states (of particular types). The
+ following attributes are defined:
+
+ className Fully qualified class name of the configuration
+ object for this element.
+ [org.apache.shale.dialog.impl.DialogImpl]
+
+ dataClassName Fully qualified class name of a JavaBean class
+ to be instantiated as the initial value of the
+ "data" property when a new DialogContext is
+ initialized. [java.util.HashMap]
+
+ name Name of this dialog (must be unique among
+ all defined dialogs).
+
+ start Name of the starting state for this dialog.
+-->
+<!ELEMENT dialog ((transition|action|end|subdialog|view|property)*)>
+<!ATTLIST dialog className CDATA #IMPLIED>
+<!ATTLIST dialog dataClassName CDATA #IMPLIED>
+<!ATTLIST dialog name CDATA #REQUIRED>
+<!ATTLIST dialog start CDATA #REQUIRED>
+
+
+<!-- The "action" element represents an action state, which causes the
+ invocation of a public method that takes no arguments, and returns
+ the logical outcome as a String. The following attributes are defined:
+
+ className Fully qualified class name of the configuration
+ object for this element.
+ [org.apache.shale.dialog.impl.ActionStateImpl]
+
+ name Name of this state (must be unique among
+ all states defined for this dialog).
+
+ method Method binding expression ("#{...}") that
+ identifies a public method that takes no
+ arguments, and returns a String that represents
+ the logical outcome of this state.
+-->
+<!ELEMENT action (property|transition*)>
+<!ATTLIST action className CDATA #IMPLIED>
+<!ATTLIST action name CDATA #REQUIRED>
+<!ATTLIST action method CDATA #REQUIRED>
+
+
+<!-- The "subdialog" element represents a transition to a subordinate
+ dialog, saving the current state in the currently executing dialog
+ on a stack. When the subordinate dialog completes, the outcome it
+ returns will be used to trigger a transition in this dialog.
+ The following attributes are defined:
+
+ className Fully qualified class name of the configuration
+ object for this element.
+
[org.apache.shale.dialog.impl.SubdialogStateImpl]
+
+ name Name of this state (must be unique among
+ all states defined for this dialog).
+
+ dialogName Name of the subordinate dialog to be
+ executed.
+
+-->
+<!ELEMENT subdialog (property|transition*)>
+<!ATTLIST subdialog className CDATA #IMPLIED>
+<!ATTLIST subdialog name CDATA #REQUIRED>
+<!ATTLIST subdialog dialogName CDATA #REQUIRED>
+
+
+<!-- The "view" element represents a view state, which causes the rendering
+ of the specified JavaServer Faces view. When the subsequent submit from
+ this view is returned, the outcome returned by whatever action method was
+ invoked is returned in order to determine the next transition. The
+ following attributes are defined:
+
+ className Fully qualified class name of the configuration
+ object for this element.
+ [org.apache.shale.dialog.impl.ViewStateImpl]
+
+ name Name of this state (must be unique among
+ all states defined for this dialog).
+
+ viewId View identifier of the JavaServer Faces view
+ that should be rendered. The logical outcome
+ returned by whatever action handles the
+ subsequent submit from this view will be used
+ to determine the next state transition.
+
+-->
+<!ELEMENT view (property|transition*)>
+<!ATTLIST view className CDATA #IMPLIED>
+<!ATTLIST view name CDATA #REQUIRED>
+<!ATTLIST view viewId CDATA #REQUIRED>
+
+
+<!-- The "end" element represents a state that terminates a dialog. If
+ a view identifier is specified, it is rendered; otherwise, it is assumed
+ that a parent dialog which invoked the current dialog will be responsible
+ for producing the view for the current response.
+
+ className Fully qualified class name of the configuration
+ object for this element.
+ [org.apache.shale.dialog.impl.EndStateImpl]
+
+ name Name of this state (must be unique among
+ all states defined for this dialog).
+
+ viewId View identifier of the JavaServer Faces view
+ that should be rendered (if any). The logical
+ outcome returned by whatever action handles the
+ subsequent submit from this view will be
+ returned to the parent dialog to drive its
+ own state transition.
+-->
+<!ELEMENT end (property|transition*)>
+<!ATTLIST end className CDATA #IMPLIED>
+<!ATTLIST end name CDATA #REQUIRED>
+<!ATTLIST end viewId CDATA #IMPLIED>
+
+
+<!-- The "transition" element represents a state transition from the current
+ state (in which this "transition" element is nested) to a subsequent
+ state. The following attributes are defined:
+
+ className Fully qualified class name of the configuration
+ object for this element.
+ [org.apache.shale.dialog.impl.TransitionImpl]
+
+ outcome Logical outcome String returned by the invoked
+ method (for an "action" element), or by the
+ invoked action's action method (for a "view"
+ element).
+
+ target State name of the state to which control should
+ be transitioned. Must match the "name"
+ attribute of a state defined in this dialog.
+-->
+
+<!ELEMENT transition (property)*>
+<!ATTLIST transition className CDATA #IMPLIED>
+<!ATTLIST transition outcome CDATA #REQUIRED>
+<!ATTLIST transition target CDATA #REQUIRED>
+
+
+<!-- The "property" element allows the configuration of an arbitrary property
+ of the base class (typically customized via the "className" attribute)
+ instanace for the surrounding configuration element. The following
+ attributes are defined:
+
+ name Property name to be configured.
+
+ value String representation of the value to which
+ this property will be set. Appropriate type
+ conversion will be applied, based on the type
+ of the underlying property.
+-->
+
+<!ELEMENT property EMPTY>
+<!ATTLIST property name CDATA #REQUIRED>
+<!ATTLIST property value CDATA #REQUIRED>
Propchange:
shale/sandbox/shale-dialog2-legacy/src/main/resources/org/apache/shale/dialog2/dialog2-config_1_1.dtd
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
shale/sandbox/shale-dialog2-legacy/src/main/resources/org/apache/shale/dialog2/dialog2-config_1_1.dtd
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL