01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.injection.internal;
16:
17: import java.lang.reflect.Method;
18:
19: import org.strecks.exceptions.ApplicationRuntimeException;
20: import org.strecks.util.Assert;
21: import org.strecks.util.PropertyValueSetter;
22:
23: /**
24: * This class has the responsibility of performing the actual binding on the target property using
25: * the Object returned from the invocation of <code>InjectionHandler.getValue(actionContext)</code>
26: * @author Phil Zoio
27: */
28: public class InjectionSetter {
29:
30: private String propertyName;
31:
32: private String methodName;
33:
34: private Method setterMethod;
35:
36: private Class type;
37:
38: public InjectionSetter(Class hostClass, String methodName,
39: String propertyName, Class type) {
40:
41: super ();
42:
43: Assert.notNull(hostClass);
44: Assert.notNull(methodName);
45: Assert.notNull(propertyName);
46: Assert.notNull(type);
47:
48: this .methodName = methodName;
49: this .propertyName = propertyName;
50: this .type = type;
51:
52: // create setter method
53: try {
54: setterMethod = hostClass.getMethod(methodName,
55: new Class[] { type });
56: } catch (Exception e) {
57: // quite a few exceptions we can have here
58: throw new ApplicationRuntimeException(
59: "Application error: could not get method "
60: + methodName + " from host class "
61: + hostClass.getName());
62: }
63:
64: }
65:
66: public void setInput(Object targetBean, Object converted) {
67: PropertyValueSetter.setPropertyValue(targetBean, setterMethod,
68: type, converted);
69: }
70:
71: public String getMethodName() {
72: return methodName;
73: }
74:
75: public String getPropertyName() {
76: return propertyName;
77: }
78:
79: public Class getType() {
80: return type;
81: }
82:
83: }
|