1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jexl.util;
17
18 import java.lang.reflect.InvocationTargetException;
19
20 import org.apache.commons.jexl.util.introspection.Introspector;
21 import org.apache.commons.logging.Log;
22
23 /***
24 * Returned the value of object property when executed.
25 */
26 public class PropertyExecutor extends AbstractExecutor
27 {
28 protected Introspector introspector = null;
29
30 protected String methodUsed = null;
31
32 public PropertyExecutor(Log r, Introspector ispctr,
33 Class clazz, String property)
34 {
35 rlog = r;
36 introspector = ispctr;
37
38 discover(clazz, property);
39 }
40
41 protected void discover(Class clazz, String property)
42 {
43
44
45
46
47 try
48 {
49 char c;
50 StringBuffer sb;
51
52 Object[] params = { };
53
54
55
56
57
58
59 sb = new StringBuffer("get");
60 sb.append(property);
61
62 methodUsed = sb.toString();
63
64 method = introspector.getMethod(clazz, methodUsed, params);
65
66 if (method != null)
67 return;
68
69
70
71
72
73 sb = new StringBuffer("get");
74 sb.append(property);
75
76 c = sb.charAt(3);
77
78 if (Character.isLowerCase(c))
79 {
80 sb.setCharAt(3, Character.toUpperCase(c));
81 }
82 else
83 {
84 sb.setCharAt(3, Character.toLowerCase(c));
85 }
86
87 methodUsed = sb.toString();
88 method = introspector.getMethod(clazz, methodUsed, params);
89
90 if (method != null)
91 return;
92
93 }
94 catch(Exception e)
95 {
96 rlog.error("PROGRAMMER ERROR : PropertyExector() : " + e );
97 }
98 }
99
100
101 /***
102 * Execute method against context.
103 */
104 public Object execute(Object o)
105 throws IllegalAccessException, InvocationTargetException
106 {
107 if (method == null)
108 return null;
109
110 return method.invoke(o, null);
111 }
112 }
113
114