KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.Modifier JavaDoc;
19
20 import org.springframework.beans.BeanUtils;
21 import org.springframework.util.Assert;
22 import org.springframework.webflow.engine.FlowVariable;
23 import org.springframework.webflow.execution.RequestContext;
24 import org.springframework.webflow.execution.ScopeType;
25
26 /**
27  * A trivial concrete flow variable subclass that creates new variable values
28  * using Java reflection.
29  *
30  * @author Keith Donald
31  */

32 public class SimpleFlowVariable extends FlowVariable {
33
34     /**
35      * The concrete variable value class.
36      */

37     private Class JavaDoc variableClass;
38
39     /**
40      * Creates a new simple flow variable.
41      * @param name the variable name
42      * @param variableClass the concrete variable class
43      * @param scope the variable scope
44      */

45     public SimpleFlowVariable(String JavaDoc name, Class JavaDoc variableClass, ScopeType scope) {
46         super(name, scope);
47         Assert.notNull(variableClass, "The variable class is required");
48         Assert.isTrue(!variableClass.isInterface(), "The variable class cannot be an interface");
49         Assert.isTrue(!Modifier.isAbstract(variableClass.getModifiers()), "The variable class cannot be abstract");
50         this.variableClass = variableClass;
51     }
52
53     /**
54      * Returns the variable value class.
55      */

56     public Class JavaDoc getVariableClass() {
57         return variableClass;
58     }
59
60     protected Object JavaDoc createVariableValue(RequestContext context) {
61         return BeanUtils.instantiateClass(variableClass);
62     }
63 }
Popular Tags