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 XSetter extends XSSLReference {
20: /**
21: * @param id
22: */
23: public XSetter(String id) {
24: super (id);
25: // XXX Auto-generated constructor stub
26: }
27:
28: /**
29: * @param id
30: * @param properties
31: */
32: public XSetter(String id, HashMap properties) {
33: super (id, properties);
34: // XXX Auto-generated constructor stub
35: }
36:
37: /* (non-Javadoc)
38: * @see org.xdev.base.xssl.XSSLReference#processReference(java.lang.Object)
39: */
40: protected Object processReference(Object reference)
41: throws Exception {
42: XSSLReturn val = (XSSLReturn) this .getElement(0);
43:
44: Object value = null;
45:
46: if (val.execute()) {
47: value = val.getObjectValue();
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: field.set(reference, value);
56: } catch (Exception ex) {
57: this .logDebug(ex);
58:
59: try {
60: fieldName = "set" + fieldName;
61:
62: Method method = cls.getMethod(fieldName,
63: new Class[] { value.getClass() });
64:
65: method.invoke(reference, new Object[] { value });
66: } catch (Exception exx) {
67: this.logDebug(exx);
68: }
69: }
70: }
71:
72: return value;
73: }
74:
75: }
|