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.engine.support;
17:
18: import org.springframework.binding.expression.Expression;
19: import org.springframework.binding.expression.support.StaticExpression;
20: import org.springframework.util.Assert;
21: import org.springframework.webflow.engine.Flow;
22: import org.springframework.webflow.engine.State;
23: import org.springframework.webflow.engine.TargetStateResolver;
24: import org.springframework.webflow.engine.Transition;
25: import org.springframework.webflow.execution.RequestContext;
26:
27: /**
28: * A transition target state resolver that evaluates an expression to resolve
29: * the target state. The default implementation.
30: *
31: * @author Keith Donald
32: */
33: public class DefaultTargetStateResolver implements TargetStateResolver {
34:
35: /**
36: * The expression for the target state identifier.
37: */
38: private Expression targetStateIdExpression;
39:
40: /**
41: * Creates a new target state resolver that always returns the same
42: * target state id.
43: * @param targetStateId the id of the target state
44: */
45: public DefaultTargetStateResolver(String targetStateId) {
46: this (new StaticExpression(targetStateId));
47: }
48:
49: /**
50: * Creates a new target state resolver.
51: * @param targetStateIdExpression the target state id expression
52: */
53: public DefaultTargetStateResolver(Expression targetStateIdExpression) {
54: Assert.notNull(targetStateIdExpression,
55: "The target state id expression is required");
56: this .targetStateIdExpression = targetStateIdExpression;
57: }
58:
59: public State resolveTargetState(Transition transition,
60: State sourceState, RequestContext context) {
61: String stateId = String.valueOf(targetStateIdExpression
62: .evaluate(context, null));
63: return ((Flow) context.getActiveFlow())
64: .getStateInstance(stateId);
65: }
66:
67: public String toString() {
68: return targetStateIdExpression.toString();
69: }
70: }
|