KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > engine > support > DefaultTargetStateResolver


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.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 JavaDoc 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, "The target state id expression is required");
55         this.targetStateIdExpression = targetStateIdExpression;
56     }
57
58     public State resolveTargetState(Transition transition, State sourceState, RequestContext context) {
59         String JavaDoc stateId = String.valueOf(targetStateIdExpression.evaluate(context, null));
60         return ((Flow)context.getActiveFlow()).getStateInstance(stateId);
61     }
62
63     public String JavaDoc toString() {
64         return targetStateIdExpression.toString();
65     }
66 }
Popular Tags