Author: rahul
Date: Tue Sep 12 14:05:40 2006
New Revision: 442705

URL: http://svn.apache.org/viewvc?view=rev&rev=442705
Log:
Improve dialog-config.xml parsing for SCXML dialogs. Introduce the notion of 
DialogMetadata, a POJO that contains all the relevant bits that Commons SCXML 
needs to create an instance of a particular dialog.

DialogMetadata is used to account for the bits of Shale dialogs specific XML 
vocabulary, which obviously special cases from a generic state machine 
vocabulary -- for example, the attribute for the dialog data class name.

Added:
    
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/config/DialogMetadata.java
   (with props)
Modified:
    
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/config/ConfigurationParser.java

Modified: 
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/config/ConfigurationParser.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/config/ConfigurationParser.java?view=diff&rev=442705&r1=442704&r2=442705
==============================================================================
--- 
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/config/ConfigurationParser.java
 (original)
+++ 
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/config/ConfigurationParser.java
 Tue Sep 12 14:05:40 2006
@@ -68,6 +68,12 @@
     // -------------------------------------------------------------- 
Properties
 
     /**
+     * <p>Default FQCN for dialog data.</p>
+     */
+    private static final String DEFAULT_DIALOG_DATA_CLASS_NAME = 
"java.util.HashMap";
+
+
+    /**
      * <p><code>Map</code> of <code>Dialog</code> instances resulting
      * from parsing, keyed by dialog name.</p>
      */
@@ -213,7 +219,9 @@
 
                 Map.Entry entry = (Map.Entry) iterator.next();
                 String name = (String) entry.getKey();
-                String scxmlconfig = (String) entry.getValue();
+                DialogMetadata dMetadata = (DialogMetadata) entry.getValue();
+                String scxmlconfig = dMetadata.getConfig();
+                String dataclassname = dMetadata.getDataclassname();
 
                 // TODO - Relative URL testing
                 URL resource = new URL(getResource(), scxmlconfig);
@@ -227,7 +235,8 @@
                     throw new SAXException(me.getMessage(), me);
                 }
 
-                dialogs.put(name, dialog);
+                dMetadata.setStateMachine(dialog);
+                dialogs.put(name, dMetadata);
 
         }
 
@@ -256,11 +265,17 @@
                 final Attributes attributes) {
 
             Map metadata = (Map) getDigester().peek();
-            metadata.put(attributes.getValue("name"),
-                        attributes.getValue("scxmlconfig"));
+            String name = attributes.getValue("name");
+            String scxmlconfig = attributes.getValue("scxmlconfig");
+            String dataclassname = attributes.getValue("dataclassname");
+            if (dataclassname == null || dataclassname.trim().length() == 0) {
+                dataclassname = DEFAULT_DIALOG_DATA_CLASS_NAME;
+            }
+            metadata.put(name, new DialogMetadata(name, scxmlconfig, 
dataclassname));
 
         }
 
     }
 
 }
+

Added: 
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/config/DialogMetadata.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/config/DialogMetadata.java?view=auto&rev=442705
==============================================================================
--- 
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/config/DialogMetadata.java
 (added)
+++ 
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/config/DialogMetadata.java
 Tue Sep 12 14:05:40 2006
@@ -0,0 +1,139 @@
+/*
+ *
+ *   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.
+ *
+ */
+
+package org.apache.shale.dialog2.scxml.config;
+
+import java.io.Serializable;
+
+import org.apache.commons.scxml.model.SCXML;
+
+
+/**
+ * <p>Bean encapsulating metadata for a Shale dialog when using Commons SCXML
+ * to drive the underlying state machine.</p>
+ *
+ * <p>This includes:
+ *  <ul>
+ *   <li>The logical name of this dialog.</li>
+ *   <li>The document location where Commons SCXML can find the SCXML document
+ *       describing this dialog.</li>
+ *   <li>The Commons SCXML object model for this dialog obtained by parsing
+ *       the above document.</li>
+ *   <li>The dialog data class name, an instance of which will be set as
+ *       dialog data once an instance of this dialog is started.</li>
+ *  </ul>
+ * </p>
+ */
+public class DialogMetadata implements Serializable {
+
+    //---------------------------------------- SCXML dialog metadata variables
+
+        /**
+         * The dialog name.
+         */
+        private String name;
+
+        /**
+         * The location where the SCXML document for this dialog resides.
+         */
+        private String config;
+
+
+        /**
+         * The Commons SCXML object model describing the state machine for 
this dialog.
+         */
+        private SCXML stateMachine;
+
+
+        /**
+         * The FQCN of the dialog data.
+         */
+        private String dataClassName;
+
+
+        //---------------------------------------- Default scope
+
+        /**
+         * Constructor.
+         *
+         * @param name The dialog name
+         * @param config The location where the SCXML document for this dialog 
resides
+         * @param dataClassName The FQCN of the dialog data
+         */
+        DialogMetadata(String name, String config, String dataclassname) {
+                this.name = name;
+            this.config = config;
+            this.dataClassName = dataclassname;
+        }
+
+
+        /**
+         * Set the Commons SCXML object model describing the state machine
+         * for this dialog.
+         *
+         * @param stateMachine The stateMachine to set.
+         */
+        public void setStateMachine(SCXML statemachine) {
+                this.stateMachine = statemachine;
+        }
+
+
+        //---------------------------------------- Public methods
+
+        /**
+         * Get the dialog name.
+         *
+         * @return Returns the dialog name.
+         */
+        public String getName() {
+                return name;
+        }
+
+
+        /**
+         * Get the data class FQN.
+         *
+         * @return Returns the dataClassName.
+         */
+        public String getDataclassname() {
+                return dataClassName;
+        }
+
+
+        /**
+         * Get the location where the SCXML document for this dialog resides.
+         *
+         * @return Returns the config.
+         */
+        public String getConfig() {
+                return config;
+        }
+
+
+        /**
+         * Get the Commons SCXML object model describing the state machine
+         * for this dialog.
+         *
+         * @return Returns the stateMachine.
+         */
+        public SCXML getStateMachine() {
+                return stateMachine;
+        }
+
+}
+

Propchange: 
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/config/DialogMetadata.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/config/DialogMetadata.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL


Reply via email to