You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/06/24 15:56:38 UTC
svn commit: r671171 - in
/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra:
conversation/ conversation/spring/ lib/jsf/
Author: skitching
Date: Tue Jun 24 06:56:38 2008
New Revision: 671171
URL: http://svn.apache.org/viewvc?rev=671171&view=rev
Log:
* Make API backwards compatible with Orchestra 1.1
* Name change for readability: "topmost" -> "root"
* Add @since1.2 to all new methods
* comment out a few methods that are never called from anywhere (yet)
* a couple of minor method renames
* Remove method ConversationManager.getOrCreateTopmostConversationContext, which is
equivalent to getOrCreateConversationContext().getRoot()
Modified:
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContext.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.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/CurrentConversationInfo.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/AbstractSpringOrchestraScope.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/OrchestraAdvisorBeanPostProcessor.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ContextLockRequestHandler.java
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContext.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContext.java?rev=671171&r1=671170&r2=671171&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContext.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContext.java Tue Jun 24 06:56:38 2008
@@ -45,6 +45,11 @@
// This id is attached as a query parameter to every url rendered in a page
// (forms and links) so that if that url is invoked then the request will
// cause the same context to be used from the user's http session.
+ //
+ // This value is never null, but an Object is used to store it rather than
+ // a primitive long because it is used as a key into a collection of
+ // conversation contexts, and using an object here saves wrapping this
+ // value in a new object instance every time it must be used as a key.
private final Long id;
// See addAttribute
@@ -69,38 +74,67 @@
private final _ReentrantLock lock = new _ReentrantLock();
- protected ConversationContext(ConversationContext parent, Long id)
+ /**
+ * Constructor.
+ */
+ protected ConversationContext(long id)
+ {
+ this(null, id);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @since 1.2
+ */
+ protected ConversationContext(ConversationContext parent, long id)
{
this.parent = parent;
- this.id = id;
+ this.id = Long.valueOf(id);
touch();
}
/**
- * get the name associated to this context
+ * Get the name associated to this context.
+ *
+ * @since 1.2
*/
- public String getName() {
+ public String getName()
+ {
return name;
}
/**
- * a name associated with this context
+ * Assign a name to this context.
+ *
+ * @since 1.2
*/
- public void setName(String name) {
+ public void setName(String name)
+ {
this.name = name;
}
/**
* The conversation context id, unique within the current http session.
*/
- public Long getId()
+ public long getId()
+ {
+ return id.longValue();
+ }
+
+ /**
+ * The conversation context id, unique within the current http session.
+ */
+ public Long getIdAsLong()
{
return id;
}
/**
- * The parent conversation context
+ * Return the parent conversation context (if any).
+ *
+ * @since 1.2
*/
public ConversationContext getParent()
{
@@ -413,11 +447,16 @@
}
/**
- * get the topmost conversation context this conversation context is associated with
- * @return
+ * Get the root conversation context this conversation context is
+ * associated with.
+ * <p>
+ * This is equivalent to calling getParent repeatedly until a context
+ * with no parent is found.
+ *
+ * @since 1.2
*/
- public ConversationContext getTopmostConversationContext() {
-
+ public ConversationContext getRoot()
+ {
ConversationContext cctx = this;
while (cctx != null && cctx.getParent() != null)
{
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java?rev=671171&r1=671170&r2=671171&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java Tue Jun 24 06:56:38 2008
@@ -27,11 +27,9 @@
import java.io.IOException;
import java.io.ObjectStreamException;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
/**
@@ -156,7 +154,7 @@
* <p>
* The current conversationContextId will be retrieved from the request
* parameters. If no such parameter is present then a new id will be
- * allocated.
+ * allocated <i>and configured as the current conversation id</i>.
* <p>
* In either case the result will be stored within the request for
* faster lookup.
@@ -228,7 +226,6 @@
* current topmost conversation context.
*
* @since 1.2
- */
protected ConversationContext[] getConversationContexts()
{
synchronized (this)
@@ -264,6 +261,7 @@
return contexts;
}
}
+ */
/**
* Get the conversation context for the given id.
@@ -283,8 +281,11 @@
/**
* Get the conversation context for the given id.
* <p>
- * If there is no such conversation context a new one will be created. The new conversation
- * context will be a "top-level" context (ie has no parent).
+ * If there is no such conversation context a new one will be created.
+ * The new conversation context will be a "top-level" context (ie has no parent).
+ * <p>
+ * The new conversation context will <i>not</i> be the current conversation context,
+ * unless the id passed in was already configured as the current conversation context id.
*/
protected ConversationContext getOrCreateConversationContext(Long conversationContextId)
{
@@ -293,7 +294,7 @@
ConversationContext conversationContext = (ConversationContext) conversationContexts.get(conversationContextId);
if (conversationContext == null)
{
- conversationContext = new ConversationContext(null, conversationContextId);
+ conversationContext = new ConversationContext(null, conversationContextId.longValue());
conversationContexts.put(conversationContextId, conversationContext);
// TODO: add the "user" name here, otherwise this debugging is not very useful
@@ -313,7 +314,6 @@
* {@link #activateConversationContext(ConversationContext)} on the newly create context too.
*
* @since 1.2
- */
protected ConversationContext startNewConversationContext()
{
synchronized (this)
@@ -336,17 +336,19 @@
return conversationContext;
}
}
-
+*/
/**
- * Actually activate the given conversation context. This means the current conversation context will be
- * deactivated and the conversations of the passed in conversation context are those used again.
+ * Make the specific context the current context for the current HTTP session.
+ * <p>
+ * Methods like getCurrentConversationContext will then return the specified
+ * context object.
*
* @since 1.2
*/
public void activateConversationContext(ConversationContext ctx)
{
FrameworkAdapter fa = FrameworkAdapter.getCurrentInstance();
- fa.setRequestAttribute(CONVERSATION_CONTEXT_REQ, ctx.getId());
+ fa.setRequestAttribute(CONVERSATION_CONTEXT_REQ, ctx.getIdAsLong());
}
/**
@@ -453,8 +455,11 @@
}
/**
- * Get the current conversation context. In an plain Orchestra installation this will also be the tompost
- * conversation context. When using a dialog/page-flow environment this might be the bottom conversation context.
+ * Get the current conversation context.
+ * <p>
+ * In a simple Orchestra application this will always be a root conversation context.
+ * When using a dialog/page-flow environment the context that is returned might have
+ * a parent context.
* <p>
* Null is returned if there is no current conversationContext.
*/
@@ -472,7 +477,9 @@
}
/**
- * Return a ConversationContext, creating one if none currently exists.
+ * Return the current ConversationContext for the current http session;
+ * if none yet exists then a ConversationContext is created and configured
+ * as the current context.
* <p>
* This is currently package-scoped because it is not clear that code
* outside orchestra can have any use for this method. The only user
@@ -496,13 +503,13 @@
}
/**
- * Get the topmost conversation context (aka the window conversation context).
+ * Get the current root conversation context (aka the window conversation context).
* <p>
* Null is returned if it does not exist.
*
* @since 1.2
*/
- public ConversationContext getTopmostConversationContext()
+ public ConversationContext getCurrentRootConversationContext()
{
Long ccid = findConversationContextId();
if (ccid == null)
@@ -519,27 +526,12 @@
}
else
{
- return conversationContext.getTopmostConversationContext();
+ return conversationContext.getRoot();
}
}
}
/**
- * Get the topmost conversation context (aka the window conversation context).
- * <p>
- * Create it if it does not exist.
- */
- private ConversationContext getOrCreateTopmostConversationContext()
- {
- Long ccid = getOrCreateConversationContextId();
- synchronized (this)
- {
- ConversationContext conversationContext = getOrCreateConversationContext(ccid);
- return conversationContext.getTopmostConversationContext();
- }
- }
-
- /**
* Get the Messager used to inform the user about anomalies.
* <p>
* What instance is returned is controlled by the FrameworkAdapter. See
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.java?rev=671171&r1=671170&r2=671171&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.java Tue Jun 24 06:56:38 2008
@@ -85,7 +85,7 @@
// fetch the conversation context, creating one if it does not yet exist.
ConversationContext ctx = conversationManager.getOrCreateCurrentConversationContext();
- return Long.toString(ctx.getId().longValue(), Character.MAX_RADIX);
+ return Long.toString(ctx.getId(), Character.MAX_RADIX);
}
public String[] getFields()
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?rev=671171&r1=671170&r2=671171&view=diff
==============================================================================
--- 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 Tue Jun 24 06:56:38 2008
@@ -51,9 +51,9 @@
{
private final CurrentConversationInfo conversationInfo;
- public CurrentConversationAdvice(String conversationName, String beanName)
+ public CurrentConversationAdvice(Conversation conversation, String beanName)
{
- conversationInfo = new CurrentConversationInfo(conversationName, beanName);
+ conversationInfo = new CurrentConversationInfo(conversation, beanName);
}
public Object invoke(MethodInvocation methodInvocation) throws Throwable
Modified: 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?rev=671171&r1=671170&r2=671171&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/CurrentConversationInfo.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/CurrentConversationInfo.java Tue Jun 24 06:56:38 2008
@@ -21,26 +21,46 @@
import java.io.Serializable;
/**
- * Holds various info about the current conversation.
+ * Provide information about the current conversation.
+ * <p>
+ * An instance of this type is stored in a thread-local variable to indicate
+ * what the "current conversation state" is. The getConversation() method
+ * can therefore be used to determine what conversation is currently active,
+ * and getBeanName() can be used to determine what the most recently-invoked
+ * conversation-scoped-bean was. This thread-local variable is maintained
+ * via the CurrentConversationAdvice which wraps every conversation-scoped
+ * bean and intercepts all method calls to the bean.
+ * <p>
+ * This object also records the fact that a specific bean is within a
+ * specific conversation. This data is saved during serialization so
+ * that on deserialize we know which conversation to reattach which
+ * bean to./
*/
public class CurrentConversationInfo implements Serializable
{
private final String conversationName;
private final String beanName;
- //caching reference instead of doing a lookup every time
+ /**
+ * The conversation object itself is not serializable (it is a Spring proxy
+ * object with various AOP advices attached to it). Therefore this reference
+ * must be transient. After deserialisation, this member is of course null,
+ * but is recalculated on demand in the getConversation method.
+ * <p>
+ * The beans that are <i>in</i> the conversation are hopefully serializable;
+ * they are saved directly and then reattached to the new Conversation instance.
+ */
private transient Conversation conversation;
- public CurrentConversationInfo(String convName, String beanName)
+ public CurrentConversationInfo(Conversation conversation, String beanName)
{
- this.conversationName = convName;
+ this.conversation = conversation;
+ this.conversationName = conversation.getName();
this.beanName = beanName;
}
/**
* The conversation the bean is associated with.
- * Will be retrieved via its name instead of holding it directly.
- * This makes it possible to do serialization stuff.
*/
public Conversation getConversation()
{
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/AbstractSpringOrchestraScope.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/AbstractSpringOrchestraScope.java?rev=671171&r1=671170&r2=671171&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/AbstractSpringOrchestraScope.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/AbstractSpringOrchestraScope.java Tue Jun 24 06:56:38 2008
@@ -140,7 +140,7 @@
ConversationContext ctx = manager.getCurrentConversationContext();
if (ctx != null)
{
- return Long.toString(ctx.getId().longValue(), 10);
+ return Long.toString(ctx.getId(), 10);
}
return null;
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/OrchestraAdvisorBeanPostProcessor.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/OrchestraAdvisorBeanPostProcessor.java?rev=671171&r1=671170&r2=671171&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/OrchestraAdvisorBeanPostProcessor.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/OrchestraAdvisorBeanPostProcessor.java Tue Jun 24 06:56:38 2008
@@ -221,7 +221,7 @@
Advisor[] advisors = new Advisor[len];
// always add the standard CurrentConversationAdvice, and do it FIRST, so it runs first
- advisors[0] = new SimpleAdvisor(new CurrentConversationAdvice(conversation.getName(), beanName));
+ advisors[0] = new SimpleAdvisor(new CurrentConversationAdvice(conversation, beanName));
for(int i=0; i<advices.length; ++i)
{
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ContextLockRequestHandler.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ContextLockRequestHandler.java?rev=671171&r1=671170&r2=671171&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ContextLockRequestHandler.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ContextLockRequestHandler.java Tue Jun 24 06:56:38 2008
@@ -79,7 +79,7 @@
// condition because nothing else can refer to that newly created
// id until the response for this request has been sent back to the
// client browser.
- context = manager.getTopmostConversationContext();
+ context = manager.getCurrentRootConversationContext();
if (context != null)
{
try