You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2008/04/05 11:37:29 UTC

svn commit: r645055 - in /myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation: Conversation.java spring/SpringSingleConversationScope.java

Author: imario
Date: Sat Apr  5 02:37:27 2008
New Revision: 645055

URL: http://svn.apache.org/viewvc?rev=645055&view=rev
Log:
ORCHESTRA-20: provide a "single conversation" per conversation scope. Mostly useful for dialog/flow frameworks.

Added:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringSingleConversationScope.java   (with props)
Modified:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/Conversation.java

Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/Conversation.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/Conversation.java?rev=645055&r1=645054&r2=645055&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/Conversation.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/Conversation.java Sat Apr  5 02:37:27 2008
@@ -19,17 +19,18 @@
 
 package org.apache.myfaces.orchestra.conversation;
 
-import java.util.Map;
-import java.util.TreeMap;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.orchestra.conversation.spring.SpringSingleConversationScope;
+
+import java.util.Map;
+import java.util.TreeMap;
 
 /**
  * A Conversation is a container for a set of beans.
- * 
+ *
  * <p>Optionally, a PersistenceContext can also be associated with a conversation.</p>
- * 
+ *
  * <p>There are various ways how to get access to a Conversation instance:
  * <ul>
  * <li>{@link Conversation#getCurrentInstance} if you are calling from a
@@ -39,10 +40,10 @@
  * interface in a bean.</li>
  * </ul>
  * </p>
- * 
+ *
  * <p>Conversation instances are typically created when an EL expression references a
  * bean whose definition indicates that it is in a conversation scope.</p>
- * 
+ *
  * <p>A conversation instance is typically destroyed:
  * <ul>
  * <li>At the end of a request when it are marked as access-scoped but
@@ -63,7 +64,7 @@
     private final Log log = LogFactory.getLog(Conversation.class);
 
     private final String name;
-    
+
     // The factory that created this conversation instance; needed
     // when restarting the conversation.
     private final ConversationFactory factory;
@@ -134,11 +135,11 @@
 
     /**
      * Add the given bean to the conversation scope.
-     * 
+     *
      * <p>This will fire a {@link ConversationBindingEvent} on the bean parameter
      * object if the bean implements the {@link ConversationBindingListener}
      * interface</p>
-     * 
+     *
      * <p>Note that any object can be stored into the conversation; it is not
      * limited to managed beans declared in a configuration file. This
      * feature is not expected to be heavily used however; most attributes of
@@ -169,7 +170,7 @@
 
     /**
      * Assert the conversation is valid.
-     * 
+     *
      * Throws IllegalStateException if this conversation has been destroyed;
      * see method setInvalid.
      */
@@ -327,7 +328,7 @@
 
     /**
      * Remove a bean from the conversation.
-     * 
+     *
      * <p>This will fire a {@link ConversationBindingEvent} if the bean implements the
      * {@link ConversationBindingListener} interface.</p>
      */
@@ -349,8 +350,10 @@
      * Get the current conversation.
      *
      * @return The conversation object associated with the nearest object in the call-stack that
-     * is configured to be in a conversation. Null is returned when no object in the call-stack
-     * is in a conversation.
+     * is configured to be in a conversation.<br />
+     * If there is no object in the call-stack the system will lookup the single conversation
+     * bound to the conversationContext.<br />
+     * If not found, null will be returned.
      */
     public static Conversation getCurrentInstance()
     {
@@ -360,6 +363,13 @@
             return conversation.getConversation();
         }
 
+        // see if there is a single conversation hanging around in the conversation context
+        ConversationContext cctx = ConversationManager.getInstance().getCurrentConversationContext(false);
+        if (cctx != null)
+        {
+            return cctx.getConversation(SpringSingleConversationScope.CONVERSATION_NAME);
+        }
+
         return null;
     }
 
@@ -435,7 +445,7 @@
 
     /**
      * Get the aspect corresponding to the given class.
-     * 
+     *
      * @return null if such an aspect has not been attached to this conversation
      */
     public ConversationAspect getAspect(Class conversationAspectClass)
@@ -444,8 +454,8 @@
     }
 
     /**
-     * Add an Aspect to this conversation. 
-     * 
+     * Add an Aspect to this conversation.
+     *
      * See class ConversationAspects for further details.
      */
     public void addAspect(ConversationAspect aspect)

Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringSingleConversationScope.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringSingleConversationScope.java?rev=645055&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringSingleConversationScope.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringSingleConversationScope.java Sat Apr  5 02:37:27 2008
@@ -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.myfaces.orchestra.conversation.spring;
+
+import org.apache.myfaces.orchestra.conversation.Conversation;
+import org.apache.myfaces.orchestra.conversation.ConversationContext;
+
+/**
+ * Provide a "single" conversation scope per conversationContext with the lifetime of
+ * the conversationContext it is included in.
+ * This is useful for dialog/flow driven systems where the conversationContext define
+ * the lifetime of a conversation.
+ * <br/>
+ * It is still possible to mix the various scopes.
+ *
+ * @since 1.2
+ */
+public class SpringSingleConversationScope extends AbstractSpringOrchestraScope
+{
+    // use the "magic conversation name" to mark a conversation as THE single conversation
+    // for now. Might be able to implement cleaner with Orchestra 2.
+    public final static String CONVERSATION_NAME="_oamo_single_conversation"; // NON-NLS
+
+    protected String getConversationNameForBean(String beanName) {
+        return CONVERSATION_NAME;
+    }
+
+    public Conversation createConversation(ConversationContext context, String name)
+    {
+        Conversation conversation = new Conversation(context, name, this);
+        return conversation;
+    }
+}

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringSingleConversationScope.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringSingleConversationScope.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringSingleConversationScope.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain