1 |
/* java.beans.IndexedPropertyDescriptor |
/* IndexedPropertyDescriptor.java -- |
2 |
Copyright (C) 1998, 2003 Free Software Foundation, Inc. |
Copyright (C) 1998, 2003 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
42 |
import java.lang.reflect.Method; |
import java.lang.reflect.Method; |
43 |
|
|
44 |
/** |
/** |
45 |
** IndexedPropertyDescriptor describes information about a JavaBean |
* IndexedPropertyDescriptor describes information about a JavaBean |
46 |
** indexed property, by which we mean an array-like property that |
* indexed property, by which we mean an array-like property that |
47 |
** has been exposed via a pair of get and set methods and another |
* has been exposed via a pair of get and set methods and another |
48 |
** pair that allows you to get to the property by an index.<P> |
* pair that allows you to get to the property by an index.<P> |
49 |
** |
* |
50 |
** An example property would have four methods like this:<P> |
* An example property would have four methods like this:<P> |
51 |
** <CODE>FooBar[] getFoo()</CODE><BR> |
* <CODE>FooBar[] getFoo()</CODE><BR> |
52 |
** <CODE>void setFoo(FooBar[])</CODE><BR> |
* <CODE>void setFoo(FooBar[])</CODE><BR> |
53 |
** <CODE>FooBar getFoo(int)</CODE><BR> |
* <CODE>FooBar getFoo(int)</CODE><BR> |
54 |
** <CODE>void setFoo(int,FooBar)</CODE><P> |
* <CODE>void setFoo(int,FooBar)</CODE><P> |
55 |
** |
* |
56 |
** The constraints put on get and set methods are:<P> |
* The constraints put on get and set methods are:<P> |
57 |
** <OL> |
* <OL> |
58 |
** <LI>There must be at least a get(int) or a set(int,...) method. |
* <LI>There must be at least a get(int) or a set(int,...) method. |
59 |
** Nothing else is required. <B>Spec note:</B>One nice restriction |
* Nothing else is required. <B>Spec note:</B>One nice restriction |
60 |
** would be that if there is a get() there must be a get(int), same |
* would be that if there is a get() there must be a get(int), same |
61 |
** with set, but that is not in the spec and is fairly harmless.)</LI> |
* with set, but that is not in the spec and is fairly harmless.)</LI> |
62 |
** <LI>A get array method must have signature |
* <LI>A get array method must have signature |
63 |
** <CODE><propertyType>[] <getMethodName>()</CODE></LI> |
* <CODE><propertyType>[] <getMethodName>()</CODE></LI> |
64 |
** <LI>A set array method must have signature |
* <LI>A set array method must have signature |
65 |
** <CODE>void <setMethodName>(<propertyType>[])</CODE></LI> |
* <CODE>void <setMethodName>(<propertyType>[])</CODE></LI> |
66 |
** <LI>A get index method must have signature |
* <LI>A get index method must have signature |
67 |
** <CODE><propertyType> <getMethodName>(int)</CODE></LI> |
* <CODE><propertyType> <getMethodName>(int)</CODE></LI> |
68 |
** <LI>A set index method must have signature |
* <LI>A set index method must have signature |
69 |
** <CODE>void <setMethodName>(int,<propertyType>)</CODE></LI> |
* <CODE>void <setMethodName>(int,<propertyType>)</CODE></LI> |
70 |
** <LI>All these methods may throw any exception.</LI> |
* <LI>All these methods may throw any exception.</LI> |
71 |
** <LI>All these methods must be public.</LI> |
* <LI>All these methods must be public.</LI> |
72 |
** </OL> |
* </OL> |
73 |
** |
* |
74 |
** @author John Keiser |
* @author John Keiser |
75 |
** @since JDK1.1 |
* @since JDK1.1 |
76 |
** @version 1.1.0, 26 Jul 1998 |
*/ |
77 |
**/ |
public class IndexedPropertyDescriptor extends PropertyDescriptor |
78 |
|
{ |
79 |
public class IndexedPropertyDescriptor extends PropertyDescriptor { |
private Class indexedPropertyType; |
80 |
private Class indexedPropertyType; |
private Method setIndex; |
81 |
private Method setIndex; |
private Method getIndex; |
82 |
private Method getIndex; |
|
83 |
|
/** |
84 |
/** Create a new IndexedPropertyDescriptor by introspection. |
* Create a new IndexedPropertyDescriptor by introspection. |
85 |
** This form of constructor creates the PropertyDescriptor by |
* This form of constructor creates the PropertyDescriptor by |
86 |
** looking for getter methods named <CODE>get<name>()</CODE> |
* looking for getter methods named <CODE>get<name>()</CODE> |
87 |
** and setter methods named |
* and setter methods named |
88 |
** <CODE>set<name>()</CODE> in class |
* <CODE>set<name>()</CODE> in class |
89 |
** <CODE><beanClass></CODE>, where <name> has its |
* <CODE><beanClass></CODE>, where <name> has its |
90 |
** first letter capitalized by the constructor.<P> |
* first letter capitalized by the constructor.<P> |
91 |
** |
* |
92 |
** <B>Implementation note:</B> If there is a get(int) method, |
* <B>Implementation note:</B> If there is a get(int) method, |
93 |
** then the return type of that method is used to find the |
* then the return type of that method is used to find the |
94 |
** remaining methods. If there is no get method, then the |
* remaining methods. If there is no get method, then the |
95 |
** set(int) method is searched for exhaustively and that type |
* set(int) method is searched for exhaustively and that type |
96 |
** is used to find the others.<P> |
* is used to find the others.<P> |
97 |
** |
* |
98 |
** <B>Spec note:</B> |
* <B>Spec note:</B> |
99 |
** If there is no get(int) method and multiple set(int) methods with |
* If there is no get(int) method and multiple set(int) methods with |
100 |
** the same name and the correct parameters (different type of course), |
* the same name and the correct parameters (different type of course), |
101 |
** then an IntrospectionException is thrown. While Sun's spec |
* then an IntrospectionException is thrown. While Sun's spec |
102 |
** does not state this, it can make Bean behavior different on |
* does not state this, it can make Bean behavior different on |
103 |
** different systems (since method order is not guaranteed) and as |
* different systems (since method order is not guaranteed) and as |
104 |
** such, can be treated as a bug in the spec. I am not aware of |
* such, can be treated as a bug in the spec. I am not aware of |
105 |
** whether Sun's implementation catches this. |
* whether Sun's implementation catches this. |
106 |
** |
* |
107 |
** @param name the programmatic name of the property, usually |
* @param name the programmatic name of the property, usually |
108 |
** starting with a lowercase letter (e.g. fooManChu |
* starting with a lowercase letter (e.g. fooManChu |
109 |
** instead of FooManChu). |
* instead of FooManChu). |
110 |
** @param beanClass the class the get and set methods live in. |
* @param beanClass the class the get and set methods live in. |
111 |
** @exception IntrospectionException if the methods are not found or invalid. |
* |
112 |
**/ |
* @exception IntrospectionException if the methods are not found or |
113 |
public IndexedPropertyDescriptor(String name, Class beanClass) throws IntrospectionException { |
* invalid. |
114 |
super(name); |
*/ |
115 |
String capitalized; |
public IndexedPropertyDescriptor(String name, Class beanClass) |
116 |
try { |
throws IntrospectionException |
117 |
capitalized = Character.toUpperCase(name.charAt(0)) + name.substring(1); |
{ |
118 |
} catch(StringIndexOutOfBoundsException e) { |
super(name); |
119 |
capitalized = ""; |
String capitalized; |
120 |
} |
try |
121 |
findMethods(beanClass, "get" + capitalized, "set" + capitalized, "get" + capitalized, "set" + capitalized); |
{ |
122 |
} |
capitalized = Character.toUpperCase(name.charAt(0)) |
123 |
|
+ name.substring(1); |
124 |
/** Create a new IndexedPropertyDescriptor by introspection. |
} |
125 |
** This form of constructor allows you to specify the |
catch(StringIndexOutOfBoundsException e) |
126 |
** names of the get and set methods to search for.<P> |
{ |
127 |
** |
capitalized = ""; |
128 |
** <B>Implementation note:</B> If there is a get(int) method, |
} |
129 |
** then the return type of that method is used to find the |
findMethods(beanClass, "get" + capitalized, "set" + capitalized, |
130 |
** remaining methods. If there is no get method, then the |
"get" + capitalized, "set" + capitalized); |
131 |
** set(int) method is searched for exhaustively and that type |
} |
132 |
** is used to find the others.<P> |
|
133 |
** |
/** |
134 |
** <B>Spec note:</B> |
* Create a new IndexedPropertyDescriptor by introspection. |
135 |
** If there is no get(int) method and multiple set(int) methods with |
* This form of constructor allows you to specify the |
136 |
** the same name and the correct parameters (different type of course), |
* names of the get and set methods to search for.<P> |
137 |
** then an IntrospectionException is thrown. While Sun's spec |
* |
138 |
** does not state this, it can make Bean behavior different on |
* <B>Implementation note:</B> If there is a get(int) method, |
139 |
** different systems (since method order is not guaranteed) and as |
* then the return type of that method is used to find the |
140 |
** such, can be treated as a bug in the spec. I am not aware of |
* remaining methods. If there is no get method, then the |
141 |
** whether Sun's implementation catches this. |
* set(int) method is searched for exhaustively and that type |
142 |
** |
* is used to find the others.<P> |
143 |
** @param name the programmatic name of the property, usually |
* |
144 |
** starting with a lowercase letter (e.g. fooManChu |
* <B>Spec note:</B> |
145 |
** instead of FooManChu). |
* If there is no get(int) method and multiple set(int) methods with |
146 |
** @param beanClass the class the get and set methods live in. |
* the same name and the correct parameters (different type of course), |
147 |
** @param getMethodName the name of the get array method. |
* then an IntrospectionException is thrown. While Sun's spec |
148 |
** @param setMethodName the name of the set array method. |
* does not state this, it can make Bean behavior different on |
149 |
** @param getIndexName the name of the get index method. |
* different systems (since method order is not guaranteed) and as |
150 |
** @param setIndexName the name of the set index method. |
* such, can be treated as a bug in the spec. I am not aware of |
151 |
** @exception IntrospectionException if the methods are not found or invalid. |
* whether Sun's implementation catches this. |
152 |
**/ |
* |
153 |
public IndexedPropertyDescriptor(String name, Class beanClass, String getMethodName, String setMethodName, String getIndexName, String setIndexName) throws IntrospectionException { |
* @param name the programmatic name of the property, usually |
154 |
super(name); |
* starting with a lowercase letter (e.g. fooManChu |
155 |
findMethods(beanClass, getMethodName, setMethodName, getIndexName, setIndexName); |
* instead of FooManChu). |
156 |
} |
* @param beanClass the class the get and set methods live in. |
157 |
|
* @param getMethodName the name of the get array method. |
158 |
/** Create a new PropertyDescriptor using explicit Methods. |
* @param setMethodName the name of the set array method. |
159 |
** Note that the methods will be checked for conformance to standard |
* @param getIndexName the name of the get index method. |
160 |
** Property method rules, as described above at the top of this class. |
* @param setIndexName the name of the set index method. |
161 |
** |
* |
162 |
** @param name the programmatic name of the property, usually |
* @exception IntrospectionException if the methods are not found or invalid. |
163 |
** starting with a lowercase letter (e.g. fooManChu |
*/ |
164 |
** instead of FooManChu). |
public IndexedPropertyDescriptor(String name, Class beanClass, |
165 |
** @param getMethod the get array method. |
String getMethodName, String setMethodName, |
166 |
** @param setMethod the set array method. |
String getIndexName, String setIndexName) |
167 |
** @param getIndex the get index method. |
throws IntrospectionException |
168 |
** @param setIndex the set index method. |
{ |
169 |
** @exception IntrospectionException if the methods are not found or invalid. |
super(name); |
170 |
**/ |
findMethods(beanClass, getMethodName, setMethodName, getIndexName, |
171 |
public IndexedPropertyDescriptor(String name, Method getMethod, Method setMethod, Method getIndex, Method setIndex) throws IntrospectionException { |
setIndexName); |
172 |
super(name); |
} |
173 |
if(getMethod != null && getMethod.getParameterTypes().length > 0) { |
|
174 |
throw new IntrospectionException("get method has parameters"); |
/** |
175 |
} |
* Create a new PropertyDescriptor using explicit Methods. |
176 |
if(getMethod != null && setMethod.getParameterTypes().length != 1) { |
* Note that the methods will be checked for conformance to standard |
177 |
throw new IntrospectionException("set method does not have exactly one parameter"); |
* Property method rules, as described above at the top of this class. |
178 |
} |
* |
179 |
if(getMethod != null && setMethod != null) { |
* @param name the programmatic name of the property, usually |
180 |
if(!getMethod.getReturnType().equals(setMethod.getParameterTypes()[0])) { |
* starting with a lowercase letter (e.g. fooManChu |
181 |
throw new IntrospectionException("set and get methods do not share the same type"); |
* instead of FooManChu). |
182 |
} |
* @param getMethod the get array method. |
183 |
if(!getMethod.getDeclaringClass().isAssignableFrom(setMethod.getDeclaringClass()) |
* @param setMethod the set array method. |
184 |
&& !setMethod.getDeclaringClass().isAssignableFrom(getMethod.getDeclaringClass())) { |
* @param getIndex the get index method. |
185 |
throw new IntrospectionException("set and get methods are not in the same class."); |
* @param setIndex the set index method. |
186 |
} |
* |
187 |
} |
* @exception IntrospectionException if the methods are not found or invalid. |
188 |
|
*/ |
189 |
if(getIndex != null && (getIndex.getParameterTypes().length != 1 |
public IndexedPropertyDescriptor(String name, Method getMethod, |
190 |
|| !(getIndex.getParameterTypes()[0]).equals(java.lang.Integer.TYPE))) { |
Method setMethod, Method getIndex, |
191 |
throw new IntrospectionException("get index method has wrong parameters"); |
Method setIndex) |
192 |
} |
throws IntrospectionException |
193 |
if(setIndex != null && (setIndex.getParameterTypes().length != 2 |
{ |
194 |
|| !(setIndex.getParameterTypes()[0]).equals(java.lang.Integer.TYPE))) { |
super(name); |
195 |
throw new IntrospectionException("set index method has wrong parameters"); |
if(getMethod != null && getMethod.getParameterTypes().length > 0) |
196 |
} |
throw new IntrospectionException("get method has parameters"); |
197 |
if(getIndex != null && setIndex != null) { |
if(getMethod != null && setMethod.getParameterTypes().length != 1) |
198 |
if(!getIndex.getReturnType().equals(setIndex.getParameterTypes()[1])) { |
throw new IntrospectionException("set method does not have exactly one parameter"); |
199 |
throw new IntrospectionException("set index methods do not share the same type"); |
if(getMethod != null && setMethod != null) |
200 |
} |
{ |
201 |
if(!getIndex.getDeclaringClass().isAssignableFrom(setIndex.getDeclaringClass()) |
if(!getMethod.getReturnType().equals(setMethod.getParameterTypes()[0])) |
202 |
&& !setIndex.getDeclaringClass().isAssignableFrom(getIndex.getDeclaringClass())) { |
{ |
203 |
throw new IntrospectionException("get and set index methods are not in the same class."); |
throw new IntrospectionException("set and get methods do not " |
204 |
} |
+ "share the same type"); |
205 |
} |
} |
206 |
|
if(!getMethod.getDeclaringClass().isAssignableFrom |
207 |
if(getIndex != null && getMethod != null && !getIndex.getDeclaringClass().isAssignableFrom(getMethod.getDeclaringClass()) |
(setMethod.getDeclaringClass()) |
208 |
&& !getMethod.getDeclaringClass().isAssignableFrom(getIndex.getDeclaringClass())) { |
&& !setMethod.getDeclaringClass().isAssignableFrom |
209 |
throw new IntrospectionException("methods are not in the same class."); |
(getMethod.getDeclaringClass())) |
210 |
} |
{ |
211 |
|
throw new IntrospectionException("set and get methods are not in " |
212 |
if(getIndex != null && getMethod != null && !Array.newInstance(getIndex.getReturnType(),0).getClass().equals(getMethod.getReturnType())) { |
+ "the same class."); |
213 |
throw new IntrospectionException("array methods do not match index methods."); |
} |
214 |
} |
} |
215 |
|
|
216 |
this.getMethod = getMethod; |
if (getIndex != null |
217 |
this.setMethod = setMethod; |
&& (getIndex.getParameterTypes().length != 1 |
218 |
this.getIndex = getIndex; |
|| !(getIndex.getParameterTypes()[0]).equals(java.lang.Integer.TYPE))) |
219 |
this.setIndex = setIndex; |
{ |
220 |
this.indexedPropertyType = getIndex != null ? getIndex.getReturnType() : setIndex.getParameterTypes()[1]; |
throw new IntrospectionException("get index method has wrong " |
221 |
this.propertyType = getMethod != null ? getMethod.getReturnType() : (setMethod != null ? setMethod.getParameterTypes()[0] : Array.newInstance(this.indexedPropertyType,0).getClass()); |
+ "parameters"); |
222 |
} |
} |
223 |
|
if (setIndex != null |
224 |
public Class getIndexedPropertyType() { |
&& (setIndex.getParameterTypes().length != 2 |
225 |
return indexedPropertyType; |
|| !(setIndex.getParameterTypes()[0]).equals(java.lang.Integer.TYPE))) |
226 |
} |
{ |
227 |
|
throw new IntrospectionException("set index method has wrong " |
228 |
public Method getIndexedReadMethod() { |
+ "parameters"); |
229 |
return getIndex; |
} |
230 |
} |
if (getIndex != null && setIndex != null) |
231 |
|
{ |
232 |
public Method getIndexedWriteMethod() { |
if(!getIndex.getReturnType().equals(setIndex.getParameterTypes()[1])) |
233 |
return setIndex; |
{ |
234 |
} |
throw new IntrospectionException("set index methods do not share " |
235 |
|
+ "the same type"); |
236 |
private void findMethods(Class beanClass, String getMethodName, String setMethodName, String getIndexName, String setIndexName) throws IntrospectionException { |
} |
237 |
try { |
if(!getIndex.getDeclaringClass().isAssignableFrom |
238 |
if(getIndexName != null) { |
(setIndex.getDeclaringClass()) |
239 |
try { |
&& !setIndex.getDeclaringClass().isAssignableFrom |
240 |
Class[] getArgs = new Class[1]; |
(getIndex.getDeclaringClass())) |
241 |
getArgs[0] = java.lang.Integer.TYPE; |
{ |
242 |
getIndex = beanClass.getMethod(getIndexName,getArgs); |
throw new IntrospectionException("get and set index methods are " |
243 |
indexedPropertyType = getIndex.getReturnType(); |
"not in the same class."); |
244 |
} catch(NoSuchMethodException E) { |
} |
245 |
} |
} |
246 |
} |
|
247 |
if(getIndex != null) { |
if (getIndex != null && getMethod != null |
248 |
if(setIndexName != null) { |
&& !getIndex.getDeclaringClass().isAssignableFrom |
249 |
try { |
(getMethod.getDeclaringClass()) |
250 |
Class[] setArgs = new Class[2]; |
&& !getMethod.getDeclaringClass().isAssignableFrom |
251 |
setArgs[0] = java.lang.Integer.TYPE; |
(getIndex.getDeclaringClass())) |
252 |
setArgs[1] = indexedPropertyType; |
{ |
253 |
setIndex = beanClass.getMethod(setIndexName,setArgs); |
throw new IntrospectionException("methods are not in the same class."); |
254 |
if(!setIndex.getReturnType().equals(java.lang.Void.TYPE)) { |
} |
255 |
throw new IntrospectionException(setIndexName + " has non-void return type"); |
|
256 |
} |
if (getIndex != null && getMethod != null |
257 |
} catch(NoSuchMethodException E) { |
&& !Array.newInstance(getIndex.getReturnType(),0) |
258 |
} |
.getClass().equals(getMethod.getReturnType())) |
259 |
} |
{ |
260 |
} else if(setIndexName != null) { |
throw new IntrospectionException("array methods do not match index " |
261 |
Method[] m = beanClass.getMethods(); |
"methods."); |
262 |
for(int i=0;i<m.length;i++) { |
} |
263 |
Method current = m[i]; |
|
264 |
if(current.getName().equals(setIndexName) |
this.getMethod = getMethod; |
265 |
&& current.getParameterTypes().length == 2 |
this.setMethod = setMethod; |
266 |
&& (current.getParameterTypes()[0]).equals(java.lang.Integer.TYPE) |
this.getIndex = getIndex; |
267 |
&& current.getReturnType().equals(java.lang.Void.TYPE)) { |
this.setIndex = setIndex; |
268 |
if(setIndex != null) { |
this.indexedPropertyType = getIndex != null ? getIndex.getReturnType() |
269 |
throw new IntrospectionException("Multiple, different set methods found that fit the bill!"); |
: setIndex.getParameterTypes()[1]; |
270 |
} else { |
this.propertyType = getMethod != null ? getMethod.getReturnType() |
271 |
setIndex = current; |
: (setMethod != null ? setMethod.getParameterTypes()[0] |
272 |
indexedPropertyType = current.getParameterTypes()[1]; |
: Array.newInstance(this.indexedPropertyType,0).getClass()); |
273 |
} |
} |
274 |
} |
|
275 |
} |
public Class getIndexedPropertyType() |
276 |
if(setIndex == null) { |
{ |
277 |
throw new IntrospectionException("Cannot find get or set methods."); |
return indexedPropertyType; |
278 |
} |
} |
279 |
} else { |
|
280 |
throw new IntrospectionException("Cannot find get or set methods."); |
public Method getIndexedReadMethod() |
281 |
} |
{ |
282 |
|
return getIndex; |
283 |
Class arrayType = Array.newInstance(indexedPropertyType,0).getClass(); |
} |
284 |
|
|
285 |
Class[] setArgs = new Class[1]; |
public Method getIndexedWriteMethod() |
286 |
setArgs[0] = arrayType; |
{ |
287 |
try { |
return setIndex; |
288 |
setMethod = beanClass.getMethod(setMethodName,setArgs); |
} |
289 |
if(!setMethod.getReturnType().equals(java.lang.Void.TYPE)) { |
|
290 |
setMethod = null; |
private void findMethods(Class beanClass, String getMethodName, |
291 |
} |
String setMethodName, String getIndexName, |
292 |
} catch(NoSuchMethodException E) { |
String setIndexName) |
293 |
} |
throws IntrospectionException |
294 |
|
{ |
295 |
Class[] getArgs = new Class[0]; |
try |
296 |
try { |
{ |
297 |
getMethod = beanClass.getMethod(getMethodName,getArgs); |
if(getIndexName != null) |
298 |
if(!getMethod.getReturnType().equals(arrayType)) { |
{ |
299 |
getMethod = null; |
try |
300 |
} |
{ |
301 |
} catch(NoSuchMethodException E) { |
Class[] getArgs = new Class[1]; |
302 |
} |
getArgs[0] = java.lang.Integer.TYPE; |
303 |
} catch(SecurityException E) { |
getIndex = beanClass.getMethod(getIndexName,getArgs); |
304 |
throw new IntrospectionException("SecurityException while trying to find methods."); |
indexedPropertyType = getIndex.getReturnType(); |
305 |
} |
} |
306 |
} |
catch(NoSuchMethodException E) |
307 |
|
{ |
308 |
|
} |
309 |
|
} |
310 |
|
if(getIndex != null) |
311 |
|
{ |
312 |
|
if(setIndexName != null) |
313 |
|
{ |
314 |
|
try |
315 |
|
{ |
316 |
|
Class[] setArgs = new Class[2]; |
317 |
|
setArgs[0] = java.lang.Integer.TYPE; |
318 |
|
setArgs[1] = indexedPropertyType; |
319 |
|
setIndex = beanClass.getMethod(setIndexName,setArgs); |
320 |
|
if(!setIndex.getReturnType().equals(java.lang.Void.TYPE)) |
321 |
|
{ |
322 |
|
throw new IntrospectionException(setIndexName |
323 |
|
+ " has non-void return type"); |
324 |
|
} |
325 |
|
} |
326 |
|
catch(NoSuchMethodException E) |
327 |
|
{ |
328 |
|
} |
329 |
|
} |
330 |
|
} |
331 |
|
else if(setIndexName != null) |
332 |
|
{ |
333 |
|
Method[] m = beanClass.getMethods(); |
334 |
|
for(int i=0;i<m.length;i++) |
335 |
|
{ |
336 |
|
Method current = m[i]; |
337 |
|
if(current.getName().equals(setIndexName) |
338 |
|
&& current.getParameterTypes().length == 2 |
339 |
|
&& (current.getParameterTypes()[0]) |
340 |
|
.equals(java.lang.Integer.TYPE) |
341 |
|
&& current.getReturnType().equals(java.lang.Void.TYPE)) |
342 |
|
{ |
343 |
|
if(setIndex != null) |
344 |
|
{ |
345 |
|
throw new IntrospectionException("Multiple, different " |
346 |
|
+ "set methods found that fit the bill!"); |
347 |
|
} |
348 |
|
else |
349 |
|
{ |
350 |
|
setIndex = current; |
351 |
|
indexedPropertyType = current.getParameterTypes()[1]; |
352 |
|
} |
353 |
|
} |
354 |
|
} |
355 |
|
if(setIndex == null) |
356 |
|
{ |
357 |
|
throw new IntrospectionException("Cannot find get or set " |
358 |
|
+ "methods."); |
359 |
|
} |
360 |
|
} |
361 |
|
else |
362 |
|
{ |
363 |
|
throw new IntrospectionException("Cannot find get or set methods."); |
364 |
|
} |
365 |
|
|
366 |
|
Class arrayType = Array.newInstance(indexedPropertyType,0).getClass(); |
367 |
|
|
368 |
|
Class[] setArgs = new Class[1]; |
369 |
|
setArgs[0] = arrayType; |
370 |
|
try |
371 |
|
{ |
372 |
|
setMethod = beanClass.getMethod(setMethodName,setArgs); |
373 |
|
if (!setMethod.getReturnType().equals(java.lang.Void.TYPE)) |
374 |
|
{ |
375 |
|
setMethod = null; |
376 |
|
} |
377 |
|
} |
378 |
|
catch(NoSuchMethodException E) |
379 |
|
{ |
380 |
|
} |
381 |
|
|
382 |
|
Class[] getArgs = new Class[0]; |
383 |
|
try |
384 |
|
{ |
385 |
|
getMethod = beanClass.getMethod(getMethodName,getArgs); |
386 |
|
if (!getMethod.getReturnType().equals(arrayType)) |
387 |
|
{ |
388 |
|
getMethod = null; |
389 |
|
} |
390 |
|
} |
391 |
|
catch(NoSuchMethodException E) |
392 |
|
{ |
393 |
|
} |
394 |
|
} |
395 |
|
catch(SecurityException E) |
396 |
|
{ |
397 |
|
throw new IntrospectionException("SecurityException while trying to " |
398 |
|
+ "find methods."); |
399 |
|
} |
400 |
|
} |
401 |
} |
} |