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 java.lang.reflect.Modifier;
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 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 name, Class variableClass,
46: ScopeType scope) {
47: super (name, scope);
48: Assert.notNull(variableClass, "The variable class is required");
49: Assert.isTrue(!variableClass.isInterface(),
50: "The variable class cannot be an interface");
51: Assert.isTrue(!Modifier
52: .isAbstract(variableClass.getModifiers()),
53: "The variable class cannot be abstract");
54: this .variableClass = variableClass;
55: }
56:
57: /**
58: * Returns the variable value class.
59: */
60: public Class getVariableClass() {
61: return variableClass;
62: }
63:
64: protected Object createVariableValue(RequestContext context) {
65: return BeanUtils.instantiateClass(variableClass);
66: }
67: }
|