01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 the current FlowExecution object for binding expressions prefixed with
24: * {@link #FLOW_SCOPE_VARIABLE}. For instance "flowScope.myBean.myProperty". Designed to be used in conjunction with
25: * {@link FlowPropertyResolver} only.
26: *
27: * This class is the original flow execution variable resolver implementation introduced in Spring Web Flow's JSF
28: * support available since 1.0. In general, prefer use of {@link DelegatingFlowVariableResolver} or
29: * {@link FlowExecutionVariableResolver} to this implementation as they are both considerably more flexible.
30: *
31: * This resolver should only be used with the {@link FlowPropertyResolver} which can only resolve flow-scoped variables.
32: * May be deprecated in a future release of Spring Web Flow.
33: *
34: * @author Colin Sampaleanu
35: */
36: public class FlowVariableResolver extends VariableResolver {
37:
38: /**
39: * Name of the exposed flow scope variable ("flowScope").
40: */
41: public static final String FLOW_SCOPE_VARIABLE = "flowScope";
42:
43: /**
44: * The standard variable resolver to delegate to if this one doesn't apply.
45: */
46: private VariableResolver resolverDelegate;
47:
48: /**
49: * Create a new FlowVariableResolver, using the given original VariableResolver.
50: * <p>
51: * A JSF implementation will automatically pass its original resolver into the constructor of a configured resolver,
52: * provided that there is a corresponding constructor argument.
53: *
54: * @param resolverDelegate the original VariableResolver
55: */
56: public FlowVariableResolver(VariableResolver resolverDelegate) {
57: this .resolverDelegate = resolverDelegate;
58: }
59:
60: /**
61: * Return the original VariableResolver that this resolver delegates to.
62: */
63: protected final VariableResolver getResolverDelegate() {
64: return resolverDelegate;
65: }
66:
67: public Object resolveVariable(FacesContext context, String name)
68: throws EvaluationException {
69: if (FLOW_SCOPE_VARIABLE.equals(name)) {
70: return FlowExecutionHolderUtils
71: .getRequiredCurrentFlowExecution(context);
72: } else {
73: return resolverDelegate.resolveVariable(context, name);
74: }
75: }
76: }
|