SWF-163 polishing - JSF cleanup methods

This commit is contained in:
Keith Donald
2007-05-04 18:58:13 +00:00
parent f31f070947
commit c4f5d91343
3 changed files with 22 additions and 17 deletions

View File

@@ -25,8 +25,9 @@ import org.springframework.webflow.execution.FlowExecutionContextHolder;
/**
* A static utility class for accessing the current flow execution holder.
* <p>
* 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 <code>null</code> if no execution is bound
* @return the flow execution or <code>null</code> 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();
}

View File

@@ -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);
}
}

View File

@@ -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);
}