01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: AnnotationsElementDetector.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.engine;
09:
10: import com.uwyn.rife.engine.annotations.Elem;
11: import com.uwyn.rife.tools.JavaSpecificationUtils;
12: import java.lang.reflect.Method;
13:
14: abstract class AnnotationsElementDetector {
15: static boolean hasElementAnnotation(String implementation) {
16: if (implementation != null
17: && JavaSpecificationUtils.isAtLeastJdk15()) {
18: try {
19: Class klass = Class
20: .forName("com.uwyn.rife.engine.AnnotationsElementDetectorProcessor");
21: Method detect = klass.getDeclaredMethod("detect",
22: new Class[] { String.class });
23: Boolean result = (Boolean) detect.invoke(null,
24: new Object[] { implementation });
25: return result.booleanValue();
26: } catch (Exception e) {
27: return false;
28: }
29: }
30:
31: return false;
32: }
33: }
34:
35: abstract class AnnotationsElementDetectorProcessor {
36: public static boolean detect(String implementation) {
37: try {
38: Class klass = Class.forName(implementation);
39: if (klass.isAnnotationPresent(Elem.class)) {
40: return true;
41: }
42: } catch (ClassNotFoundException e) {
43: // do nothing, the implementation is not a valid Java class
44: }
45:
46: return false;
47: }
48: }
|