1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jexl3.internal.introspection;
18
19 import org.apache.commons.jexl3.JexlEngine;
20 import org.apache.commons.jexl3.introspection.JexlMethod;
21 import org.apache.commons.jexl3.introspection.JexlPropertyGet;
22 import org.apache.commons.jexl3.introspection.JexlPropertySet;
23
24
25
26
27
28
29
30
31 abstract class AbstractExecutor {
32
33
34
35 public abstract static class Get extends AbstractExecutor implements JexlPropertyGet {
36
37
38
39
40
41 protected Get(final Class<?> theClass, final java.lang.reflect.Method theMethod) {
42 super(theClass, theMethod);
43 }
44 }
45
46
47
48
49 public abstract static class Method extends AbstractExecutor implements JexlMethod {
50
51 protected final MethodKey key;
52
53
54
55
56
57
58
59 protected Method(final Class<?> c, final java.lang.reflect.Method m, final MethodKey k) {
60 super(c, m);
61 key = k;
62 }
63
64 @Override
65 public final Class<?> getReturnType() {
66 return method.getReturnType();
67 }
68
69 @Override
70 public Object getTargetProperty() {
71 return key;
72 }
73 }
74
75
76
77
78 public abstract static class Set extends AbstractExecutor implements JexlPropertySet {
79
80
81
82
83
84 protected Set(final Class<?> theClass, final java.lang.reflect.Method theMethod) {
85 super(theClass, theMethod);
86 }
87 }
88
89
90 public static final Object TRY_FAILED = JexlEngine.TRY_FAILED;
91
92
93
94
95
96
97 static Integer castInteger(final Object arg) {
98 return arg instanceof Number? ((Number) arg).intValue() : null;
99 }
100
101
102
103
104
105
106 static String castString(final Object arg) {
107 return arg instanceof CharSequence || arg instanceof Integer ? arg.toString() : null;
108 }
109
110
111
112
113
114
115 static Class<?> classOf(final Object instance) {
116 return instance == null ? Object.class : instance.getClass();
117 }
118
119
120
121
122
123
124
125 static java.lang.reflect.Method initMarker(final Class<?> clazz, final String name, final Class<?>... parms) {
126 try {
127 return clazz.getMethod(name, parms);
128 } catch (final Exception xnever) {
129 throw new Error(xnever);
130 }
131 }
132
133
134
135
136
137
138 static Object[] makeArgs(final Object... args) {
139 return args;
140 }
141
142
143 protected final Class<?> objectClass;
144
145
146 protected final java.lang.reflect.Method method;
147
148
149
150
151
152
153 protected AbstractExecutor(final Class<?> theClass, final java.lang.reflect.Method theMethod) {
154 objectClass = theClass;
155 method = theMethod;
156 }
157
158
159
160
161
162
163 public boolean equals(final AbstractExecutor arg) {
164
165 if (!this.getClass().equals(arg.getClass())) {
166 return false;
167 }
168 if (!getMethod().equals(arg.getMethod())) {
169 return false;
170 }
171 if (!getTargetClass().equals(arg.getTargetClass())) {
172 return false;
173 }
174
175 final Object lhsp = getTargetProperty();
176 final Object rhsp = arg.getTargetProperty();
177 if (lhsp == null && rhsp == null) {
178 return true;
179 }
180 if (lhsp != null && rhsp != null) {
181 return lhsp.equals(rhsp);
182 }
183 return false;
184 }
185
186 @Override
187 public boolean equals(final Object obj) {
188 return this == obj || obj instanceof AbstractExecutor && equals((AbstractExecutor) obj);
189 }
190
191
192
193
194
195 public final java.lang.reflect.Method getMethod() {
196 return method;
197 }
198
199
200
201
202
203 public final String getMethodName() {
204 return method.getName();
205 }
206
207
208
209
210
211 public final Class<?> getTargetClass() {
212 return objectClass;
213 }
214
215
216
217
218
219 public Object getTargetProperty() {
220 return null;
221 }
222
223 @Override
224 public int hashCode() {
225 return method.hashCode();
226 }
227
228
229
230
231
232
233
234 public final boolean isAlive() {
235 return method != null;
236 }
237
238
239
240
241
242
243
244 public boolean isCacheable() {
245 return method != null;
246 }
247
248
249
250
251
252
253 public final boolean tryFailed(final Object exec) {
254 return exec == JexlEngine.TRY_FAILED;
255 }
256 }