KickJava   Java API By Example, From Geeks To Geeks.

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


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.FacesContext;
19 import javax.faces.el.EvaluationException;
20 import javax.faces.el.VariableResolver;
21
22 /**
23  * Custom variable resolver that resolves to a thread-bound FlowExecution object
24  * for binding expressions prefixed with {@link #FLOW_SCOPE_VARIABLE}. For instance
25  * "flowScope.myBean.myProperty".
26  *
27  * @author Colin Sampaleanu
28  */

29 public class FlowVariableResolver extends VariableResolver {
30
31     /**
32      * Name of the exposed flow scope variable ("flowScope").
33      */

34     public static final String JavaDoc FLOW_SCOPE_VARIABLE = "flowScope";
35
36     /**
37      * The standard variable resolver to delegate to if this one doesn't apply.
38      */

39     private VariableResolver resolverDelegate;
40
41     /**
42      * Create a new FlowVariableResolver, using the given original
43      * VariableResolver.
44      * <p>
45      * A JSF implementation will automatically pass its original resolver into
46      * the constructor of a configured resolver, provided that there is a
47      * corresponding constructor argument.
48      *
49      * @param resolverDelegate the original VariableResolver
50      */

51     public FlowVariableResolver(VariableResolver resolverDelegate) {
52         this.resolverDelegate = resolverDelegate;
53     }
54
55     /**
56      * Return the original VariableResolver that this resolver delegates to.
57      */

58     protected final VariableResolver getResolverDelegate() {
59         return resolverDelegate;
60     }
61
62     /**
63      * Check for the special "flow" variable first, then delegate to the
64      * original VariableResolver.
65      */

66     public Object JavaDoc resolveVariable(FacesContext context, String JavaDoc name) throws EvaluationException {
67         if (!FLOW_SCOPE_VARIABLE.equals(name)) {
68             return resolverDelegate.resolveVariable(context, name);
69         }
70         else {
71             FlowExecutionHolder holder = FlowExecutionHolderUtils.getFlowExecutionHolder(context);
72             if (holder == null)
73                 throw new EvaluationException(
74                         "'flowScope' variable prefix specified, but a FlowExecution is not bound to current thread context as it should be");
75             return holder.getFlowExecution();
76         }
77     }
78 }
Popular Tags