01: /*
02: * Created on Dec 29, 2003
03: *
04: * To change the template for this generated file go to
05: * Window>Preferences>Java>Code Generation>Code and Comments
06: */
07: package org.xdev.base.xssl;
08:
09: import java.util.HashMap;
10:
11: import java.lang.reflect.*;
12:
13: /**
14: * @author AYegorov
15: *
16: * To change the template for this generated type comment go to
17: * Window>Preferences>Java>Code Generation>Code and Comments
18: */
19: public class XGetter extends XSSLReference {
20: public static final String FIELD_NAME = "field-name";
21:
22: /**
23: * @param id
24: */
25: public XGetter(String id) {
26: super (id);
27: // XXX Auto-generated constructor stub
28: }
29:
30: /**
31: * @param id
32: * @param properties
33: */
34: public XGetter(String id, HashMap properties) {
35: super (id, properties);
36: // XXX Auto-generated constructor stub
37: }
38:
39: /* (non-Javadoc)
40: * @see org.xdev.base.xssl.XSSLReference#processReference(java.lang.Object)
41: */
42: protected Object processReference(Object reference) {
43: Object value = null;
44:
45: if (reference == null) {
46: reference = this .getElement(0);
47: }
48:
49: Class cls = reference.getClass();
50:
51: String fieldName = this .getProperty(XGetter.FIELD_NAME);
52:
53: try {
54: Field field = cls.getField(fieldName);
55:
56: value = field.get(reference);
57: } catch (Exception ex) {
58: this .logDebug(ex);
59:
60: try {
61: Method method = cls.getMethod(fieldName, null);
62:
63: value = method.invoke(reference, null);
64: } catch (Exception exx) {
65: this .logDebug(exx);
66: try {
67: fieldName = "get" + fieldName;
68:
69: Method method = cls.getMethod(fieldName, null);
70:
71: value = method.invoke(reference, null);
72: } catch (Exception exxx) {
73: this.logDebug(exxx);
74: }
75: }
76: }
77:
78: return value;
79: }
80:
81: }
|