From 6f6e06294ab2395ece5e5d91aee6d02cc5beedc1 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 12 Nov 2012 19:26:45 -0800 Subject: [PATCH] Make ConversationManagers easier to subclass Increased visibility of the following package scope classes: - ContainedConversation - ConversationContainer - JdkConcurrentConversationLock - NoOpConversationLock Provided additional hook methods and accessors for subclasses. Issue: SWF-756 --- .../conversation/impl/ContainedConversation.java | 12 ++++++++++-- .../conversation/impl/ConversationContainer.java | 14 ++++++++++++-- .../impl/JdkConcurrentConversationLock.java | 4 ++-- .../conversation/impl/NoOpConversationLock.java | 4 ++-- .../impl/SessionBindingConversationManager.java | 4 +--- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/ContainedConversation.java b/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/ContainedConversation.java index ef8aae75..8edd5fd8 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/ContainedConversation.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/ContainedConversation.java @@ -33,7 +33,7 @@ import org.springframework.webflow.core.collection.SharedAttributeMap; * * @author Erwin Vervaet */ -class ContainedConversation implements Conversation, Serializable { +public class ContainedConversation implements Conversation, Serializable { private static final Log logger = LogFactory.getLog(SessionBindingConversationManager.class); @@ -58,8 +58,16 @@ class ContainedConversation implements Conversation, Serializable { this.attributes = new HashMap(); } + protected void setContainer(ConversationContainer container) { + this.container = container; + } + public ConversationId getId() { - return id; + return this.id; + } + + protected void setId(ConversationId id) { + this.id = id; } public void lock() { diff --git a/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/ConversationContainer.java b/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/ConversationContainer.java index 67cd01ab..51284cfa 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/ConversationContainer.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/ConversationContainer.java @@ -35,7 +35,7 @@ import org.springframework.webflow.conversation.NoSuchConversationException; * * @author Erwin Vervaet */ -class ConversationContainer implements Serializable { +public class ConversationContainer implements Serializable { private static final Log logger = LogFactory.getLog(ConversationContainer.class); @@ -91,7 +91,7 @@ class ConversationContainer implements Serializable { * @return the created conversation */ public synchronized Conversation createConversation(ConversationParameters parameters, ConversationLock lock) { - ContainedConversation conversation = new ContainedConversation(this, nextId(), lock); + ContainedConversation conversation = createContainedConversation(nextId(), lock); conversation.putAttribute("name", parameters.getName()); conversation.putAttribute("caption", parameters.getCaption()); conversation.putAttribute("description", parameters.getDescription()); @@ -126,6 +126,10 @@ class ConversationContainer implements Serializable { throw new NoSuchConversationException(id); } + protected final List getConversations() { + return conversations; + } + /** * Remove identified conversation from this container. */ @@ -145,4 +149,10 @@ class ConversationContainer implements Serializable { private boolean maxExceeded() { return maxConversations > 0 && conversations.size() > maxConversations; } + + // Hook methods + + protected ContainedConversation createContainedConversation(ConversationId id, ConversationLock lock) { + return new ContainedConversation(this, id, lock); + } } diff --git a/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/JdkConcurrentConversationLock.java b/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/JdkConcurrentConversationLock.java index 893b2db1..621e7be6 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/JdkConcurrentConversationLock.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/JdkConcurrentConversationLock.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2008 the original author or authors. + * Copyright 2004-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ import org.springframework.webflow.conversation.ConversationLockException; * * @author Keith Donald */ -class JdkConcurrentConversationLock implements ConversationLock { +public class JdkConcurrentConversationLock implements ConversationLock { private Lock lock = new ReentrantLock(); diff --git a/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/NoOpConversationLock.java b/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/NoOpConversationLock.java index a7a30f3d..9e6cf5f4 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/NoOpConversationLock.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/NoOpConversationLock.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2008 the original author or authors. + * Copyright 2004-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import java.io.ObjectStreamException; * * @author Keith Donald */ -class NoOpConversationLock implements ConversationLock { +public class NoOpConversationLock implements ConversationLock { /** * The singleton instance. diff --git a/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/SessionBindingConversationManager.java b/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/SessionBindingConversationManager.java index d5d73a24..bdd500e1 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/SessionBindingConversationManager.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/SessionBindingConversationManager.java @@ -131,13 +131,11 @@ public class SessionBindingConversationManager implements ConversationManager { return new ConversationContainer(maxConversations, sessionKey); } - // internal helpers - /** * Obtain the conversation container from the session. Create a new empty container and add it to the session if no * existing container can be found. */ - private ConversationContainer getConversationContainer() { + protected final ConversationContainer getConversationContainer() { SharedAttributeMap sessionMap = ExternalContextHolder.getExternalContext().getSessionMap(); synchronized (sessionMap.getMutex()) { ConversationContainer container = (ConversationContainer) sessionMap.get(sessionKey);