01: /*
02: * Created on Mar 19, 2004
03: */
04: package net.sourceforge.orbroker;
05:
06: import java.lang.reflect.InvocationTargetException;
07: import java.lang.reflect.Method;
08:
09: /**
10: * @author Nils Kilden-Pedersen
11: */
12: abstract class SetterMethod extends ArgumentsMember implements Setter {
13: protected SetterMethod(Method setMethod) {
14: super (setMethod);
15: }
16:
17: private Method getMethod() {
18: return (Method) getMember();
19: }
20:
21: final Class[] getParameterTypes() {
22: return getMethod().getParameterTypes();
23: }
24:
25: /**
26: * Set value
27: * @param resultObject
28: * @param row
29: */
30: public final void setValue(Object resultObject, ResultRow row) {
31: Method setMethod = getMethod();
32: ArgumentList parmList = getArgumentList();
33: Object[] parmObjects = parmList.getArgumentValues(row);
34: try {
35: setMethod.invoke(resultObject, parmObjects);
36: } catch (InvocationTargetException e) {
37: throw new ReflectionException(e.getTargetException());
38: } catch (NullPointerException e) {
39: Class[] parmTypes = setMethod.getParameterTypes();
40: for (int i = 0; i < parmTypes.length; i++) {
41: if (parmTypes[i].isPrimitive()
42: && parmObjects[i] == null) {
43: String msg = "Cannot assign 'null' using method '"
44: + setMethod.toString() + "' on argument "
45: + (i + 1) + " of type '" + parmTypes[i]
46: + "'";
47: throw new ReflectionException(msg, e);
48: }
49: }
50: throw e;
51: } catch (Exception e) {
52: String msg = "Cannot invoke method: " + setMethod;
53: throw new ReflectionException(msg, e);
54: }
55: }
56: }
|