From c4f5d913431e09fc73402aa6f8e418ed0eabaae0 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Fri, 4 May 2007 18:58:13 +0000 Subject: [PATCH] SWF-163 polishing - JSF cleanup methods --- .../jsf/FlowExecutionHolderUtils.java | 29 ++++++++++++------- .../executor/jsf/FlowNavigationHandler.java | 6 ++-- .../executor/jsf/FlowPhaseListener.java | 4 +-- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/spring-webflow/src/main/java/org/springframework/webflow/executor/jsf/FlowExecutionHolderUtils.java b/spring-webflow/src/main/java/org/springframework/webflow/executor/jsf/FlowExecutionHolderUtils.java index 42416dc5..6e7d7490 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/executor/jsf/FlowExecutionHolderUtils.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/executor/jsf/FlowExecutionHolderUtils.java @@ -25,8 +25,9 @@ import org.springframework.webflow.execution.FlowExecutionContextHolder; /** * A static utility class for accessing the current flow execution holder. *

- * By default, the current flow execution holder is stored associated with the current thread in the - * {@link FacesContext}'s {@link ExternalContext#getRequestMap()}. + * By default, the current flow execution holder is associated with the + * current thread via the {@link FacesContext}'s + * {@link ExternalContext#getRequestMap()}. * * @author Keith Donald * @author Craig McClanahan @@ -53,7 +54,8 @@ public class FlowExecutionHolderUtils { } /** - * Returns true if the flow execution has been restored in the current thread. + * Returns true if the flow execution has been restored in the current + * thread. * @param context the faces context * @return true if restored, false otherwise */ @@ -64,17 +66,19 @@ public class FlowExecutionHolderUtils { /** * Returns the current flow execution in the given faces context. * @param context faces context - * @return the flow execution or null if no execution is bound + * @return the flow execution or null if no execution is + * bound */ public static FlowExecution getCurrentFlowExecution(FacesContext context) { FlowExecutionHolder holder = getFlowExecutionHolder(context); if (holder != null) { return holder.getFlowExecution(); - } else { + } + else { return null; } } - + /** * Returns the current required flow execution in the given faces context. * @param context faces context @@ -94,16 +98,21 @@ public class FlowExecutionHolderUtils { } /** - * Unlocks the current flow execution in the faces context if necessary. - * Can be safely called even if no execution is bound or one is bound but not locked. + * Cleans up the current flow execution in the faces context if necessary. + * Specifically, handles unlocking the execution if necessary, setting the + * holder to null, and cleaning up the flow execution context thread local. + * Can be safely called even if no execution is bound or one is bound but + * not locked. * @param context the faces context */ - public static void unlockCurrentFlowExecutionIfNecessary(FacesContext context) { + public static void cleanupCurrentFlowExecution(FacesContext context) { if (isFlowExecutionRestored(context)) { getFlowExecutionHolder(context).unlockFlowExecutionIfNecessary(); + FlowExecutionContextHolder.setFlowExecutionContext(null); + context.getExternalContext().getRequestMap().remove(getFlowExecutionHolderKey()); } } - + private static String getFlowExecutionHolderKey() { return FlowExecutionHolder.class.getName(); } diff --git a/spring-webflow/src/main/java/org/springframework/webflow/executor/jsf/FlowNavigationHandler.java b/spring-webflow/src/main/java/org/springframework/webflow/executor/jsf/FlowNavigationHandler.java index c3f52e27..a38f2a74 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/executor/jsf/FlowNavigationHandler.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/executor/jsf/FlowNavigationHandler.java @@ -30,7 +30,6 @@ import org.springframework.webflow.definition.FlowDefinition; import org.springframework.webflow.definition.registry.FlowDefinitionLocator; import org.springframework.webflow.engine.NoMatchingTransitionException; import org.springframework.webflow.execution.FlowExecution; -import org.springframework.webflow.execution.FlowExecutionContextHolder; import org.springframework.webflow.execution.FlowExecutionFactory; import org.springframework.webflow.execution.ViewSelection; import org.springframework.webflow.executor.RequestParameterInputMapper; @@ -246,9 +245,8 @@ public class FlowNavigationHandler extends DecoratingNavigationHandler { private void cleanupResources(FacesContext context) { if (logger.isDebugEnabled()) { logger.debug("Cleaning up allocated flow system resources"); - } - FlowExecutionContextHolder.setFlowExecutionContext(null); - FlowExecutionHolderUtils.unlockCurrentFlowExecutionIfNecessary(context); + } + FlowExecutionHolderUtils.cleanupCurrentFlowExecution(context); ExternalContextHolder.setExternalContext(null); } } \ No newline at end of file diff --git a/spring-webflow/src/main/java/org/springframework/webflow/executor/jsf/FlowPhaseListener.java b/spring-webflow/src/main/java/org/springframework/webflow/executor/jsf/FlowPhaseListener.java index 8573ca2f..02c02817 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/executor/jsf/FlowPhaseListener.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/executor/jsf/FlowPhaseListener.java @@ -36,7 +36,6 @@ import org.springframework.webflow.core.collection.MutableAttributeMap; import org.springframework.webflow.definition.FlowDefinition; import org.springframework.webflow.definition.registry.FlowDefinitionLocator; import org.springframework.webflow.execution.FlowExecution; -import org.springframework.webflow.execution.FlowExecutionContextHolder; import org.springframework.webflow.execution.FlowExecutionFactory; import org.springframework.webflow.execution.ViewSelection; import org.springframework.webflow.execution.repository.FlowExecutionAccessException; @@ -482,8 +481,7 @@ public class FlowPhaseListener implements PhaseListener { if (logger.isDebugEnabled()) { logger.debug("Cleaning up allocated flow system resources"); } - FlowExecutionContextHolder.setFlowExecutionContext(null); - FlowExecutionHolderUtils.unlockCurrentFlowExecutionIfNecessary(context); + FlowExecutionHolderUtils.cleanupCurrentFlowExecution(context); ExternalContextHolder.setExternalContext(null); }