1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.river.example.browser;
19
20 import java.lang.reflect.Field;
21 import java.lang.reflect.Array;
22 import java.lang.reflect.Modifier;
23
24
25
26
27
28
29
30
31
32
33 class Introspector {
34
35 public static boolean isHidden(Field f){
36 int m = f.getModifiers();
37
38 if(Modifier.isPrivate(m) || Modifier.isStatic(m))
39 return true;
40
41 return false;
42 }
43
44 public static boolean isString(Class clazz){
45 if("java.lang.String".equals(clazz.getName()))
46 return true;
47 return false;
48 }
49
50 public static boolean isWrapper(Class clazz){
51 String name = clazz.getName();
52
53 if("java.lang.Integer".equals(name) ||
54 "java.lang.Boolean".equals(name) ||
55 "java.lang.Byte".equals(name) ||
56 "java.lang.Char".equals(name) ||
57 "java.lang.Double".equals(name) ||
58 "java.lang.Float".equals(name) ||
59 "java.lang.Long".equals(name)){
60 return true;
61 }
62 return false;
63 }
64
65
66 public static String getTypename(Class t, boolean showPackage) {
67 String brackets = "";
68 while(t.isArray()) {
69 brackets += "[]";
70 t = t.getComponentType();
71 }
72
73 if(showPackage)
74 return t.getName() + brackets;
75 else
76 return extractClassName(t.getName()) + brackets;
77 }
78
79
80 public static String getModifierString(int m) {
81 if(m == 0)
82 return "";
83 else
84 return Modifier.toString(m) + " ";
85 }
86
87
88 public static String getFieldString(Field f, boolean showModifier, boolean showPackage) {
89 String fstring = "";
90
91 if(showModifier)
92 fstring += getModifierString(f.getModifiers());
93
94 fstring += getTypename(f.getType(), showPackage);
95 fstring += " ";
96 fstring += f.getName();
97
98 return fstring;
99 }
100
101 public static String extractClassName(String fullName){
102 int index = fullName.lastIndexOf(".");
103
104 return fullName.substring(index + 1);
105 }
106 }