1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.ibatis.common.beans;
17
18 import java.util.List;
19
20
21
22
23 public abstract class BaseProbe implements Probe {
24
25
26
27
28
29
30
31
32
33
34
35 protected abstract void setProperty(Object object, String property, Object value);
36
37
38
39
40
41
42
43
44
45
46
47 protected abstract Object getProperty(Object object, String property);
48
49
50
51
52
53
54
55
56
57 public abstract String[] getReadablePropertyNames(Object object);
58
59
60
61
62
63
64
65
66
67 public abstract String[] getWriteablePropertyNames(Object object);
68
69
70
71
72
73
74
75
76
77
78
79 protected Object getIndexedProperty(Object object, String indexedName) {
80
81 Object value = null;
82
83 try {
84 String name = indexedName.substring(0, indexedName.indexOf('['));
85 int i = Integer.parseInt(indexedName.substring(indexedName.indexOf('[') + 1, indexedName.indexOf(']')));
86 Object list = null;
87 if ("".equals(name)) {
88 list = object;
89 } else {
90 list = getProperty(object, name);
91 }
92
93 if (list instanceof List) {
94 value = ((List) list).get(i);
95 } else if (list instanceof Object[]) {
96 value = ((Object[]) list)[i];
97 } else if (list instanceof char[]) {
98 value = Character.valueOf(((char[]) list)[i]);
99 } else if (list instanceof boolean[]) {
100 value = new Boolean(((boolean[]) list)[i]);
101 } else if (list instanceof byte[]) {
102 value = Byte.valueOf(((byte[]) list)[i]);
103 } else if (list instanceof double[]) {
104 value = Double.valueOf(((double[]) list)[i]);
105 } else if (list instanceof float[]) {
106 value = Float.valueOf(((float[]) list)[i]);
107 } else if (list instanceof int[]) {
108 value = Integer.valueOf(((int[]) list)[i]);
109 } else if (list instanceof long[]) {
110 value = Long.valueOf(((long[]) list)[i]);
111 } else if (list instanceof short[]) {
112 value = Short.valueOf(((short[]) list)[i]);
113 } else {
114 throw new ProbeException(
115 "The '" + name + "' property of the " + object.getClass().getName() + " class is not a List or Array.");
116 }
117
118 } catch (ProbeException e) {
119 throw e;
120 } catch (Exception e) {
121 throw new ProbeException("Error getting ordinal list from JavaBean. Cause " + e, e);
122 }
123
124 return value;
125 }
126
127
128
129
130
131
132
133
134
135
136
137 protected Class getIndexedType(Object object, String indexedName) {
138
139 Class value = null;
140
141 try {
142 String name = indexedName.substring(0, indexedName.indexOf('['));
143 int i = Integer.parseInt(indexedName.substring(indexedName.indexOf('[') + 1, indexedName.indexOf(']')));
144 Object list = null;
145 if (!"".equals(name)) {
146 list = getProperty(object, name);
147 } else {
148 list = object;
149 }
150
151 if (list instanceof List) {
152 value = ((List) list).get(i).getClass();
153 } else if (list instanceof Object[]) {
154 value = ((Object[]) list)[i].getClass();
155 } else if (list instanceof char[]) {
156 value = Character.class;
157 } else if (list instanceof boolean[]) {
158 value = Boolean.class;
159 } else if (list instanceof byte[]) {
160 value = Byte.class;
161 } else if (list instanceof double[]) {
162 value = Double.class;
163 } else if (list instanceof float[]) {
164 value = Float.class;
165 } else if (list instanceof int[]) {
166 value = Integer.class;
167 } else if (list instanceof long[]) {
168 value = Long.class;
169 } else if (list instanceof short[]) {
170 value = Short.class;
171 } else {
172 throw new ProbeException(
173 "The '" + name + "' property of the " + object.getClass().getName() + " class is not a List or Array.");
174 }
175
176 } catch (ProbeException e) {
177 throw e;
178 } catch (Exception e) {
179 throw new ProbeException("Error getting ordinal list from JavaBean. Cause " + e, e);
180 }
181
182 return value;
183 }
184
185
186
187
188
189
190
191
192
193
194
195 protected void setIndexedProperty(Object object, String indexedName, Object value) {
196
197 try {
198 String name = indexedName.substring(0, indexedName.indexOf('['));
199 int i = Integer.parseInt(indexedName.substring(indexedName.indexOf('[') + 1, indexedName.indexOf(']')));
200 Object list = getProperty(object, name);
201 if (list instanceof List) {
202 ((List) list).set(i, value);
203 } else if (list instanceof Object[]) {
204 ((Object[]) list)[i] = value;
205 } else if (list instanceof char[]) {
206 ((char[]) list)[i] = ((Character) value).charValue();
207 } else if (list instanceof boolean[]) {
208 ((boolean[]) list)[i] = ((Boolean) value).booleanValue();
209 } else if (list instanceof byte[]) {
210 ((byte[]) list)[i] = ((Byte) value).byteValue();
211 } else if (list instanceof double[]) {
212 ((double[]) list)[i] = ((Double) value).doubleValue();
213 } else if (list instanceof float[]) {
214 ((float[]) list)[i] = ((Float) value).floatValue();
215 } else if (list instanceof int[]) {
216 ((int[]) list)[i] = ((Integer) value).intValue();
217 } else if (list instanceof long[]) {
218 ((long[]) list)[i] = ((Long) value).longValue();
219 } else if (list instanceof short[]) {
220 ((short[]) list)[i] = ((Short) value).shortValue();
221 } else {
222 throw new ProbeException(
223 "The '" + name + "' property of the " + object.getClass().getName() + " class is not a List or Array.");
224 }
225 } catch (ProbeException e) {
226 throw e;
227 } catch (Exception e) {
228 throw new ProbeException("Error getting ordinal value from JavaBean. Cause " + e, e);
229 }
230 }
231 }