KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > engine > FlowVariable


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;
17
18 import java.io.Serializable JavaDoc;
19
20 import org.springframework.core.style.ToStringCreator;
21 import org.springframework.util.Assert;
22 import org.springframework.webflow.execution.RequestContext;
23 import org.springframework.webflow.execution.ScopeType;
24
25 /**
26  * A value object that defines a specification for a flow variable. Encapsulates
27  * information about the variable and the behavior necessary to create a new
28  * variable instance in a flow execution scope.
29  *
30  * @author Keith Donald
31  */

32 public abstract class FlowVariable extends AnnotatedObject implements Serializable JavaDoc {
33
34     /**
35      * The variable name.
36      */

37     private String JavaDoc name;
38
39     /**
40      * The variable scope.
41      */

42     private ScopeType scope;
43
44     /**
45      * Creates a new flow variable.
46      * @param name the variable name
47      * @param scope the variable scope type
48      */

49     public FlowVariable(String JavaDoc name, ScopeType scope) {
50         Assert.hasText(name, "The variable name is required");
51         Assert.notNull(scope, "The variable scope type is required");
52         this.name = name;
53         this.scope = scope;
54     }
55
56     /**
57      * Returns the name of this variable.
58      */

59     public String JavaDoc getName() {
60         return name;
61     }
62
63     /**
64      * Returns the scope of this variable.
65      */

66     public ScopeType getScope() {
67         return scope;
68     }
69     
70     // name and scope based equality
71

72     public boolean equals(Object JavaDoc o) {
73         if (!(o instanceof FlowVariable)) {
74             return false;
75         }
76         FlowVariable other = (FlowVariable)o;
77         return name.equals(other.name) && scope.equals(other.scope);
78     }
79
80     public int hashCode() {
81         return name.hashCode() + scope.hashCode();
82     }
83
84     /**
85      * Creates a new instance of this flow variable in the configured scope.
86      * @param context the flow execution request context
87      */

88     public final void create(RequestContext context) {
89         scope.getScope(context).put(name, createVariableValue(context));
90     }
91
92     /**
93      * Hook method that needs to be implemented by subclasses to calculate the
94      * value of this flow variable based on the information available in the
95      * request context.
96      * @param context the flow execution request context
97      * @return the flow variable value
98      */

99     protected abstract Object JavaDoc createVariableValue(RequestContext context);
100
101     public String JavaDoc toString() {
102         return new ToStringCreator(this).append("name", name).append("scope", scope).toString();
103     }
104 }
Popular Tags