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: import org.springframework.webflow.execution.FlowExecution;
23:
24: /**
25: * Custom variable resolver that resolves to a thread-bound FlowExecution object for binding expressions prefixed with a
26: * {@link #FLOW_EXECUTION_VARIABLE_NAME}. For instance "flowExecution.conversationScope.myProperty".
27: *
28: * This class is designed to be used with a {@link FlowExecutionPropertyResolver}.
29: *
30: * This class is a more flexible alternative to the {@link FlowVariableResolver} which is expected to be used ONLY with
31: * a {@link FlowPropertyResolver} to resolve flow scope variables ONLY. It is more flexible because it provides access
32: * to any scope structure of a {@link FlowExecution} object.
33: *
34: * @author Keith Donald
35: */
36: public class FlowExecutionVariableResolver extends VariableResolver {
37:
38: /**
39: * Name of the flow execution variable.
40: */
41: public static final String FLOW_EXECUTION_VARIABLE_NAME = "flowExecution";
42:
43: /**
44: * The standard variable resolver to delegate to if this one doesn't apply.
45: */
46: private VariableResolver resolverDelegate;
47:
48: /**
49: * Creates a new flow executon variable resolver that resolves the current FlowExecution object.
50: * @param resolverDelegate the resolver to delegate to when the variable is not named "flowExecution".
51: */
52: public FlowExecutionVariableResolver(
53: VariableResolver resolverDelegate) {
54: this .resolverDelegate = resolverDelegate;
55: }
56:
57: /**
58: * Returns the variable resolver this resolver delegates to if necessary.
59: */
60: protected final VariableResolver getResolverDelegate() {
61: return resolverDelegate;
62: }
63:
64: public Object resolveVariable(FacesContext context, String name)
65: throws EvaluationException {
66: if (FLOW_EXECUTION_VARIABLE_NAME.equals(name)) {
67: return FlowExecutionHolderUtils
68: .getRequiredCurrentFlowExecution(context);
69: } else {
70: return resolverDelegate.resolveVariable(context, name);
71: }
72: }
73: }
|