Author: rahul
Date: Mon Oct 30 17:14:30 2006
New Revision: 469332

URL: http://svn.apache.org/viewvc?view=rev&rev=469332
Log:
Introduce the notion of a DialogStateMapper which maps dialog state IDs to JSF 
view IDs.
 * The current FacesContext is available to this mapping, so it is possible to 
support multiple sets of views over user agents, modalities, locales, user 
roles etc. (ofcourse, the latter two on rare occassions) and share the same 
dialog "controller".
 * The default behavior is an identity transform, the state ID is used as-is as 
the view ID (a leading slash is added, if needed)
 * That behavior can be changed by replacing the application scope bean (which 
implements DialogStateMapper) at key 
"org$apache$shale$dialog$scxml$STATE_MAPPER"
Removed related TODOs from code, added new one as a reminder to document this 
bit.
SHALE-263

Added:
    
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/DialogStateMapper.java
   (with props)
    
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/
    
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/DefaultDialogStateMapper.java
   (with props)
    
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/package.html
   (with props)
Modified:
    
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/Globals.java
    
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
    
shale/framework/trunk/shale-dialog-scxml/src/main/resources/META-INF/faces-config.xml

Added: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/DialogStateMapper.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/DialogStateMapper.java?view=auto&rev=469332
==============================================================================
--- 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/DialogStateMapper.java
 (added)
+++ 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/DialogStateMapper.java
 Mon Oct 30 17:14:30 2006
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.dialog.scxml;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * <p>[EMAIL PROTECTED] DialogStateMapper} is an interface describing a 
pluggable
+ * mechanism to map between the state ID within a SCXML dialog definition
+ * and the corresponding JavaServer Faces <em>view identifier</em>
+ * that should be rendered when the dialog state machine comes to rest in
+ * that state.</p>
+ *
+ * <p>By default, an identity transform is applied i.e. the
+ * JavaServer Faces <code>view identifier</code> used is the same as
+ * the dialog state identifier.</p>
+ *
+ * TODO: Add mention in website docs.
+ *
+ * @since 1.0.4
+ *
+ * $Id$
+ */
+public interface DialogStateMapper {
+
+    /**
+     * <p>Return the JavaServer Faces <code>view identifier</code> that
+     * corresponds to current dialog state. The current [EMAIL PROTECTED] 
FacesContext}
+     * instance is also available so developers can consult pertinent
+     * information such as user role, current locale, user agent making
+     * the request etc. to map the state identifier to the view
+     * identifier, if needed.</p>
+     *
+     * @param dialogName The logical name of the dialog this state belongs to
+     * @param stateId The state identifier for the current dialog state
+     * @param context The current [EMAIL PROTECTED] FacesContext}
+     * @return The JavaServer Faces <code>view identifier</code> that should
+     *         be rendered
+     */
+    public String mapStateId(String dialogName, String stateId,
+                            FacesContext context);
+
+}
+

Propchange: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/DialogStateMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/DialogStateMapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/Globals.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/Globals.java?view=diff&rev=469332&r1=469331&r2=469332
==============================================================================
--- 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/Globals.java
 (original)
+++ 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/Globals.java
 Mon Oct 30 17:14:30 2006
@@ -17,6 +17,8 @@
 
 package org.apache.shale.dialog.scxml;
 
+import org.apache.shale.dialog.scxml.impl.DefaultDialogStateMapper;
+
 /**
  * <p>Manifest constants and well known event names for the
  * Jakarta Commons SCXML driven Shale dialog implementation.</p>
@@ -42,6 +44,15 @@
      */
     public static final String DIALOGS =
             "org.apache.shale.dialog.scxml.DIALOGS";
+
+
+    /**
+     * <p>Application scope attribute under which the current
+     * [EMAIL PROTECTED] DialogStateMapper} implementation resides. Defaults to
+     * [EMAIL PROTECTED] DefaultDialogStateMapper}.</p>
+     */
+    public static final String STATE_MAPPER =
+            "org$apache$shale$dialog$scxml$STATE_MAPPER";
 
 
     /**

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=469332&r1=469331&r2=469332
==============================================================================
--- 
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 Oct 30 17:14:30 2006
@@ -22,6 +22,7 @@
 import javax.faces.application.ViewHandler;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
 
 import org.apache.commons.scxml.SCXMLExecutor;
 import org.apache.commons.scxml.SCXMLListener;
@@ -226,19 +227,15 @@
             fireOnException(me);
         }
 
-        // TODO - Re-evaluate before leaving sandbox
-        // Using C/C, "View" state ID is JSF viewId, which is an acceptable
-        // approach with Commons SCXML v0.5
         Iterator iterator = 
dialogExecutor.getCurrentStatus().getStates().iterator();
         this.stateId = ((State) iterator.next()).getId();
-        String viewId = stateId; // to illustrate there could be some other 
transform here
 
         // If done, stop context
         if (dialogExecutor.getCurrentStatus().isFinal()) {
             stop(context);
         }
 
-        navigateTo(viewId, context);
+        navigateTo(stateId, context);
 
     }
 
@@ -277,18 +274,15 @@
             fireOnException(me);
         }
 
-        // Using C/C, "View" state ID is JSF viewId, which is an acceptable
-        // approach with Commons SCXML v0.5 since it accepts spaces etc.
         Iterator iterator = 
dialogExecutor.getCurrentStatus().getStates().iterator();
         this.stateId = ((State) iterator.next()).getId();
-        String viewId = stateId; // to illustrate there could be some other 
transform here
 
         // Might be done at the beginning itself, if so, stop context
         if (dialogExecutor.getCurrentStatus().isFinal()) {
             stop(context);
         }
 
-        navigateTo(viewId, context);
+        navigateTo(stateId, context);
 
     }
 
@@ -323,13 +317,17 @@
 
 
     /**
-     * <p>Convention over configuration approach.</p>
+     * <p>Navigate to the JavaServer Faces <code>view identifier</code>
+     * that is mapped to by the current state identifier for this dialog.</p>
      *
-     * @param viewId The identifier of the view to navigate to.
+     * @param stateId The current state identifier for this dialog.
      * @param context The current <code>FacesContext</code>
      */
-    private void navigateTo(String viewId, FacesContext context) {
-        // TODO: Convention needs to be configurable ;-)
+    private void navigateTo(String stateId, FacesContext context) {
+        ValueBinding vb = context.getApplication().createValueBinding
+            ("#{" + Globals.STATE_MAPPER + "}");
+        DialogStateMapper dsm = (DialogStateMapper) vb.getValue(context);
+        String viewId = dsm.mapStateId(name, stateId, context);
         // Navigate to the requested view identifier (if any)
         if (viewId == null) {
             return;

Added: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/DefaultDialogStateMapper.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/DefaultDialogStateMapper.java?view=auto&rev=469332
==============================================================================
--- 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/DefaultDialogStateMapper.java
 (added)
+++ 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/DefaultDialogStateMapper.java
 Mon Oct 30 17:14:30 2006
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.dialog.scxml.impl;
+
+import javax.faces.context.FacesContext;
+
+import org.apache.shale.dialog.scxml.DialogStateMapper;
+
+/**
+ * <p>Default [EMAIL PROTECTED] DialogStateMapper} implementation. The dialog 
state
+ * identifier itself is used as the JavaServer Faces
+ * <code>view identifier</code>.</p>
+ *
+ * @since 1.0.4
+ *
+ * $Id$
+ */
+public class DefaultDialogStateMapper implements DialogStateMapper {
+
+    /**
+     * <p>The default implementation is an identity transform i.e. it
+     * returns the dialog state ID as the next JavaServer Faces
+     * <code>view identifier</code>.</p>
+     */
+    public String mapStateId(String dialogName, String stateId,
+            FacesContext context) {
+
+        // the identity transform
+        return stateId;
+
+    }
+
+}
+

Propchange: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/DefaultDialogStateMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/DefaultDialogStateMapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/package.html
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/package.html?view=auto&rev=469332
==============================================================================
--- 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/package.html
 (added)
+++ 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/package.html
 Mon Oct 30 17:14:30 2006
@@ -0,0 +1,27 @@
+<html>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to you 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.
+
+-->
+<head>
+</head>
+<body>
+
+  <p>Default implementations of interfaces in this module.</p>
+
+</body>
+</html>

Propchange: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/impl/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: 
shale/framework/trunk/shale-dialog-scxml/src/main/resources/META-INF/faces-config.xml
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/resources/META-INF/faces-config.xml?view=diff&rev=469332&r1=469331&r2=469332
==============================================================================
--- 
shale/framework/trunk/shale-dialog-scxml/src/main/resources/META-INF/faces-config.xml
 (original)
+++ 
shale/framework/trunk/shale-dialog-scxml/src/main/resources/META-INF/faces-config.xml
 Mon Oct 30 17:14:30 2006
@@ -34,4 +34,10 @@
         <managed-bean-scope>session</managed-bean-scope>
     </managed-bean>
 
+    <managed-bean>
+        
<managed-bean-name>org$apache$shale$dialog$scxml$STATE_MAPPER</managed-bean-name>
+        
<managed-bean-class>org.apache.shale.dialog.scxml.impl.DefaultDialogStateMapper</managed-bean-class>
+        <managed-bean-scope>application</managed-bean-scope>
+    </managed-bean>
+
 </faces-config>


Reply via email to