KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > executor > jsf > FlowExecutionHolderUtils


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.springframework.webflow.executor.jsf;
17
18 import javax.faces.context.ExternalContext;
19 import javax.faces.context.FacesContext;
20
21 /**
22  * A static utility class for accessing the current flow execution holder.
23  * <p>
24  * By default, the current flow execution holder is stored associated with the
25  * current thread in the {@link FacesContext}'s
26  * {@link ExternalContext#getRequestMap()}.
27  *
28  * @author Keith Donald
29  * @author Craig McClanahan
30  */

31 public class FlowExecutionHolderUtils {
32
33     /**
34      * Returns the current flow execution holder for the given faces context.
35      * @param context faces context
36      * @return the flow execution holder, or <code>null</code> if none set.
37      */

38     public static FlowExecutionHolder getFlowExecutionHolder(FacesContext context) {
39         return (FlowExecutionHolder)context.getExternalContext().getRequestMap().get(getFlowExecutionHolderKey());
40     }
41
42     /**
43      * Sets the current flow execution holder for the given faces context.
44      * @param holder the flow execution holder
45      * @param context faces context
46      */

47     public static void setFlowExecutionHolder(FlowExecutionHolder holder, FacesContext context) {
48         context.getExternalContext().getRequestMap().put(getFlowExecutionHolderKey(), holder);
49     }
50
51     private static String JavaDoc getFlowExecutionHolderKey() {
52         return FlowExecutionHolder.class.getName();
53     }
54
55     public static boolean isFlowExecutionRestored(FacesContext context) {
56         return getFlowExecutionHolder(context) != null;
57     }
58     
59     public static boolean isFlowExecutionChanged(FacesContext context) {
60         return isFlowExecutionRestored(context) && getFlowExecutionHolder(context).needsSave();
61     }
62 }
Popular Tags