|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.enhance; |
|
16 |
| |
|
17 |
| import java.beans.BeanInfo; |
|
18 |
| import java.beans.IntrospectionException; |
|
19 |
| import java.beans.Introspector; |
|
20 |
| import java.beans.PropertyDescriptor; |
|
21 |
| import java.lang.reflect.Constructor; |
|
22 |
| import java.lang.reflect.Method; |
|
23 |
| import java.lang.reflect.Modifier; |
|
24 |
| import java.util.ArrayList; |
|
25 |
| import java.util.HashMap; |
|
26 |
| import java.util.HashSet; |
|
27 |
| import java.util.Iterator; |
|
28 |
| import java.util.List; |
|
29 |
| import java.util.Map; |
|
30 |
| import java.util.Set; |
|
31 |
| |
|
32 |
| import org.apache.commons.logging.Log; |
|
33 |
| import org.apache.hivemind.ApplicationRuntimeException; |
|
34 |
| import org.apache.hivemind.ClassResolver; |
|
35 |
| import org.apache.hivemind.HiveMind; |
|
36 |
| import org.apache.hivemind.Location; |
|
37 |
| import org.apache.hivemind.service.BodyBuilder; |
|
38 |
| import org.apache.hivemind.service.ClassFab; |
|
39 |
| import org.apache.hivemind.service.ClassFactory; |
|
40 |
| import org.apache.hivemind.service.MethodSignature; |
|
41 |
| import org.apache.hivemind.util.Defense; |
|
42 |
| import org.apache.hivemind.util.ToStringBuilder; |
|
43 |
| import org.apache.tapestry.services.ComponentConstructor; |
|
44 |
| import org.apache.tapestry.spec.IComponentSpecification; |
|
45 |
| import org.apache.tapestry.util.IdAllocator; |
|
46 |
| import org.apache.tapestry.util.ObjectIdentityMap; |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| public class EnhancementOperationImpl implements EnhancementOperation |
|
57 |
| { |
|
58 |
| private ClassResolver _resolver; |
|
59 |
| |
|
60 |
| private IComponentSpecification _specification; |
|
61 |
| |
|
62 |
| private Class _baseClass; |
|
63 |
| |
|
64 |
| private ClassFab _classFab; |
|
65 |
| |
|
66 |
| private final Set _claimedProperties = new HashSet(); |
|
67 |
| |
|
68 |
| private final JavaClassMapping _javaClassMapping = new JavaClassMapping(); |
|
69 |
| |
|
70 |
| private final List _constructorTypes = new ArrayList(); |
|
71 |
| |
|
72 |
| private final List _constructorArguments = new ArrayList(); |
|
73 |
| |
|
74 |
| private final ObjectIdentityMap _finalFields = new ObjectIdentityMap(); |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| private Set _addedInterfaces = new HashSet(); |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| private Map _incompleteMethods = new HashMap(); |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| private Map _properties = new HashMap(); |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| private BodyBuilder _constructorBuilder; |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| private final IdAllocator _idAllocator = new IdAllocator(); |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| private final Map _methods = new HashMap(); |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
| private final Log _log; |
|
116 |
| |
|
117 |
1809
| public EnhancementOperationImpl(ClassResolver classResolver,
|
|
118 |
| IComponentSpecification specification, Class baseClass, ClassFactory classFactory, |
|
119 |
| Log log) |
|
120 |
| { |
|
121 |
1809
| Defense.notNull(classResolver, "classResolver");
|
|
122 |
1809
| Defense.notNull(specification, "specification");
|
|
123 |
1809
| Defense.notNull(baseClass, "baseClass");
|
|
124 |
1809
| Defense.notNull(classFactory, "classFactory");
|
|
125 |
| |
|
126 |
1809
| _resolver = classResolver;
|
|
127 |
1809
| _specification = specification;
|
|
128 |
1809
| _baseClass = baseClass;
|
|
129 |
| |
|
130 |
1809
| introspectBaseClass();
|
|
131 |
| |
|
132 |
1809
| String name = newClassName();
|
|
133 |
| |
|
134 |
1809
| _classFab = classFactory.newClass(name, _baseClass);
|
|
135 |
1809
| _log = log;
|
|
136 |
| } |
|
137 |
| |
|
138 |
0
| public String toString()
|
|
139 |
| { |
|
140 |
0
| ToStringBuilder builder = new ToStringBuilder(this);
|
|
141 |
| |
|
142 |
0
| builder.append("baseClass", _baseClass.getName());
|
|
143 |
0
| builder.append("claimedProperties", _claimedProperties);
|
|
144 |
0
| builder.append("classFab", _classFab);
|
|
145 |
| |
|
146 |
0
| return builder.toString();
|
|
147 |
| } |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
| |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
1809
| private void introspectBaseClass()
|
|
159 |
| { |
|
160 |
1809
| try
|
|
161 |
| { |
|
162 |
1809
| synchronized (HiveMind.INTROSPECTOR_MUTEX)
|
|
163 |
| { |
|
164 |
1809
| addPropertiesDeclaredInBaseClass();
|
|
165 |
| } |
|
166 |
| } |
|
167 |
| catch (IntrospectionException ex) |
|
168 |
| { |
|
169 |
0
| throw new ApplicationRuntimeException(EnhanceMessages.unabelToIntrospectClass(
|
|
170 |
| _baseClass, |
|
171 |
| ex), ex); |
|
172 |
| } |
|
173 |
| |
|
174 |
| } |
|
175 |
| |
|
176 |
1809
| private void addPropertiesDeclaredInBaseClass() throws IntrospectionException
|
|
177 |
| { |
|
178 |
1809
| Class introspectClass = _baseClass;
|
|
179 |
| |
|
180 |
1809
| addPropertiesDeclaredInClass(introspectClass);
|
|
181 |
| |
|
182 |
1809
| List interfaceQueue = new ArrayList();
|
|
183 |
| |
|
184 |
1809
| while (introspectClass != null)
|
|
185 |
| { |
|
186 |
8805
| addInterfacesToQueue(introspectClass, interfaceQueue);
|
|
187 |
| |
|
188 |
8805
| introspectClass = introspectClass.getSuperclass();
|
|
189 |
| } |
|
190 |
| |
|
191 |
1809
| while (!interfaceQueue.isEmpty())
|
|
192 |
| { |
|
193 |
19485
| Class interfaceClass = (Class) interfaceQueue.remove(0);
|
|
194 |
| |
|
195 |
19485
| addPropertiesDeclaredInClass(interfaceClass);
|
|
196 |
| |
|
197 |
19485
| addInterfacesToQueue(interfaceClass, interfaceQueue);
|
|
198 |
| } |
|
199 |
| } |
|
200 |
| |
|
201 |
28290
| private void addInterfacesToQueue(Class introspectClass, List interfaceQueue)
|
|
202 |
| { |
|
203 |
28290
| Class[] interfaces = introspectClass.getInterfaces();
|
|
204 |
| |
|
205 |
28290
| for (int i = 0; i < interfaces.length; i++)
|
|
206 |
19485
| interfaceQueue.add(interfaces[i]);
|
|
207 |
| } |
|
208 |
| |
|
209 |
21294
| private void addPropertiesDeclaredInClass(Class introspectClass) throws IntrospectionException
|
|
210 |
| { |
|
211 |
21294
| BeanInfo bi = Introspector.getBeanInfo(introspectClass);
|
|
212 |
| |
|
213 |
21294
| PropertyDescriptor[] pds = bi.getPropertyDescriptors();
|
|
214 |
| |
|
215 |
21294
| for (int i = 0; i < pds.length; i++)
|
|
216 |
| { |
|
217 |
121050
| PropertyDescriptor pd = pds[i];
|
|
218 |
| |
|
219 |
121050
| String name = pd.getName();
|
|
220 |
| |
|
221 |
121050
| if (!_properties.containsKey(name))
|
|
222 |
48648
| _properties.put(name, pd);
|
|
223 |
| } |
|
224 |
| } |
|
225 |
| |
|
226 |
| |
|
227 |
| |
|
228 |
| |
|
229 |
| |
|
230 |
| |
|
231 |
3
| EnhancementOperationImpl()
|
|
232 |
| { |
|
233 |
3
| _log = null;
|
|
234 |
| } |
|
235 |
| |
|
236 |
12774
| public void claimProperty(String propertyName)
|
|
237 |
| { |
|
238 |
12774
| Defense.notNull(propertyName, "propertyName");
|
|
239 |
| |
|
240 |
12774
| if (_claimedProperties.contains(propertyName))
|
|
241 |
6
| throw new ApplicationRuntimeException(EnhanceMessages.claimedProperty(propertyName));
|
|
242 |
| |
|
243 |
12768
| _claimedProperties.add(propertyName);
|
|
244 |
| } |
|
245 |
| |
|
246 |
3627
| public void claimReadonlyProperty(String propertyName)
|
|
247 |
| { |
|
248 |
3627
| claimProperty(propertyName);
|
|
249 |
| |
|
250 |
3627
| PropertyDescriptor pd = getPropertyDescriptor(propertyName);
|
|
251 |
| |
|
252 |
3627
| if (pd != null && pd.getWriteMethod() != null)
|
|
253 |
3
| throw new ApplicationRuntimeException(EnhanceMessages.readonlyProperty(propertyName, pd
|
|
254 |
| .getWriteMethod())); |
|
255 |
| } |
|
256 |
| |
|
257 |
21912
| public void addField(String name, Class type)
|
|
258 |
| { |
|
259 |
21912
| _classFab.addField(name, type);
|
|
260 |
| } |
|
261 |
| |
|
262 |
5511
| public String addInjectedField(String fieldName, Class fieldType, Object value)
|
|
263 |
| { |
|
264 |
5511
| Defense.notNull(fieldName, "fieldName");
|
|
265 |
5511
| Defense.notNull(fieldType, "fieldType");
|
|
266 |
5511
| Defense.notNull(value, "value");
|
|
267 |
| |
|
268 |
5511
| String existing = (String) _finalFields.get(value);
|
|
269 |
| |
|
270 |
| |
|
271 |
| |
|
272 |
5511
| if (existing != null)
|
|
273 |
0
| return existing;
|
|
274 |
| |
|
275 |
| |
|
276 |
| |
|
277 |
| |
|
278 |
| |
|
279 |
| |
|
280 |
5511
| String uniqueName = _idAllocator.allocateId(fieldName);
|
|
281 |
| |
|
282 |
| |
|
283 |
| |
|
284 |
| |
|
285 |
5511
| _classFab.addField(uniqueName, fieldType);
|
|
286 |
| |
|
287 |
5511
| int parameterIndex = addConstructorParameter(fieldType, value);
|
|
288 |
| |
|
289 |
5511
| constructorBuilder().addln("{0} = ${1};", uniqueName, Integer.toString(parameterIndex));
|
|
290 |
| |
|
291 |
| |
|
292 |
| |
|
293 |
5511
| _finalFields.put(value, uniqueName);
|
|
294 |
| |
|
295 |
5511
| return uniqueName;
|
|
296 |
| } |
|
297 |
| |
|
298 |
276
| public Class convertTypeName(String type)
|
|
299 |
| { |
|
300 |
276
| Defense.notNull(type, "type");
|
|
301 |
| |
|
302 |
276
| Class result = _javaClassMapping.getType(type);
|
|
303 |
| |
|
304 |
276
| if (result == null)
|
|
305 |
| { |
|
306 |
66
| result = _resolver.findClass(type);
|
|
307 |
| |
|
308 |
63
| _javaClassMapping.recordType(type, result);
|
|
309 |
| } |
|
310 |
| |
|
311 |
273
| return result;
|
|
312 |
| } |
|
313 |
| |
|
314 |
10056
| public Class getPropertyType(String name)
|
|
315 |
| { |
|
316 |
10056
| Defense.notNull(name, "name");
|
|
317 |
| |
|
318 |
10056
| PropertyDescriptor pd = getPropertyDescriptor(name);
|
|
319 |
| |
|
320 |
10056
| return pd == null ? null : pd.getPropertyType();
|
|
321 |
| } |
|
322 |
| |
|
323 |
267
| public void validateProperty(String name, Class expectedType)
|
|
324 |
| { |
|
325 |
267
| Defense.notNull(name, "name");
|
|
326 |
267
| Defense.notNull(expectedType, "expectedType");
|
|
327 |
| |
|
328 |
267
| PropertyDescriptor pd = getPropertyDescriptor(name);
|
|
329 |
| |
|
330 |
267
| if (pd == null)
|
|
331 |
75
| return;
|
|
332 |
| |
|
333 |
192
| Class propertyType = pd.getPropertyType();
|
|
334 |
| |
|
335 |
192
| if (propertyType.equals(expectedType))
|
|
336 |
189
| return;
|
|
337 |
| |
|
338 |
3
| throw new ApplicationRuntimeException(EnhanceMessages.propertyTypeMismatch(
|
|
339 |
| _baseClass, |
|
340 |
| name, |
|
341 |
| propertyType, |
|
342 |
| expectedType)); |
|
343 |
| } |
|
344 |
| |
|
345 |
24324
| private PropertyDescriptor getPropertyDescriptor(String name)
|
|
346 |
| { |
|
347 |
24324
| return (PropertyDescriptor) _properties.get(name);
|
|
348 |
| } |
|
349 |
| |
|
350 |
10374
| public String getAccessorMethodName(String propertyName)
|
|
351 |
| { |
|
352 |
10374
| Defense.notNull(propertyName, "propertyName");
|
|
353 |
| |
|
354 |
10374
| PropertyDescriptor pd = getPropertyDescriptor(propertyName);
|
|
355 |
| |
|
356 |
10374
| if (pd != null && pd.getReadMethod() != null)
|
|
357 |
9759
| return pd.getReadMethod().getName();
|
|
358 |
| |
|
359 |
615
| return EnhanceUtils.createAccessorMethodName(propertyName);
|
|
360 |
| } |
|
361 |
| |
|
362 |
21885
| public void addMethod(int modifier, MethodSignature sig, String methodBody, Location location)
|
|
363 |
| { |
|
364 |
21885
| Defense.notNull(sig, "sig");
|
|
365 |
21885
| Defense.notNull(methodBody, "methodBody");
|
|
366 |
21885
| Defense.notNull(location, "location");
|
|
367 |
| |
|
368 |
21885
| Location existing = (Location) _methods.get(sig);
|
|
369 |
21885
| if (existing != null)
|
|
370 |
3
| throw new ApplicationRuntimeException(EnhanceMessages.methodConflict(sig, existing),
|
|
371 |
| location, null); |
|
372 |
| |
|
373 |
21882
| _methods.put(sig, location);
|
|
374 |
| |
|
375 |
21882
| _classFab.addMethod(modifier, sig, methodBody);
|
|
376 |
| } |
|
377 |
| |
|
378 |
3
| public Class getBaseClass()
|
|
379 |
| { |
|
380 |
3
| return _baseClass;
|
|
381 |
| } |
|
382 |
| |
|
383 |
2580
| public String getClassReference(Class clazz)
|
|
384 |
| { |
|
385 |
2580
| Defense.notNull(clazz, "clazz");
|
|
386 |
| |
|
387 |
2580
| String result = (String) _finalFields.get(clazz);
|
|
388 |
| |
|
389 |
2580
| if (result == null)
|
|
390 |
1887
| result = addClassReference(clazz);
|
|
391 |
| |
|
392 |
2580
| return result;
|
|
393 |
| } |
|
394 |
| |
|
395 |
1887
| private String addClassReference(Class clazz)
|
|
396 |
| { |
|
397 |
1887
| StringBuffer buffer = new StringBuffer("_class$");
|
|
398 |
| |
|
399 |
1887
| Class c = clazz;
|
|
400 |
| |
|
401 |
1887
| while (c.isArray())
|
|
402 |
| { |
|
403 |
39
| buffer.append("array$");
|
|
404 |
39
| c = c.getComponentType();
|
|
405 |
| } |
|
406 |
| |
|
407 |
1887
| buffer.append(c.getName().replace('.', '$'));
|
|
408 |
| |
|
409 |
1887
| String fieldName = buffer.toString();
|
|
410 |
| |
|
411 |
1887
| return addInjectedField(fieldName, Class.class, clazz);
|
|
412 |
| } |
|
413 |
| |
|
414 |
| |
|
415 |
| |
|
416 |
| |
|
417 |
| |
|
418 |
| |
|
419 |
5511
| private int addConstructorParameter(Class type, Object value)
|
|
420 |
| { |
|
421 |
5511
| _constructorTypes.add(type);
|
|
422 |
5511
| _constructorArguments.add(value);
|
|
423 |
| |
|
424 |
5511
| return _constructorArguments.size();
|
|
425 |
| } |
|
426 |
| |
|
427 |
5511
| private BodyBuilder constructorBuilder()
|
|
428 |
| { |
|
429 |
5511
| if (_constructorBuilder == null)
|
|
430 |
| { |
|
431 |
1230
| _constructorBuilder = new BodyBuilder();
|
|
432 |
1230
| _constructorBuilder.begin();
|
|
433 |
| } |
|
434 |
| |
|
435 |
5511
| return _constructorBuilder;
|
|
436 |
| } |
|
437 |
| |
|
438 |
| |
|
439 |
| |
|
440 |
| |
|
441 |
| |
|
442 |
| |
|
443 |
1746
| public ComponentConstructor getConstructor()
|
|
444 |
| { |
|
445 |
1746
| try
|
|
446 |
| { |
|
447 |
1746
| finalizeEnhancedClass();
|
|
448 |
| |
|
449 |
1746
| Constructor c = findConstructor();
|
|
450 |
| |
|
451 |
1743
| Object[] params = _constructorArguments.toArray();
|
|
452 |
| |
|
453 |
1743
| return new ComponentConstructorImpl(c, params, _classFab.toString(), _specification
|
|
454 |
| .getLocation()); |
|
455 |
| } |
|
456 |
| catch (Throwable t) |
|
457 |
| { |
|
458 |
3
| throw new ApplicationRuntimeException(EnhanceMessages.classEnhancementFailure(
|
|
459 |
| _baseClass, |
|
460 |
| t), _classFab, null, t); |
|
461 |
| } |
|
462 |
| } |
|
463 |
| |
|
464 |
1749
| void finalizeEnhancedClass()
|
|
465 |
| { |
|
466 |
1749
| finalizeIncompleteMethods();
|
|
467 |
| |
|
468 |
1749
| if (_constructorBuilder != null)
|
|
469 |
| { |
|
470 |
1227
| _constructorBuilder.end();
|
|
471 |
| |
|
472 |
1227
| Class[] types = (Class[]) _constructorTypes
|
|
473 |
| .toArray(new Class[_constructorTypes.size()]); |
|
474 |
| |
|
475 |
1227
| _classFab.addConstructor(types, null, _constructorBuilder.toString());
|
|
476 |
| } |
|
477 |
| |
|
478 |
1749
| if (_log != null)
|
|
479 |
1167
| _log.debug("Creating class:\n\n" + _classFab);
|
|
480 |
| } |
|
481 |
| |
|
482 |
1749
| private void finalizeIncompleteMethods()
|
|
483 |
| { |
|
484 |
1749
| Iterator i = _incompleteMethods.entrySet().iterator();
|
|
485 |
1749
| while (i.hasNext())
|
|
486 |
| { |
|
487 |
2226
| Map.Entry e = (Map.Entry) i.next();
|
|
488 |
2226
| MethodSignature sig = (MethodSignature) e.getKey();
|
|
489 |
2226
| BodyBuilder builder = (BodyBuilder) e.getValue();
|
|
490 |
| |
|
491 |
| |
|
492 |
| |
|
493 |
| |
|
494 |
2226
| builder.end();
|
|
495 |
| |
|
496 |
2226
| _classFab.addMethod(Modifier.PUBLIC, sig, builder.toString());
|
|
497 |
| } |
|
498 |
| } |
|
499 |
| |
|
500 |
1746
| private Constructor findConstructor()
|
|
501 |
| { |
|
502 |
1746
| Class componentClass = _classFab.createClass();
|
|
503 |
| |
|
504 |
| |
|
505 |
| |
|
506 |
1743
| return componentClass.getConstructors()[0];
|
|
507 |
| } |
|
508 |
| |
|
509 |
| static int _uid = 0; |
|
510 |
| |
|
511 |
1809
| private String newClassName()
|
|
512 |
| { |
|
513 |
1809
| String baseName = _baseClass.getName();
|
|
514 |
1809
| int dotx = baseName.lastIndexOf('.');
|
|
515 |
| |
|
516 |
1809
| return "$" + baseName.substring(dotx + 1) + "_" + _uid++;
|
|
517 |
| } |
|
518 |
| |
|
519 |
13062
| public void extendMethodImplementation(Class interfaceClass, MethodSignature methodSignature,
|
|
520 |
| String code) |
|
521 |
| { |
|
522 |
13062
| addInterfaceIfNeeded(interfaceClass);
|
|
523 |
| |
|
524 |
13062
| BodyBuilder builder = (BodyBuilder) _incompleteMethods.get(methodSignature);
|
|
525 |
| |
|
526 |
13062
| if (builder == null)
|
|
527 |
| { |
|
528 |
2232
| builder = createIncompleteMethod(methodSignature);
|
|
529 |
| |
|
530 |
2232
| _incompleteMethods.put(methodSignature, builder);
|
|
531 |
| } |
|
532 |
| |
|
533 |
13062
| builder.addln(code);
|
|
534 |
| } |
|
535 |
| |
|
536 |
13062
| private void addInterfaceIfNeeded(Class interfaceClass)
|
|
537 |
| { |
|
538 |
13062
| if (implementsInterface(interfaceClass))
|
|
539 |
12357
| return;
|
|
540 |
| |
|
541 |
705
| _classFab.addInterface(interfaceClass);
|
|
542 |
705
| _addedInterfaces.add(interfaceClass);
|
|
543 |
| } |
|
544 |
| |
|
545 |
18909
| public boolean implementsInterface(Class interfaceClass)
|
|
546 |
| { |
|
547 |
18909
| if (interfaceClass.isAssignableFrom(_baseClass))
|
|
548 |
8457
| return true;
|
|
549 |
| |
|
550 |
10452
| Iterator i = _addedInterfaces.iterator();
|
|
551 |
10452
| while (i.hasNext())
|
|
552 |
| { |
|
553 |
5058
| Class addedInterface = (Class) i.next();
|
|
554 |
| |
|
555 |
5058
| if (interfaceClass.isAssignableFrom(addedInterface))
|
|
556 |
4167
| return true;
|
|
557 |
| } |
|
558 |
| |
|
559 |
6285
| return false;
|
|
560 |
| } |
|
561 |
| |
|
562 |
2232
| private BodyBuilder createIncompleteMethod(MethodSignature sig)
|
|
563 |
| { |
|
564 |
2232
| BodyBuilder result = new BodyBuilder();
|
|
565 |
| |
|
566 |
| |
|
567 |
| |
|
568 |
2232
| result.begin();
|
|
569 |
| |
|
570 |
2232
| if (existingImplementation(sig))
|
|
571 |
1491
| result.addln("super.{0}($$);", sig.getName());
|
|
572 |
| |
|
573 |
2232
| return result;
|
|
574 |
| } |
|
575 |
| |
|
576 |
| |
|
577 |
| |
|
578 |
| |
|
579 |
| |
|
580 |
| |
|
581 |
2232
| private boolean existingImplementation(MethodSignature sig)
|
|
582 |
| { |
|
583 |
2232
| Method m = findMethod(sig);
|
|
584 |
| |
|
585 |
2232
| return m != null && !Modifier.isAbstract(m.getModifiers());
|
|
586 |
| } |
|
587 |
| |
|
588 |
| |
|
589 |
| |
|
590 |
| |
|
591 |
2232
| private Method findMethod(MethodSignature sig)
|
|
592 |
| { |
|
593 |
| |
|
594 |
| |
|
595 |
2232
| try
|
|
596 |
| { |
|
597 |
2232
| return _baseClass.getMethod(sig.getName(), sig.getParameterTypes());
|
|
598 |
| |
|
599 |
| } |
|
600 |
| catch (NoSuchMethodException ex) |
|
601 |
| { |
|
602 |
| |
|
603 |
| } |
|
604 |
| |
|
605 |
1491
| Class c = _baseClass;
|
|
606 |
| |
|
607 |
1491
| while (c != Object.class)
|
|
608 |
| { |
|
609 |
4404
| try
|
|
610 |
| { |
|
611 |
4404
| return c.getDeclaredMethod(sig.getName(), sig.getParameterTypes());
|
|
612 |
| } |
|
613 |
| catch (NoSuchMethodException ex) |
|
614 |
| { |
|
615 |
| |
|
616 |
| } |
|
617 |
| |
|
618 |
3618
| c = c.getSuperclass();
|
|
619 |
| } |
|
620 |
| |
|
621 |
705
| return null;
|
|
622 |
| } |
|
623 |
| |
|
624 |
1686
| public List findUnclaimedAbstractProperties()
|
|
625 |
| { |
|
626 |
1686
| List result = new ArrayList();
|
|
627 |
| |
|
628 |
1686
| Iterator i = _properties.values().iterator();
|
|
629 |
| |
|
630 |
1686
| while (i.hasNext())
|
|
631 |
| { |
|
632 |
45738
| PropertyDescriptor pd = (PropertyDescriptor) i.next();
|
|
633 |
| |
|
634 |
45738
| String name = pd.getName();
|
|
635 |
| |
|
636 |
45738
| if (_claimedProperties.contains(name))
|
|
637 |
7824
| continue;
|
|
638 |
| |
|
639 |
37914
| if (isAbstractProperty(pd))
|
|
640 |
4341
| result.add(name);
|
|
641 |
| } |
|
642 |
| |
|
643 |
1686
| return result;
|
|
644 |
| } |
|
645 |
| |
|
646 |
| |
|
647 |
| |
|
648 |
| |
|
649 |
| |
|
650 |
| |
|
651 |
37914
| private boolean isAbstractProperty(PropertyDescriptor pd)
|
|
652 |
| { |
|
653 |
37914
| return isExistingAbstractMethod(pd.getReadMethod())
|
|
654 |
| || isExistingAbstractMethod(pd.getWriteMethod()); |
|
655 |
| } |
|
656 |
| |
|
657 |
71676
| private boolean isExistingAbstractMethod(Method m)
|
|
658 |
| { |
|
659 |
71676
| return m != null && Modifier.isAbstract(m.getModifiers());
|
|
660 |
| } |
|
661 |
| } |