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 2007/08/12 20:40:50 UTC
svn commit: r565109 - in /myfaces/orchestra/trunk:
core/src/main/java/org/apache/myfaces/orchestra/conversation/
core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/
examples/src/main/java/org/apache/myfaces/examples/annotations/
Author: imario
Date: Sun Aug 12 11:40:49 2007
New Revision: 565109
URL: http://svn.apache.org/viewvc?view=rev&rev=565109
Log:
enhanced currentConversationAdvice to allow access to the "current" bean name
added ConversationUtils.invalidateAndRestartCurrent()
Added:
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/CurrentConversationInfo.java
Removed:
myfaces/orchestra/trunk/examples/src/main/java/org/apache/myfaces/examples/annotations/MutliViewController.java
Modified:
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/Conversation.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationUtils.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/CurrentConversationAdvice.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringConversationScope.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?view=diff&rev=565109&r1=565108&r2=565109
==============================================================================
--- 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 Sun Aug 12 11:40:49 2007
@@ -292,24 +292,40 @@
*/
public static Conversation getCurrentInstance()
{
- Conversation conversation = (Conversation) CURRENT_CONVERSATION.get();
+ CurrentConversationInfo conversation = getCurrentInstanceInfo();
if (conversation != null)
{
- conversation.touch();
+ return conversation.getConversation();
}
- return conversation;
+
+ return null;
}
/**
- * Sets the current conversation instance.
+ * Sets info about the current conversation instance.
* <p>
* This method is only expected to be called by CurrentConversationAdvice.invoke,
* which ensures that the current instance is reset to null as soon as no bean
* in the call-stack is within a conversation.
*/
- static void setCurrentInstance(Conversation conversation)
+ static void setCurrentInstance(CurrentConversationInfo conversation)
{
CURRENT_CONVERSATION.set(conversation);
+ }
+
+ /**
+ * Returns the info about the current conversation
+ */
+ static CurrentConversationInfo getCurrentInstanceInfo()
+ {
+ CurrentConversationInfo conversationInfo = (CurrentConversationInfo) CURRENT_CONVERSATION.get();
+ if (conversationInfo != null && conversationInfo.getConversation() != null)
+ {
+ conversationInfo.getConversation().touch();
+ return conversationInfo;
+ }
+
+ return null;
}
/**
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationUtils.java?view=diff&rev=565109&r1=565108&r2=565109
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationUtils.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationUtils.java Sun Aug 12 11:40:49 2007
@@ -52,6 +52,21 @@
}
/**
+ * <p>This will end and restart the current conversation</p>
+ * <p>In contrast to {@link #invalidateAndRestart(Conversation)} this
+ * method returns a new instance of the "current bean".</p>
+ */
+ public static Object invalidateAndRestartCurrent()
+ {
+ CurrentConversationInfo currentConversationInfo = Conversation.getCurrentInstanceInfo();
+ String name = currentConversationInfo.getBeanName();
+
+ currentConversationInfo.getConversation().invalidateAndRestart();
+
+ return FrameworkAdapter.getInstance().getBean(name);
+ }
+
+ /**
* <p>if no conversation with name <code>conversationName</code> is active a redirect to
* <code>redirectViewId</code> will be issued.</p>
* <p>If <code>redirectViewId</code> starts with an slash ('/') the context path will be added</p>
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/CurrentConversationAdvice.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/CurrentConversationAdvice.java?view=diff&rev=565109&r1=565108&r2=565109
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/CurrentConversationAdvice.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/CurrentConversationAdvice.java Sun Aug 12 11:40:49 2007
@@ -41,25 +41,25 @@
*/
public class CurrentConversationAdvice implements MethodInterceptor
{
- private final Conversation conversation;
+ private final CurrentConversationInfo conversationInfo;
- public CurrentConversationAdvice(Conversation conversation)
+ public CurrentConversationAdvice(Conversation conversation, String beanName)
{
- this.conversation = conversation;
+ conversationInfo = new CurrentConversationInfo(conversation, beanName);
}
public Object invoke(MethodInvocation methodInvocation) throws Throwable
{
// Save the current conversation so it can be restored later.
// Note that for "top-level" calls, the saved value is null.
- Conversation previous = Conversation.getCurrentInstance();
+ CurrentConversationInfo previous = Conversation.getCurrentInstanceInfo();
// Set the appropriate conversation for the target object.
- Conversation.setCurrentInstance(conversation);
+ Conversation.setCurrentInstance(conversationInfo);
try
{
- conversation.enterConversation();
+ conversationInfo.getConversation().enterConversation();
return methodInvocation.proceed();
}
@@ -69,11 +69,11 @@
// Do this before anything else in case other methods throw exceptions.
Conversation.setCurrentInstance(previous);
- conversation.leaveConversation();
+ conversationInfo.getConversation().leaveConversation();
- if (conversation.isQueueInvalid())
+ if (conversationInfo.getConversation().isQueueInvalid())
{
- conversation.invalidate();
+ conversationInfo.getConversation().invalidate();
}
}
}
Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/CurrentConversationInfo.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/CurrentConversationInfo.java?view=auto&rev=565109
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/CurrentConversationInfo.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/CurrentConversationInfo.java Sun Aug 12 11:40:49 2007
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+/**
+ * holds various infos about the current conversation
+ */
+public class CurrentConversationInfo
+{
+ private final Conversation conversation;
+ private final String beanName;
+
+ public CurrentConversationInfo(Conversation conversation, String beanName)
+ {
+ this.conversation = conversation;
+ this.beanName = beanName;
+ }
+
+ /**
+ * the conversation the bean is associated with
+ */
+ public Conversation getConversation()
+ {
+ return conversation;
+ }
+
+ /**
+ * the bean name
+ */
+ public String getBeanName()
+ {
+ return beanName;
+ }
+}
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringConversationScope.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringConversationScope.java?view=diff&rev=565109&r1=565108&r2=565109
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringConversationScope.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/SpringConversationScope.java Sun Aug 12 11:40:49 2007
@@ -142,7 +142,7 @@
ProxyFactory factory = new ProxyFactory(value);
factory.setProxyTargetClass(true);
- factory.addAdvice(new CurrentConversationAdvice(conversation));
+ factory.addAdvice(new CurrentConversationAdvice(conversation, beanName));
if (advices != null && advices.length > 0)
{