01: /*
02: * Created on Feb 23, 2004
03: */
04: package net.sourceforge.orbroker;
05:
06: import java.lang.reflect.Constructor;
07:
08: import net.kildenpedersen.reflect.Reflector;
09:
10: /**
11: * @author Nils Kilden-Pedersen
12: */
13: class ResultObjectConstructor extends ResultObjectInstantiator {
14:
15: private static Constructor buildConstructor(Class type,
16: ArgumentList parameters) {
17: parameters.close();
18: Class[] parmClasses = parameters.getArgumentTypes();
19: Constructor constructor = Reflector.getAccessibleConstructor(
20: type, parmClasses);
21: if (constructor != null) {
22: return constructor;
23: }
24: String msg = "Unknown constructor: "
25: + Reflector.getClassName(type) + parameters.toString();
26: throw new ConfigurationException(msg);
27: }
28:
29: ResultObjectConstructor(Class type, ArgumentList parameters) {
30: super (buildConstructor(type, parameters), parameters);
31: }
32:
33: private Constructor getConstructor() {
34: return (Constructor) getMember();
35: }
36:
37: /**
38: * Get new instance.
39: * @param row
40: * @return result object
41: */
42: Object newInstance(ResultRow row) {
43: Object[] parmObjects = this .getArgumentList()
44: .getArgumentValues(row);
45: try {
46: return getConstructor().newInstance(parmObjects);
47: } catch (Exception e) {
48: String msg = "Cannot construct "
49: + Reflector.getClassName(getConstructor()
50: .getDeclaringClass());
51: throw new ReflectionException(msg, e);
52: }
53: }
54:
55: /**
56: * @inheritDoc
57: * @see net.sourceforge.orbroker.ResultObjectInstantiator#copy(Class)
58: */
59: ResultObjectInstantiator copy(Class forType) {
60: return new ResultObjectConstructor(forType, getArgumentList());
61: }
62: }
|