01: package org.drools.eclipse.editors.completion;
02:
03: import java.lang.reflect.Field;
04:
05: public class ReflectionUtils {
06:
07: private ReflectionUtils() {
08: }
09:
10: public static Object getField(Object instance, String name) {
11: Class clazz = instance.getClass();
12:
13: do {
14: Field[] fields = clazz.getDeclaredFields();
15: for (int i = 0; i < fields.length; i++) {
16: Field f = fields[i];
17: if (name.equals(f.getName())) {
18: try {
19: f.setAccessible(true);
20: return f.get(instance);
21:
22: } catch (SecurityException ex) {
23: return null;
24: } catch (IllegalArgumentException ex) {
25: return null;
26: } catch (IllegalAccessException ex) {
27: return null;
28: }
29: }
30: }
31: clazz = clazz.getSuperclass();
32: } while (clazz.getSuperclass() != null);
33: return null;
34: }
35: }
|