author | malenkov |
Mon, 30 Jul 2012 13:35:10 +0400 | |
changeset 13356 | 89a34c00fd8c |
parent 11668 | 138b661e3841 |
child 13654 | 9a35ae08fd2b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
8760
diff
changeset
|
2 |
* Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.beans; |
|
27 |
||
13356 | 28 |
import com.sun.beans.TypeResolver; |
4382
c0759b1ccb56
5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents:
3476
diff
changeset
|
29 |
import com.sun.beans.WeakCache; |
2 | 30 |
import com.sun.beans.finder.ClassFinder; |
31 |
||
7249
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
32 |
import java.awt.Component; |
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
33 |
|
4851
4f7de5eeeac7
6921057: REGRESSION: persistence delegate issue on Windows and Linux against 5.u23b03/6u17b11
malenkov
parents:
4393
diff
changeset
|
34 |
import java.lang.ref.Reference; |
4f7de5eeeac7
6921057: REGRESSION: persistence delegate issue on Windows and Linux against 5.u23b03/6u17b11
malenkov
parents:
4393
diff
changeset
|
35 |
import java.lang.ref.SoftReference; |
2 | 36 |
import java.lang.reflect.Method; |
37 |
import java.lang.reflect.Modifier; |
|
13356 | 38 |
import java.lang.reflect.Type; |
2 | 39 |
|
40 |
import java.util.Map; |
|
41 |
import java.util.ArrayList; |
|
42 |
import java.util.HashMap; |
|
43 |
import java.util.Iterator; |
|
44 |
import java.util.EventListener; |
|
7249
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
45 |
import java.util.EventObject; |
2 | 46 |
import java.util.List; |
47 |
import java.util.TreeMap; |
|
3239
f675984c2349
6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
2
diff
changeset
|
48 |
|
2 | 49 |
import sun.reflect.misc.ReflectUtil; |
50 |
||
51 |
/** |
|
52 |
* The Introspector class provides a standard way for tools to learn about |
|
53 |
* the properties, events, and methods supported by a target Java Bean. |
|
54 |
* <p> |
|
55 |
* For each of those three kinds of information, the Introspector will |
|
56 |
* separately analyze the bean's class and superclasses looking for |
|
57 |
* either explicit or implicit information and use that information to |
|
58 |
* build a BeanInfo object that comprehensively describes the target bean. |
|
59 |
* <p> |
|
60 |
* For each class "Foo", explicit information may be available if there exists |
|
61 |
* a corresponding "FooBeanInfo" class that provides a non-null value when |
|
62 |
* queried for the information. We first look for the BeanInfo class by |
|
63 |
* taking the full package-qualified name of the target bean class and |
|
64 |
* appending "BeanInfo" to form a new class name. If this fails, then |
|
65 |
* we take the final classname component of this name, and look for that |
|
66 |
* class in each of the packages specified in the BeanInfo package search |
|
67 |
* path. |
|
68 |
* <p> |
|
69 |
* Thus for a class such as "sun.xyz.OurButton" we would first look for a |
|
70 |
* BeanInfo class called "sun.xyz.OurButtonBeanInfo" and if that failed we'd |
|
71 |
* look in each package in the BeanInfo search path for an OurButtonBeanInfo |
|
72 |
* class. With the default search path, this would mean looking for |
|
73 |
* "sun.beans.infos.OurButtonBeanInfo". |
|
74 |
* <p> |
|
75 |
* If a class provides explicit BeanInfo about itself then we add that to |
|
76 |
* the BeanInfo information we obtained from analyzing any derived classes, |
|
77 |
* but we regard the explicit information as being definitive for the current |
|
78 |
* class and its base classes, and do not proceed any further up the superclass |
|
79 |
* chain. |
|
80 |
* <p> |
|
81 |
* If we don't find explicit BeanInfo on a class, we use low-level |
|
82 |
* reflection to study the methods of the class and apply standard design |
|
83 |
* patterns to identify property accessors, event sources, or public |
|
84 |
* methods. We then proceed to analyze the class's superclass and add |
|
85 |
* in the information from it (and possibly on up the superclass chain). |
|
86 |
* <p> |
|
87 |
* For more information about introspection and design patterns, please |
|
88 |
* consult the |
|
8760
83843c0b84f7
7021517: java.beans code comments have issues with HTML4 compliance
malenkov
parents:
7249
diff
changeset
|
89 |
* <a href="http://java.sun.com/products/javabeans/docs/index.html">JavaBeans™ specification</a>. |
2 | 90 |
*/ |
91 |
||
92 |
public class Introspector { |
|
93 |
||
94 |
// Flags that can be used to control getBeanInfo: |
|
95 |
public final static int USE_ALL_BEANINFO = 1; |
|
96 |
public final static int IGNORE_IMMEDIATE_BEANINFO = 2; |
|
97 |
public final static int IGNORE_ALL_BEANINFO = 3; |
|
98 |
||
99 |
// Static Caches to speed up introspection. |
|
11086
09b1d6383d0b
7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents:
9035
diff
changeset
|
100 |
private static final WeakCache<Class<?>, Method[]> declaredMethodCache = new WeakCache<>(); |
2 | 101 |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
102 |
private Class<?> beanClass; |
2 | 103 |
private BeanInfo explicitBeanInfo; |
104 |
private BeanInfo superBeanInfo; |
|
105 |
private BeanInfo additionalBeanInfo[]; |
|
106 |
||
107 |
private boolean propertyChangeSource = false; |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
108 |
private static Class<EventListener> eventListenerType = EventListener.class; |
2 | 109 |
|
110 |
// These should be removed. |
|
111 |
private String defaultEventName; |
|
112 |
private String defaultPropertyName; |
|
113 |
private int defaultEventIndex = -1; |
|
114 |
private int defaultPropertyIndex = -1; |
|
115 |
||
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
116 |
// Methods maps from Method names to MethodDescriptors |
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
117 |
private Map<String, MethodDescriptor> methods; |
2 | 118 |
|
119 |
// properties maps from String names to PropertyDescriptors |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
120 |
private Map<String, PropertyDescriptor> properties; |
2 | 121 |
|
122 |
// events maps from String names to EventSetDescriptors |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
123 |
private Map<String, EventSetDescriptor> events; |
2 | 124 |
|
125 |
private final static EventSetDescriptor[] EMPTY_EVENTSETDESCRIPTORS = new EventSetDescriptor[0]; |
|
126 |
||
127 |
static final String ADD_PREFIX = "add"; |
|
128 |
static final String REMOVE_PREFIX = "remove"; |
|
129 |
static final String GET_PREFIX = "get"; |
|
130 |
static final String SET_PREFIX = "set"; |
|
131 |
static final String IS_PREFIX = "is"; |
|
132 |
||
133 |
//====================================================================== |
|
134 |
// Public methods |
|
135 |
//====================================================================== |
|
136 |
||
137 |
/** |
|
138 |
* Introspect on a Java Bean and learn about all its properties, exposed |
|
139 |
* methods, and events. |
|
140 |
* <p> |
|
141 |
* If the BeanInfo class for a Java Bean has been previously Introspected |
|
142 |
* then the BeanInfo class is retrieved from the BeanInfo cache. |
|
143 |
* |
|
144 |
* @param beanClass The bean class to be analyzed. |
|
145 |
* @return A BeanInfo object describing the target bean. |
|
146 |
* @exception IntrospectionException if an exception occurs during |
|
147 |
* introspection. |
|
148 |
* @see #flushCaches |
|
149 |
* @see #flushFromCaches |
|
150 |
*/ |
|
151 |
public static BeanInfo getBeanInfo(Class<?> beanClass) |
|
152 |
throws IntrospectionException |
|
153 |
{ |
|
154 |
if (!ReflectUtil.isPackageAccessible(beanClass)) { |
|
155 |
return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo(); |
|
156 |
} |
|
11086
09b1d6383d0b
7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents:
9035
diff
changeset
|
157 |
ThreadGroupContext context = ThreadGroupContext.getContext(); |
5959
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
5947
diff
changeset
|
158 |
BeanInfo beanInfo; |
11086
09b1d6383d0b
7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents:
9035
diff
changeset
|
159 |
synchronized (declaredMethodCache) { |
09b1d6383d0b
7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents:
9035
diff
changeset
|
160 |
beanInfo = context.getBeanInfo(beanClass); |
5959
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
5947
diff
changeset
|
161 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
5947
diff
changeset
|
162 |
if (beanInfo == null) { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
5947
diff
changeset
|
163 |
beanInfo = new Introspector(beanClass, null, USE_ALL_BEANINFO).getBeanInfo(); |
11086
09b1d6383d0b
7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents:
9035
diff
changeset
|
164 |
synchronized (declaredMethodCache) { |
09b1d6383d0b
7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents:
9035
diff
changeset
|
165 |
context.putBeanInfo(beanClass, beanInfo); |
4382
c0759b1ccb56
5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents:
3476
diff
changeset
|
166 |
} |
3438
8bd2d2eeac83
6660539: Introspector shares cache of mutable BeanInfo between AppContexts.
malenkov
parents:
2
diff
changeset
|
167 |
} |
5959
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
5947
diff
changeset
|
168 |
return beanInfo; |
2 | 169 |
} |
170 |
||
171 |
/** |
|
172 |
* Introspect on a Java bean and learn about all its properties, exposed |
|
173 |
* methods, and events, subject to some control flags. |
|
174 |
* <p> |
|
175 |
* If the BeanInfo class for a Java Bean has been previously Introspected |
|
176 |
* based on the same arguments then the BeanInfo class is retrieved |
|
177 |
* from the BeanInfo cache. |
|
178 |
* |
|
179 |
* @param beanClass The bean class to be analyzed. |
|
180 |
* @param flags Flags to control the introspection. |
|
181 |
* If flags == USE_ALL_BEANINFO then we use all of the BeanInfo |
|
182 |
* classes we can discover. |
|
183 |
* If flags == IGNORE_IMMEDIATE_BEANINFO then we ignore any |
|
184 |
* BeanInfo associated with the specified beanClass. |
|
185 |
* If flags == IGNORE_ALL_BEANINFO then we ignore all BeanInfo |
|
186 |
* associated with the specified beanClass or any of its |
|
187 |
* parent classes. |
|
188 |
* @return A BeanInfo object describing the target bean. |
|
189 |
* @exception IntrospectionException if an exception occurs during |
|
190 |
* introspection. |
|
191 |
*/ |
|
192 |
public static BeanInfo getBeanInfo(Class<?> beanClass, int flags) |
|
193 |
throws IntrospectionException { |
|
194 |
return getBeanInfo(beanClass, null, flags); |
|
195 |
} |
|
196 |
||
197 |
/** |
|
198 |
* Introspect on a Java bean and learn all about its properties, exposed |
|
199 |
* methods, below a given "stop" point. |
|
200 |
* <p> |
|
201 |
* If the BeanInfo class for a Java Bean has been previously Introspected |
|
202 |
* based on the same arguments, then the BeanInfo class is retrieved |
|
203 |
* from the BeanInfo cache. |
|
204 |
* |
|
205 |
* @param beanClass The bean class to be analyzed. |
|
206 |
* @param stopClass The baseclass at which to stop the analysis. Any |
|
207 |
* methods/properties/events in the stopClass or in its baseclasses |
|
208 |
* will be ignored in the analysis. |
|
209 |
* @exception IntrospectionException if an exception occurs during |
|
210 |
* introspection. |
|
211 |
*/ |
|
212 |
public static BeanInfo getBeanInfo(Class<?> beanClass, Class<?> stopClass) |
|
213 |
throws IntrospectionException { |
|
214 |
return getBeanInfo(beanClass, stopClass, USE_ALL_BEANINFO); |
|
215 |
} |
|
216 |
||
217 |
/** |
|
218 |
* Introspect on a Java Bean and learn about all its properties, |
|
219 |
* exposed methods and events, below a given {@code stopClass} point |
|
220 |
* subject to some control {@code flags}. |
|
221 |
* <dl> |
|
222 |
* <dt>USE_ALL_BEANINFO</dt> |
|
223 |
* <dd>Any BeanInfo that can be discovered will be used.</dd> |
|
224 |
* <dt>IGNORE_IMMEDIATE_BEANINFO</dt> |
|
225 |
* <dd>Any BeanInfo associated with the specified {@code beanClass} will be ignored.</dd> |
|
226 |
* <dt>IGNORE_ALL_BEANINFO</dt> |
|
227 |
* <dd>Any BeanInfo associated with the specified {@code beanClass} |
|
228 |
* or any of its parent classes will be ignored.</dd> |
|
229 |
* </dl> |
|
230 |
* Any methods/properties/events in the {@code stopClass} |
|
231 |
* or in its parent classes will be ignored in the analysis. |
|
232 |
* <p> |
|
233 |
* If the BeanInfo class for a Java Bean has been |
|
234 |
* previously introspected based on the same arguments then |
|
235 |
* the BeanInfo class is retrieved from the BeanInfo cache. |
|
236 |
* |
|
237 |
* @param beanClass the bean class to be analyzed |
|
238 |
* @param stopClass the parent class at which to stop the analysis |
|
239 |
* @param flags flags to control the introspection |
|
240 |
* @return a BeanInfo object describing the target bean |
|
241 |
* @exception IntrospectionException if an exception occurs during introspection |
|
242 |
* |
|
243 |
* @since 1.7 |
|
244 |
*/ |
|
245 |
public static BeanInfo getBeanInfo(Class<?> beanClass, Class<?> stopClass, |
|
246 |
int flags) throws IntrospectionException { |
|
247 |
BeanInfo bi; |
|
248 |
if (stopClass == null && flags == USE_ALL_BEANINFO) { |
|
249 |
// Same parameters to take advantage of caching. |
|
250 |
bi = getBeanInfo(beanClass); |
|
251 |
} else { |
|
252 |
bi = (new Introspector(beanClass, stopClass, flags)).getBeanInfo(); |
|
253 |
} |
|
254 |
return bi; |
|
255 |
||
256 |
// Old behaviour: Make an independent copy of the BeanInfo. |
|
257 |
//return new GenericBeanInfo(bi); |
|
258 |
} |
|
259 |
||
260 |
||
261 |
/** |
|
262 |
* Utility method to take a string and convert it to normal Java variable |
|
263 |
* name capitalization. This normally means converting the first |
|
264 |
* character from upper case to lower case, but in the (unusual) special |
|
265 |
* case when there is more than one character and both the first and |
|
266 |
* second characters are upper case, we leave it alone. |
|
267 |
* <p> |
|
268 |
* Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays |
|
269 |
* as "URL". |
|
270 |
* |
|
271 |
* @param name The string to be decapitalized. |
|
272 |
* @return The decapitalized version of the string. |
|
273 |
*/ |
|
274 |
public static String decapitalize(String name) { |
|
275 |
if (name == null || name.length() == 0) { |
|
276 |
return name; |
|
277 |
} |
|
278 |
if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) && |
|
279 |
Character.isUpperCase(name.charAt(0))){ |
|
280 |
return name; |
|
281 |
} |
|
282 |
char chars[] = name.toCharArray(); |
|
283 |
chars[0] = Character.toLowerCase(chars[0]); |
|
284 |
return new String(chars); |
|
285 |
} |
|
286 |
||
287 |
/** |
|
288 |
* Gets the list of package names that will be used for |
|
289 |
* finding BeanInfo classes. |
|
290 |
* |
|
291 |
* @return The array of package names that will be searched in |
|
292 |
* order to find BeanInfo classes. The default value |
|
293 |
* for this array is implementation-dependent; e.g. |
|
294 |
* Sun implementation initially sets to {"sun.beans.infos"}. |
|
295 |
*/ |
|
296 |
||
3239
f675984c2349
6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
2
diff
changeset
|
297 |
public static String[] getBeanInfoSearchPath() { |
11086
09b1d6383d0b
7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents:
9035
diff
changeset
|
298 |
return ThreadGroupContext.getContext().getBeanInfoFinder().getPackages(); |
2 | 299 |
} |
300 |
||
301 |
/** |
|
302 |
* Change the list of package names that will be used for |
|
303 |
* finding BeanInfo classes. The behaviour of |
|
304 |
* this method is undefined if parameter path |
|
305 |
* is null. |
|
306 |
* |
|
307 |
* <p>First, if there is a security manager, its <code>checkPropertiesAccess</code> |
|
308 |
* method is called. This could result in a SecurityException. |
|
309 |
* |
|
310 |
* @param path Array of package names. |
|
311 |
* @exception SecurityException if a security manager exists and its |
|
312 |
* <code>checkPropertiesAccess</code> method doesn't allow setting |
|
313 |
* of system properties. |
|
314 |
* @see SecurityManager#checkPropertiesAccess |
|
315 |
*/ |
|
316 |
||
3239
f675984c2349
6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
2
diff
changeset
|
317 |
public static void setBeanInfoSearchPath(String[] path) { |
2 | 318 |
SecurityManager sm = System.getSecurityManager(); |
319 |
if (sm != null) { |
|
320 |
sm.checkPropertiesAccess(); |
|
321 |
} |
|
11086
09b1d6383d0b
7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents:
9035
diff
changeset
|
322 |
ThreadGroupContext.getContext().getBeanInfoFinder().setPackages(path); |
2 | 323 |
} |
324 |
||
325 |
||
326 |
/** |
|
327 |
* Flush all of the Introspector's internal caches. This method is |
|
328 |
* not normally required. It is normally only needed by advanced |
|
329 |
* tools that update existing "Class" objects in-place and need |
|
330 |
* to make the Introspector re-analyze existing Class objects. |
|
331 |
*/ |
|
332 |
||
333 |
public static void flushCaches() { |
|
11086
09b1d6383d0b
7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents:
9035
diff
changeset
|
334 |
synchronized (declaredMethodCache) { |
09b1d6383d0b
7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents:
9035
diff
changeset
|
335 |
ThreadGroupContext.getContext().clearBeanInfoCache(); |
4382
c0759b1ccb56
5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents:
3476
diff
changeset
|
336 |
declaredMethodCache.clear(); |
3438
8bd2d2eeac83
6660539: Introspector shares cache of mutable BeanInfo between AppContexts.
malenkov
parents:
2
diff
changeset
|
337 |
} |
2 | 338 |
} |
339 |
||
340 |
/** |
|
341 |
* Flush the Introspector's internal cached information for a given class. |
|
342 |
* This method is not normally required. It is normally only needed |
|
343 |
* by advanced tools that update existing "Class" objects in-place |
|
344 |
* and need to make the Introspector re-analyze an existing Class object. |
|
345 |
* |
|
346 |
* Note that only the direct state associated with the target Class |
|
347 |
* object is flushed. We do not flush state for other Class objects |
|
348 |
* with the same name, nor do we flush state for any related Class |
|
349 |
* objects (such as subclasses), even though their state may include |
|
350 |
* information indirectly obtained from the target Class object. |
|
351 |
* |
|
352 |
* @param clz Class object to be flushed. |
|
353 |
* @throws NullPointerException If the Class object is null. |
|
354 |
*/ |
|
355 |
public static void flushFromCaches(Class<?> clz) { |
|
356 |
if (clz == null) { |
|
357 |
throw new NullPointerException(); |
|
358 |
} |
|
11086
09b1d6383d0b
7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents:
9035
diff
changeset
|
359 |
synchronized (declaredMethodCache) { |
09b1d6383d0b
7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents:
9035
diff
changeset
|
360 |
ThreadGroupContext.getContext().removeBeanInfo(clz); |
4382
c0759b1ccb56
5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents:
3476
diff
changeset
|
361 |
declaredMethodCache.put(clz, null); |
3438
8bd2d2eeac83
6660539: Introspector shares cache of mutable BeanInfo between AppContexts.
malenkov
parents:
2
diff
changeset
|
362 |
} |
2 | 363 |
} |
364 |
||
365 |
//====================================================================== |
|
366 |
// Private implementation methods |
|
367 |
//====================================================================== |
|
368 |
||
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
369 |
private Introspector(Class<?> beanClass, Class<?> stopClass, int flags) |
2 | 370 |
throws IntrospectionException { |
371 |
this.beanClass = beanClass; |
|
372 |
||
373 |
// Check stopClass is a superClass of startClass. |
|
374 |
if (stopClass != null) { |
|
375 |
boolean isSuper = false; |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
376 |
for (Class<?> c = beanClass.getSuperclass(); c != null; c = c.getSuperclass()) { |
2 | 377 |
if (c == stopClass) { |
378 |
isSuper = true; |
|
379 |
} |
|
380 |
} |
|
381 |
if (!isSuper) { |
|
382 |
throw new IntrospectionException(stopClass.getName() + " not superclass of " + |
|
383 |
beanClass.getName()); |
|
384 |
} |
|
385 |
} |
|
386 |
||
387 |
if (flags == USE_ALL_BEANINFO) { |
|
388 |
explicitBeanInfo = findExplicitBeanInfo(beanClass); |
|
389 |
} |
|
390 |
||
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
391 |
Class<?> superClass = beanClass.getSuperclass(); |
2 | 392 |
if (superClass != stopClass) { |
393 |
int newFlags = flags; |
|
394 |
if (newFlags == IGNORE_IMMEDIATE_BEANINFO) { |
|
395 |
newFlags = USE_ALL_BEANINFO; |
|
396 |
} |
|
397 |
superBeanInfo = getBeanInfo(superClass, stopClass, newFlags); |
|
398 |
} |
|
399 |
if (explicitBeanInfo != null) { |
|
400 |
additionalBeanInfo = explicitBeanInfo.getAdditionalBeanInfo(); |
|
401 |
} |
|
402 |
if (additionalBeanInfo == null) { |
|
403 |
additionalBeanInfo = new BeanInfo[0]; |
|
404 |
} |
|
405 |
} |
|
406 |
||
407 |
/** |
|
408 |
* Constructs a GenericBeanInfo class from the state of the Introspector |
|
409 |
*/ |
|
410 |
private BeanInfo getBeanInfo() throws IntrospectionException { |
|
411 |
||
412 |
// the evaluation order here is import, as we evaluate the |
|
413 |
// event sets and locate PropertyChangeListeners before we |
|
414 |
// look for properties. |
|
415 |
BeanDescriptor bd = getTargetBeanDescriptor(); |
|
416 |
MethodDescriptor mds[] = getTargetMethodInfo(); |
|
417 |
EventSetDescriptor esds[] = getTargetEventInfo(); |
|
418 |
PropertyDescriptor pds[] = getTargetPropertyInfo(); |
|
419 |
||
420 |
int defaultEvent = getTargetDefaultEventIndex(); |
|
421 |
int defaultProperty = getTargetDefaultPropertyIndex(); |
|
422 |
||
423 |
return new GenericBeanInfo(bd, esds, defaultEvent, pds, |
|
424 |
defaultProperty, mds, explicitBeanInfo); |
|
425 |
||
426 |
} |
|
427 |
||
428 |
/** |
|
429 |
* Looks for an explicit BeanInfo class that corresponds to the Class. |
|
430 |
* First it looks in the existing package that the Class is defined in, |
|
431 |
* then it checks to see if the class is its own BeanInfo. Finally, |
|
432 |
* the BeanInfo search path is prepended to the class and searched. |
|
433 |
* |
|
3239
f675984c2349
6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
2
diff
changeset
|
434 |
* @param beanClass the class type of the bean |
2 | 435 |
* @return Instance of an explicit BeanInfo class or null if one isn't found. |
436 |
*/ |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
437 |
private static BeanInfo findExplicitBeanInfo(Class<?> beanClass) { |
11086
09b1d6383d0b
7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents:
9035
diff
changeset
|
438 |
return ThreadGroupContext.getContext().getBeanInfoFinder().find(beanClass); |
2 | 439 |
} |
440 |
||
441 |
/** |
|
442 |
* @return An array of PropertyDescriptors describing the editable |
|
443 |
* properties supported by the target bean. |
|
444 |
*/ |
|
445 |
||
446 |
private PropertyDescriptor[] getTargetPropertyInfo() { |
|
447 |
||
448 |
// Check if the bean has its own BeanInfo that will provide |
|
449 |
// explicit information. |
|
450 |
PropertyDescriptor[] explicitProperties = null; |
|
451 |
if (explicitBeanInfo != null) { |
|
452 |
explicitProperties = getPropertyDescriptors(this.explicitBeanInfo); |
|
453 |
} |
|
454 |
||
455 |
if (explicitProperties == null && superBeanInfo != null) { |
|
456 |
// We have no explicit BeanInfo properties. Check with our parent. |
|
457 |
addPropertyDescriptors(getPropertyDescriptors(this.superBeanInfo)); |
|
458 |
} |
|
459 |
||
460 |
for (int i = 0; i < additionalBeanInfo.length; i++) { |
|
461 |
addPropertyDescriptors(additionalBeanInfo[i].getPropertyDescriptors()); |
|
462 |
} |
|
463 |
||
464 |
if (explicitProperties != null) { |
|
465 |
// Add the explicit BeanInfo data to our results. |
|
466 |
addPropertyDescriptors(explicitProperties); |
|
467 |
||
468 |
} else { |
|
469 |
||
470 |
// Apply some reflection to the current class. |
|
471 |
||
472 |
// First get an array of all the public methods at this level |
|
473 |
Method methodList[] = getPublicDeclaredMethods(beanClass); |
|
474 |
||
475 |
// Now analyze each method. |
|
476 |
for (int i = 0; i < methodList.length; i++) { |
|
477 |
Method method = methodList[i]; |
|
11668
138b661e3841
7122138: IAE thrown because Introspector ignores synthetic methods
malenkov
parents:
11140
diff
changeset
|
478 |
if (method == null) { |
2 | 479 |
continue; |
480 |
} |
|
481 |
// skip static methods. |
|
482 |
int mods = method.getModifiers(); |
|
483 |
if (Modifier.isStatic(mods)) { |
|
484 |
continue; |
|
485 |
} |
|
486 |
String name = method.getName(); |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
487 |
Class<?>[] argTypes = method.getParameterTypes(); |
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
488 |
Class<?> resultType = method.getReturnType(); |
2 | 489 |
int argCount = argTypes.length; |
490 |
PropertyDescriptor pd = null; |
|
491 |
||
492 |
if (name.length() <= 3 && !name.startsWith(IS_PREFIX)) { |
|
493 |
// Optimization. Don't bother with invalid propertyNames. |
|
494 |
continue; |
|
495 |
} |
|
496 |
||
497 |
try { |
|
498 |
||
499 |
if (argCount == 0) { |
|
500 |
if (name.startsWith(GET_PREFIX)) { |
|
501 |
// Simple getter |
|
502 |
pd = new PropertyDescriptor(this.beanClass, name.substring(3), method, null); |
|
503 |
} else if (resultType == boolean.class && name.startsWith(IS_PREFIX)) { |
|
504 |
// Boolean getter |
|
505 |
pd = new PropertyDescriptor(this.beanClass, name.substring(2), method, null); |
|
506 |
} |
|
507 |
} else if (argCount == 1) { |
|
3241
6fd229e009e7
6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents:
3239
diff
changeset
|
508 |
if (int.class.equals(argTypes[0]) && name.startsWith(GET_PREFIX)) { |
2 | 509 |
pd = new IndexedPropertyDescriptor(this.beanClass, name.substring(3), null, null, method, null); |
3241
6fd229e009e7
6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents:
3239
diff
changeset
|
510 |
} else if (void.class.equals(resultType) && name.startsWith(SET_PREFIX)) { |
2 | 511 |
// Simple setter |
512 |
pd = new PropertyDescriptor(this.beanClass, name.substring(3), null, method); |
|
513 |
if (throwsException(method, PropertyVetoException.class)) { |
|
514 |
pd.setConstrained(true); |
|
515 |
} |
|
516 |
} |
|
517 |
} else if (argCount == 2) { |
|
3241
6fd229e009e7
6723447: Introspector doesn't check return type for indexed property setters
malenkov
parents:
3239
diff
changeset
|
518 |
if (void.class.equals(resultType) && int.class.equals(argTypes[0]) && name.startsWith(SET_PREFIX)) { |
2 | 519 |
pd = new IndexedPropertyDescriptor(this.beanClass, name.substring(3), null, null, null, method); |
520 |
if (throwsException(method, PropertyVetoException.class)) { |
|
521 |
pd.setConstrained(true); |
|
522 |
} |
|
523 |
} |
|
524 |
} |
|
525 |
} catch (IntrospectionException ex) { |
|
526 |
// This happens if a PropertyDescriptor or IndexedPropertyDescriptor |
|
527 |
// constructor fins that the method violates details of the deisgn |
|
528 |
// pattern, e.g. by having an empty name, or a getter returning |
|
529 |
// void , or whatever. |
|
530 |
pd = null; |
|
531 |
} |
|
532 |
||
533 |
if (pd != null) { |
|
534 |
// If this class or one of its base classes is a PropertyChange |
|
535 |
// source, then we assume that any properties we discover are "bound". |
|
536 |
if (propertyChangeSource) { |
|
537 |
pd.setBound(true); |
|
538 |
} |
|
539 |
addPropertyDescriptor(pd); |
|
540 |
} |
|
541 |
} |
|
542 |
} |
|
543 |
processPropertyDescriptors(); |
|
544 |
||
545 |
// Allocate and populate the result array. |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
546 |
PropertyDescriptor result[] = |
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
547 |
properties.values().toArray(new PropertyDescriptor[properties.size()]); |
2 | 548 |
|
549 |
// Set the default index. |
|
550 |
if (defaultPropertyName != null) { |
|
551 |
for (int i = 0; i < result.length; i++) { |
|
552 |
if (defaultPropertyName.equals(result[i].getName())) { |
|
553 |
defaultPropertyIndex = i; |
|
554 |
} |
|
555 |
} |
|
556 |
} |
|
557 |
||
558 |
return result; |
|
559 |
} |
|
560 |
||
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
561 |
private HashMap<String, List<PropertyDescriptor>> pdStore = new HashMap<>(); |
2 | 562 |
|
563 |
/** |
|
564 |
* Adds the property descriptor to the list store. |
|
565 |
*/ |
|
566 |
private void addPropertyDescriptor(PropertyDescriptor pd) { |
|
567 |
String propName = pd.getName(); |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
568 |
List<PropertyDescriptor> list = pdStore.get(propName); |
2 | 569 |
if (list == null) { |
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
570 |
list = new ArrayList<>(); |
2 | 571 |
pdStore.put(propName, list); |
572 |
} |
|
573 |
if (this.beanClass != pd.getClass0()) { |
|
574 |
// replace existing property descriptor |
|
575 |
// only if we have types to resolve |
|
576 |
// in the context of this.beanClass |
|
577 |
try { |
|
578 |
String name = pd.getName(); |
|
579 |
Method read = pd.getReadMethod(); |
|
580 |
Method write = pd.getWriteMethod(); |
|
581 |
boolean cls = true; |
|
582 |
if (read != null) cls = cls && read.getGenericReturnType() instanceof Class; |
|
583 |
if (write != null) cls = cls && write.getGenericParameterTypes()[0] instanceof Class; |
|
584 |
if (pd instanceof IndexedPropertyDescriptor) { |
|
585 |
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor)pd; |
|
586 |
Method readI = ipd.getIndexedReadMethod(); |
|
587 |
Method writeI = ipd.getIndexedWriteMethod(); |
|
588 |
if (readI != null) cls = cls && readI.getGenericReturnType() instanceof Class; |
|
589 |
if (writeI != null) cls = cls && writeI.getGenericParameterTypes()[1] instanceof Class; |
|
590 |
if (!cls) { |
|
591 |
pd = new IndexedPropertyDescriptor(this.beanClass, name, read, write, readI, writeI); |
|
592 |
} |
|
593 |
} else if (!cls) { |
|
594 |
pd = new PropertyDescriptor(this.beanClass, name, read, write); |
|
595 |
} |
|
596 |
} catch ( IntrospectionException e ) { |
|
597 |
} |
|
598 |
} |
|
599 |
list.add(pd); |
|
600 |
} |
|
601 |
||
602 |
private void addPropertyDescriptors(PropertyDescriptor[] descriptors) { |
|
603 |
if (descriptors != null) { |
|
604 |
for (PropertyDescriptor descriptor : descriptors) { |
|
605 |
addPropertyDescriptor(descriptor); |
|
606 |
} |
|
607 |
} |
|
608 |
} |
|
609 |
||
610 |
private PropertyDescriptor[] getPropertyDescriptors(BeanInfo info) { |
|
611 |
PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); |
|
612 |
int index = info.getDefaultPropertyIndex(); |
|
613 |
if ((0 <= index) && (index < descriptors.length)) { |
|
614 |
this.defaultPropertyName = descriptors[index].getName(); |
|
615 |
} |
|
616 |
return descriptors; |
|
617 |
} |
|
618 |
||
619 |
/** |
|
620 |
* Populates the property descriptor table by merging the |
|
621 |
* lists of Property descriptors. |
|
622 |
*/ |
|
623 |
private void processPropertyDescriptors() { |
|
624 |
if (properties == null) { |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
625 |
properties = new TreeMap<>(); |
2 | 626 |
} |
627 |
||
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
628 |
List<PropertyDescriptor> list; |
2 | 629 |
|
630 |
PropertyDescriptor pd, gpd, spd; |
|
631 |
IndexedPropertyDescriptor ipd, igpd, ispd; |
|
632 |
||
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
633 |
Iterator<List<PropertyDescriptor>> it = pdStore.values().iterator(); |
2 | 634 |
while (it.hasNext()) { |
635 |
pd = null; gpd = null; spd = null; |
|
636 |
ipd = null; igpd = null; ispd = null; |
|
637 |
||
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
638 |
list = it.next(); |
2 | 639 |
|
640 |
// First pass. Find the latest getter method. Merge properties |
|
641 |
// of previous getter methods. |
|
642 |
for (int i = 0; i < list.size(); i++) { |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
643 |
pd = list.get(i); |
2 | 644 |
if (pd instanceof IndexedPropertyDescriptor) { |
645 |
ipd = (IndexedPropertyDescriptor)pd; |
|
646 |
if (ipd.getIndexedReadMethod() != null) { |
|
647 |
if (igpd != null) { |
|
648 |
igpd = new IndexedPropertyDescriptor(igpd, ipd); |
|
649 |
} else { |
|
650 |
igpd = ipd; |
|
651 |
} |
|
652 |
} |
|
653 |
} else { |
|
654 |
if (pd.getReadMethod() != null) { |
|
655 |
if (gpd != null) { |
|
656 |
// Don't replace the existing read |
|
657 |
// method if it starts with "is" |
|
658 |
Method method = gpd.getReadMethod(); |
|
659 |
if (!method.getName().startsWith(IS_PREFIX)) { |
|
660 |
gpd = new PropertyDescriptor(gpd, pd); |
|
661 |
} |
|
662 |
} else { |
|
663 |
gpd = pd; |
|
664 |
} |
|
665 |
} |
|
666 |
} |
|
667 |
} |
|
668 |
||
669 |
// Second pass. Find the latest setter method which |
|
670 |
// has the same type as the getter method. |
|
671 |
for (int i = 0; i < list.size(); i++) { |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
672 |
pd = list.get(i); |
2 | 673 |
if (pd instanceof IndexedPropertyDescriptor) { |
674 |
ipd = (IndexedPropertyDescriptor)pd; |
|
675 |
if (ipd.getIndexedWriteMethod() != null) { |
|
676 |
if (igpd != null) { |
|
677 |
if (igpd.getIndexedPropertyType() |
|
678 |
== ipd.getIndexedPropertyType()) { |
|
679 |
if (ispd != null) { |
|
680 |
ispd = new IndexedPropertyDescriptor(ispd, ipd); |
|
681 |
} else { |
|
682 |
ispd = ipd; |
|
683 |
} |
|
684 |
} |
|
685 |
} else { |
|
686 |
if (ispd != null) { |
|
687 |
ispd = new IndexedPropertyDescriptor(ispd, ipd); |
|
688 |
} else { |
|
689 |
ispd = ipd; |
|
690 |
} |
|
691 |
} |
|
692 |
} |
|
693 |
} else { |
|
694 |
if (pd.getWriteMethod() != null) { |
|
695 |
if (gpd != null) { |
|
696 |
if (gpd.getPropertyType() == pd.getPropertyType()) { |
|
697 |
if (spd != null) { |
|
698 |
spd = new PropertyDescriptor(spd, pd); |
|
699 |
} else { |
|
700 |
spd = pd; |
|
701 |
} |
|
702 |
} |
|
703 |
} else { |
|
704 |
if (spd != null) { |
|
705 |
spd = new PropertyDescriptor(spd, pd); |
|
706 |
} else { |
|
707 |
spd = pd; |
|
708 |
} |
|
709 |
} |
|
710 |
} |
|
711 |
} |
|
712 |
} |
|
713 |
||
714 |
// At this stage we should have either PDs or IPDs for the |
|
715 |
// representative getters and setters. The order at which the |
|
716 |
// property descriptors are determined represent the |
|
717 |
// precedence of the property ordering. |
|
718 |
pd = null; ipd = null; |
|
719 |
||
720 |
if (igpd != null && ispd != null) { |
|
721 |
// Complete indexed properties set |
|
722 |
// Merge any classic property descriptors |
|
723 |
if (gpd != null) { |
|
724 |
PropertyDescriptor tpd = mergePropertyDescriptor(igpd, gpd); |
|
725 |
if (tpd instanceof IndexedPropertyDescriptor) { |
|
726 |
igpd = (IndexedPropertyDescriptor)tpd; |
|
727 |
} |
|
728 |
} |
|
729 |
if (spd != null) { |
|
730 |
PropertyDescriptor tpd = mergePropertyDescriptor(ispd, spd); |
|
731 |
if (tpd instanceof IndexedPropertyDescriptor) { |
|
732 |
ispd = (IndexedPropertyDescriptor)tpd; |
|
733 |
} |
|
734 |
} |
|
735 |
if (igpd == ispd) { |
|
736 |
pd = igpd; |
|
737 |
} else { |
|
738 |
pd = mergePropertyDescriptor(igpd, ispd); |
|
739 |
} |
|
740 |
} else if (gpd != null && spd != null) { |
|
741 |
// Complete simple properties set |
|
742 |
if (gpd == spd) { |
|
743 |
pd = gpd; |
|
744 |
} else { |
|
745 |
pd = mergePropertyDescriptor(gpd, spd); |
|
746 |
} |
|
747 |
} else if (ispd != null) { |
|
748 |
// indexed setter |
|
749 |
pd = ispd; |
|
750 |
// Merge any classic property descriptors |
|
751 |
if (spd != null) { |
|
752 |
pd = mergePropertyDescriptor(ispd, spd); |
|
753 |
} |
|
754 |
if (gpd != null) { |
|
755 |
pd = mergePropertyDescriptor(ispd, gpd); |
|
756 |
} |
|
757 |
} else if (igpd != null) { |
|
758 |
// indexed getter |
|
759 |
pd = igpd; |
|
760 |
// Merge any classic property descriptors |
|
761 |
if (gpd != null) { |
|
762 |
pd = mergePropertyDescriptor(igpd, gpd); |
|
763 |
} |
|
764 |
if (spd != null) { |
|
765 |
pd = mergePropertyDescriptor(igpd, spd); |
|
766 |
} |
|
767 |
} else if (spd != null) { |
|
768 |
// simple setter |
|
769 |
pd = spd; |
|
770 |
} else if (gpd != null) { |
|
771 |
// simple getter |
|
772 |
pd = gpd; |
|
773 |
} |
|
774 |
||
775 |
// Very special case to ensure that an IndexedPropertyDescriptor |
|
776 |
// doesn't contain less information than the enclosed |
|
777 |
// PropertyDescriptor. If it does, then recreate as a |
|
778 |
// PropertyDescriptor. See 4168833 |
|
779 |
if (pd instanceof IndexedPropertyDescriptor) { |
|
780 |
ipd = (IndexedPropertyDescriptor)pd; |
|
781 |
if (ipd.getIndexedReadMethod() == null && ipd.getIndexedWriteMethod() == null) { |
|
782 |
pd = new PropertyDescriptor(ipd); |
|
783 |
} |
|
784 |
} |
|
785 |
||
786 |
// Find the first property descriptor |
|
787 |
// which does not have getter and setter methods. |
|
788 |
// See regression bug 4984912. |
|
789 |
if ( (pd == null) && (list.size() > 0) ) { |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
790 |
pd = list.get(0); |
2 | 791 |
} |
792 |
||
793 |
if (pd != null) { |
|
794 |
properties.put(pd.getName(), pd); |
|
795 |
} |
|
796 |
} |
|
797 |
} |
|
798 |
||
799 |
/** |
|
800 |
* Adds the property descriptor to the indexedproperty descriptor only if the |
|
801 |
* types are the same. |
|
802 |
* |
|
803 |
* The most specific property descriptor will take precedence. |
|
804 |
*/ |
|
805 |
private PropertyDescriptor mergePropertyDescriptor(IndexedPropertyDescriptor ipd, |
|
806 |
PropertyDescriptor pd) { |
|
807 |
PropertyDescriptor result = null; |
|
808 |
||
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
809 |
Class<?> propType = pd.getPropertyType(); |
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
810 |
Class<?> ipropType = ipd.getIndexedPropertyType(); |
2 | 811 |
|
812 |
if (propType.isArray() && propType.getComponentType() == ipropType) { |
|
813 |
if (pd.getClass0().isAssignableFrom(ipd.getClass0())) { |
|
814 |
result = new IndexedPropertyDescriptor(pd, ipd); |
|
815 |
} else { |
|
816 |
result = new IndexedPropertyDescriptor(ipd, pd); |
|
817 |
} |
|
818 |
} else { |
|
819 |
// Cannot merge the pd because of type mismatch |
|
820 |
// Return the most specific pd |
|
821 |
if (pd.getClass0().isAssignableFrom(ipd.getClass0())) { |
|
822 |
result = ipd; |
|
823 |
} else { |
|
824 |
result = pd; |
|
825 |
// Try to add methods which may have been lost in the type change |
|
826 |
// See 4168833 |
|
827 |
Method write = result.getWriteMethod(); |
|
828 |
Method read = result.getReadMethod(); |
|
829 |
||
830 |
if (read == null && write != null) { |
|
6657
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
831 |
read = findMethod(result.getClass0(), |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
832 |
GET_PREFIX + NameGenerator.capitalize(result.getName()), 0); |
2 | 833 |
if (read != null) { |
834 |
try { |
|
835 |
result.setReadMethod(read); |
|
836 |
} catch (IntrospectionException ex) { |
|
837 |
// no consequences for failure. |
|
838 |
} |
|
839 |
} |
|
840 |
} |
|
841 |
if (write == null && read != null) { |
|
6657
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
842 |
write = findMethod(result.getClass0(), |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
843 |
SET_PREFIX + NameGenerator.capitalize(result.getName()), 1, |
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
844 |
new Class<?>[] { FeatureDescriptor.getReturnType(result.getClass0(), read) }); |
2 | 845 |
if (write != null) { |
846 |
try { |
|
847 |
result.setWriteMethod(write); |
|
848 |
} catch (IntrospectionException ex) { |
|
849 |
// no consequences for failure. |
|
850 |
} |
|
851 |
} |
|
852 |
} |
|
853 |
} |
|
854 |
} |
|
855 |
return result; |
|
856 |
} |
|
857 |
||
858 |
// Handle regular pd merge |
|
859 |
private PropertyDescriptor mergePropertyDescriptor(PropertyDescriptor pd1, |
|
860 |
PropertyDescriptor pd2) { |
|
861 |
if (pd1.getClass0().isAssignableFrom(pd2.getClass0())) { |
|
862 |
return new PropertyDescriptor(pd1, pd2); |
|
863 |
} else { |
|
864 |
return new PropertyDescriptor(pd2, pd1); |
|
865 |
} |
|
866 |
} |
|
867 |
||
868 |
// Handle regular ipd merge |
|
869 |
private PropertyDescriptor mergePropertyDescriptor(IndexedPropertyDescriptor ipd1, |
|
870 |
IndexedPropertyDescriptor ipd2) { |
|
871 |
if (ipd1.getClass0().isAssignableFrom(ipd2.getClass0())) { |
|
872 |
return new IndexedPropertyDescriptor(ipd1, ipd2); |
|
873 |
} else { |
|
874 |
return new IndexedPropertyDescriptor(ipd2, ipd1); |
|
875 |
} |
|
876 |
} |
|
877 |
||
878 |
/** |
|
879 |
* @return An array of EventSetDescriptors describing the kinds of |
|
880 |
* events fired by the target bean. |
|
881 |
*/ |
|
882 |
private EventSetDescriptor[] getTargetEventInfo() throws IntrospectionException { |
|
883 |
if (events == null) { |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
884 |
events = new HashMap<>(); |
2 | 885 |
} |
886 |
||
887 |
// Check if the bean has its own BeanInfo that will provide |
|
888 |
// explicit information. |
|
889 |
EventSetDescriptor[] explicitEvents = null; |
|
890 |
if (explicitBeanInfo != null) { |
|
891 |
explicitEvents = explicitBeanInfo.getEventSetDescriptors(); |
|
892 |
int ix = explicitBeanInfo.getDefaultEventIndex(); |
|
893 |
if (ix >= 0 && ix < explicitEvents.length) { |
|
894 |
defaultEventName = explicitEvents[ix].getName(); |
|
895 |
} |
|
896 |
} |
|
897 |
||
898 |
if (explicitEvents == null && superBeanInfo != null) { |
|
899 |
// We have no explicit BeanInfo events. Check with our parent. |
|
900 |
EventSetDescriptor supers[] = superBeanInfo.getEventSetDescriptors(); |
|
901 |
for (int i = 0 ; i < supers.length; i++) { |
|
902 |
addEvent(supers[i]); |
|
903 |
} |
|
904 |
int ix = superBeanInfo.getDefaultEventIndex(); |
|
905 |
if (ix >= 0 && ix < supers.length) { |
|
906 |
defaultEventName = supers[ix].getName(); |
|
907 |
} |
|
908 |
} |
|
909 |
||
910 |
for (int i = 0; i < additionalBeanInfo.length; i++) { |
|
911 |
EventSetDescriptor additional[] = additionalBeanInfo[i].getEventSetDescriptors(); |
|
912 |
if (additional != null) { |
|
913 |
for (int j = 0 ; j < additional.length; j++) { |
|
914 |
addEvent(additional[j]); |
|
915 |
} |
|
916 |
} |
|
917 |
} |
|
918 |
||
919 |
if (explicitEvents != null) { |
|
920 |
// Add the explicit explicitBeanInfo data to our results. |
|
921 |
for (int i = 0 ; i < explicitEvents.length; i++) { |
|
922 |
addEvent(explicitEvents[i]); |
|
923 |
} |
|
924 |
||
925 |
} else { |
|
926 |
||
927 |
// Apply some reflection to the current class. |
|
928 |
||
929 |
// Get an array of all the public beans methods at this level |
|
930 |
Method methodList[] = getPublicDeclaredMethods(beanClass); |
|
931 |
||
932 |
// Find all suitable "add", "remove" and "get" Listener methods |
|
933 |
// The name of the listener type is the key for these hashtables |
|
934 |
// i.e, ActionListener |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
935 |
Map<String, Method> adds = null; |
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
936 |
Map<String, Method> removes = null; |
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
937 |
Map<String, Method> gets = null; |
2 | 938 |
|
939 |
for (int i = 0; i < methodList.length; i++) { |
|
940 |
Method method = methodList[i]; |
|
941 |
if (method == null) { |
|
942 |
continue; |
|
943 |
} |
|
944 |
// skip static methods. |
|
945 |
int mods = method.getModifiers(); |
|
946 |
if (Modifier.isStatic(mods)) { |
|
947 |
continue; |
|
948 |
} |
|
949 |
String name = method.getName(); |
|
950 |
// Optimization avoid getParameterTypes |
|
951 |
if (!name.startsWith(ADD_PREFIX) && !name.startsWith(REMOVE_PREFIX) |
|
952 |
&& !name.startsWith(GET_PREFIX)) { |
|
953 |
continue; |
|
954 |
} |
|
955 |
||
13356 | 956 |
if (name.startsWith(ADD_PREFIX)) { |
957 |
Class<?> returnType = method.getReturnType(); |
|
958 |
if (returnType == void.class) { |
|
959 |
Type[] parameterTypes = method.getGenericParameterTypes(); |
|
960 |
if (parameterTypes.length == 1) { |
|
961 |
Class<?> type = TypeResolver.erase(TypeResolver.resolveInClass(beanClass, parameterTypes[0])); |
|
962 |
if (Introspector.isSubclass(type, eventListenerType)) { |
|
963 |
String listenerName = name.substring(3); |
|
964 |
if (listenerName.length() > 0 && |
|
965 |
type.getName().endsWith(listenerName)) { |
|
966 |
if (adds == null) { |
|
967 |
adds = new HashMap<>(); |
|
968 |
} |
|
969 |
adds.put(listenerName, method); |
|
970 |
} |
|
971 |
} |
|
2 | 972 |
} |
973 |
} |
|
974 |
} |
|
13356 | 975 |
else if (name.startsWith(REMOVE_PREFIX)) { |
976 |
Class<?> returnType = method.getReturnType(); |
|
977 |
if (returnType == void.class) { |
|
978 |
Type[] parameterTypes = method.getGenericParameterTypes(); |
|
979 |
if (parameterTypes.length == 1) { |
|
980 |
Class<?> type = TypeResolver.erase(TypeResolver.resolveInClass(beanClass, parameterTypes[0])); |
|
981 |
if (Introspector.isSubclass(type, eventListenerType)) { |
|
982 |
String listenerName = name.substring(6); |
|
983 |
if (listenerName.length() > 0 && |
|
984 |
type.getName().endsWith(listenerName)) { |
|
985 |
if (removes == null) { |
|
986 |
removes = new HashMap<>(); |
|
987 |
} |
|
988 |
removes.put(listenerName, method); |
|
989 |
} |
|
990 |
} |
|
2 | 991 |
} |
992 |
} |
|
993 |
} |
|
13356 | 994 |
else if (name.startsWith(GET_PREFIX)) { |
995 |
Class<?>[] parameterTypes = method.getParameterTypes(); |
|
996 |
if (parameterTypes.length == 0) { |
|
997 |
Class<?> returnType = FeatureDescriptor.getReturnType(beanClass, method); |
|
998 |
if (returnType.isArray()) { |
|
999 |
Class<?> type = returnType.getComponentType(); |
|
1000 |
if (Introspector.isSubclass(type, eventListenerType)) { |
|
1001 |
String listenerName = name.substring(3, name.length() - 1); |
|
1002 |
if (listenerName.length() > 0 && |
|
1003 |
type.getName().endsWith(listenerName)) { |
|
1004 |
if (gets == null) { |
|
1005 |
gets = new HashMap<>(); |
|
1006 |
} |
|
1007 |
gets.put(listenerName, method); |
|
1008 |
} |
|
1009 |
} |
|
2 | 1010 |
} |
1011 |
} |
|
1012 |
} |
|
1013 |
} |
|
1014 |
||
1015 |
if (adds != null && removes != null) { |
|
1016 |
// Now look for matching addFooListener+removeFooListener pairs. |
|
1017 |
// Bonus if there is a matching getFooListeners method as well. |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1018 |
Iterator<String> keys = adds.keySet().iterator(); |
2 | 1019 |
while (keys.hasNext()) { |
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1020 |
String listenerName = keys.next(); |
2 | 1021 |
// Skip any "add" which doesn't have a matching "remove" or |
1022 |
// a listener name that doesn't end with Listener |
|
1023 |
if (removes.get(listenerName) == null || !listenerName.endsWith("Listener")) { |
|
1024 |
continue; |
|
1025 |
} |
|
1026 |
String eventName = decapitalize(listenerName.substring(0, listenerName.length()-8)); |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1027 |
Method addMethod = adds.get(listenerName); |
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1028 |
Method removeMethod = removes.get(listenerName); |
2 | 1029 |
Method getMethod = null; |
1030 |
if (gets != null) { |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1031 |
getMethod = gets.get(listenerName); |
2 | 1032 |
} |
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1033 |
Class<?> argType = FeatureDescriptor.getParameterTypes(beanClass, addMethod)[0]; |
2 | 1034 |
|
1035 |
// generate a list of Method objects for each of the target methods: |
|
1036 |
Method allMethods[] = getPublicDeclaredMethods(argType); |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1037 |
List<Method> validMethods = new ArrayList<>(allMethods.length); |
2 | 1038 |
for (int i = 0; i < allMethods.length; i++) { |
1039 |
if (allMethods[i] == null) { |
|
1040 |
continue; |
|
1041 |
} |
|
1042 |
||
1043 |
if (isEventHandler(allMethods[i])) { |
|
1044 |
validMethods.add(allMethods[i]); |
|
1045 |
} |
|
1046 |
} |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1047 |
Method[] methods = validMethods.toArray(new Method[validMethods.size()]); |
2 | 1048 |
|
1049 |
EventSetDescriptor esd = new EventSetDescriptor(eventName, argType, |
|
1050 |
methods, addMethod, |
|
1051 |
removeMethod, |
|
1052 |
getMethod); |
|
1053 |
||
1054 |
// If the adder method throws the TooManyListenersException then it |
|
1055 |
// is a Unicast event source. |
|
1056 |
if (throwsException(addMethod, |
|
1057 |
java.util.TooManyListenersException.class)) { |
|
1058 |
esd.setUnicast(true); |
|
1059 |
} |
|
1060 |
addEvent(esd); |
|
1061 |
} |
|
1062 |
} // if (adds != null ... |
|
1063 |
} |
|
1064 |
EventSetDescriptor[] result; |
|
1065 |
if (events.size() == 0) { |
|
1066 |
result = EMPTY_EVENTSETDESCRIPTORS; |
|
1067 |
} else { |
|
1068 |
// Allocate and populate the result array. |
|
1069 |
result = new EventSetDescriptor[events.size()]; |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1070 |
result = events.values().toArray(result); |
2 | 1071 |
|
1072 |
// Set the default index. |
|
1073 |
if (defaultEventName != null) { |
|
1074 |
for (int i = 0; i < result.length; i++) { |
|
1075 |
if (defaultEventName.equals(result[i].getName())) { |
|
1076 |
defaultEventIndex = i; |
|
1077 |
} |
|
1078 |
} |
|
1079 |
} |
|
1080 |
} |
|
1081 |
return result; |
|
1082 |
} |
|
1083 |
||
1084 |
private void addEvent(EventSetDescriptor esd) { |
|
1085 |
String key = esd.getName(); |
|
1086 |
if (esd.getName().equals("propertyChange")) { |
|
1087 |
propertyChangeSource = true; |
|
1088 |
} |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1089 |
EventSetDescriptor old = events.get(key); |
2 | 1090 |
if (old == null) { |
1091 |
events.put(key, esd); |
|
1092 |
return; |
|
1093 |
} |
|
1094 |
EventSetDescriptor composite = new EventSetDescriptor(old, esd); |
|
1095 |
events.put(key, composite); |
|
1096 |
} |
|
1097 |
||
1098 |
/** |
|
1099 |
* @return An array of MethodDescriptors describing the private |
|
1100 |
* methods supported by the target bean. |
|
1101 |
*/ |
|
1102 |
private MethodDescriptor[] getTargetMethodInfo() { |
|
1103 |
if (methods == null) { |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1104 |
methods = new HashMap<>(100); |
2 | 1105 |
} |
1106 |
||
1107 |
// Check if the bean has its own BeanInfo that will provide |
|
1108 |
// explicit information. |
|
1109 |
MethodDescriptor[] explicitMethods = null; |
|
1110 |
if (explicitBeanInfo != null) { |
|
1111 |
explicitMethods = explicitBeanInfo.getMethodDescriptors(); |
|
1112 |
} |
|
1113 |
||
1114 |
if (explicitMethods == null && superBeanInfo != null) { |
|
1115 |
// We have no explicit BeanInfo methods. Check with our parent. |
|
1116 |
MethodDescriptor supers[] = superBeanInfo.getMethodDescriptors(); |
|
1117 |
for (int i = 0 ; i < supers.length; i++) { |
|
1118 |
addMethod(supers[i]); |
|
1119 |
} |
|
1120 |
} |
|
1121 |
||
1122 |
for (int i = 0; i < additionalBeanInfo.length; i++) { |
|
1123 |
MethodDescriptor additional[] = additionalBeanInfo[i].getMethodDescriptors(); |
|
1124 |
if (additional != null) { |
|
1125 |
for (int j = 0 ; j < additional.length; j++) { |
|
1126 |
addMethod(additional[j]); |
|
1127 |
} |
|
1128 |
} |
|
1129 |
} |
|
1130 |
||
1131 |
if (explicitMethods != null) { |
|
1132 |
// Add the explicit explicitBeanInfo data to our results. |
|
1133 |
for (int i = 0 ; i < explicitMethods.length; i++) { |
|
1134 |
addMethod(explicitMethods[i]); |
|
1135 |
} |
|
1136 |
||
1137 |
} else { |
|
1138 |
||
1139 |
// Apply some reflection to the current class. |
|
1140 |
||
1141 |
// First get an array of all the beans methods at this level |
|
1142 |
Method methodList[] = getPublicDeclaredMethods(beanClass); |
|
1143 |
||
1144 |
// Now analyze each method. |
|
1145 |
for (int i = 0; i < methodList.length; i++) { |
|
1146 |
Method method = methodList[i]; |
|
1147 |
if (method == null) { |
|
1148 |
continue; |
|
1149 |
} |
|
1150 |
MethodDescriptor md = new MethodDescriptor(method); |
|
1151 |
addMethod(md); |
|
1152 |
} |
|
1153 |
} |
|
1154 |
||
1155 |
// Allocate and populate the result array. |
|
1156 |
MethodDescriptor result[] = new MethodDescriptor[methods.size()]; |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1157 |
result = methods.values().toArray(result); |
2 | 1158 |
|
1159 |
return result; |
|
1160 |
} |
|
1161 |
||
1162 |
private void addMethod(MethodDescriptor md) { |
|
1163 |
// We have to be careful here to distinguish method by both name |
|
1164 |
// and argument lists. |
|
1165 |
// This method gets called a *lot, so we try to be efficient. |
|
1166 |
String name = md.getName(); |
|
1167 |
||
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1168 |
MethodDescriptor old = methods.get(name); |
2 | 1169 |
if (old == null) { |
1170 |
// This is the common case. |
|
1171 |
methods.put(name, md); |
|
1172 |
return; |
|
1173 |
} |
|
1174 |
||
1175 |
// We have a collision on method names. This is rare. |
|
1176 |
||
1177 |
// Check if old and md have the same type. |
|
1178 |
String[] p1 = md.getParamNames(); |
|
1179 |
String[] p2 = old.getParamNames(); |
|
1180 |
||
1181 |
boolean match = false; |
|
1182 |
if (p1.length == p2.length) { |
|
1183 |
match = true; |
|
1184 |
for (int i = 0; i < p1.length; i++) { |
|
1185 |
if (p1[i] != p2[i]) { |
|
1186 |
match = false; |
|
1187 |
break; |
|
1188 |
} |
|
1189 |
} |
|
1190 |
} |
|
1191 |
if (match) { |
|
1192 |
MethodDescriptor composite = new MethodDescriptor(old, md); |
|
1193 |
methods.put(name, composite); |
|
1194 |
return; |
|
1195 |
} |
|
1196 |
||
1197 |
// We have a collision on method names with different type signatures. |
|
1198 |
// This is very rare. |
|
1199 |
||
1200 |
String longKey = makeQualifiedMethodName(name, p1); |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1201 |
old = methods.get(longKey); |
2 | 1202 |
if (old == null) { |
1203 |
methods.put(longKey, md); |
|
1204 |
return; |
|
1205 |
} |
|
1206 |
MethodDescriptor composite = new MethodDescriptor(old, md); |
|
1207 |
methods.put(longKey, composite); |
|
1208 |
} |
|
1209 |
||
1210 |
/** |
|
1211 |
* Creates a key for a method in a method cache. |
|
1212 |
*/ |
|
1213 |
private static String makeQualifiedMethodName(String name, String[] params) { |
|
1214 |
StringBuffer sb = new StringBuffer(name); |
|
1215 |
sb.append('='); |
|
1216 |
for (int i = 0; i < params.length; i++) { |
|
1217 |
sb.append(':'); |
|
1218 |
sb.append(params[i]); |
|
1219 |
} |
|
1220 |
return sb.toString(); |
|
1221 |
} |
|
1222 |
||
1223 |
private int getTargetDefaultEventIndex() { |
|
1224 |
return defaultEventIndex; |
|
1225 |
} |
|
1226 |
||
1227 |
private int getTargetDefaultPropertyIndex() { |
|
1228 |
return defaultPropertyIndex; |
|
1229 |
} |
|
1230 |
||
1231 |
private BeanDescriptor getTargetBeanDescriptor() { |
|
1232 |
// Use explicit info, if available, |
|
1233 |
if (explicitBeanInfo != null) { |
|
1234 |
BeanDescriptor bd = explicitBeanInfo.getBeanDescriptor(); |
|
1235 |
if (bd != null) { |
|
1236 |
return (bd); |
|
1237 |
} |
|
1238 |
} |
|
1239 |
// OK, fabricate a default BeanDescriptor. |
|
7249
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1240 |
return new BeanDescriptor(this.beanClass, findCustomizerClass(this.beanClass)); |
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1241 |
} |
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1242 |
|
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1243 |
private static Class<?> findCustomizerClass(Class<?> type) { |
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1244 |
String name = type.getName() + "Customizer"; |
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1245 |
try { |
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1246 |
type = ClassFinder.findClass(name, type.getClassLoader()); |
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1247 |
// Each customizer should inherit java.awt.Component and implement java.beans.Customizer |
8760
83843c0b84f7
7021517: java.beans code comments have issues with HTML4 compliance
malenkov
parents:
7249
diff
changeset
|
1248 |
// according to the section 9.3 of JavaBeans™ specification |
7249
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1249 |
if (Component.class.isAssignableFrom(type) && Customizer.class.isAssignableFrom(type)) { |
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1250 |
return type; |
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1251 |
} |
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1252 |
} |
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1253 |
catch (Exception exception) { |
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1254 |
// ignore any exceptions |
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1255 |
} |
34380acce3b6
6447751: Bean Customizer should be detectable by reflection name alone
malenkov
parents:
6657
diff
changeset
|
1256 |
return null; |
2 | 1257 |
} |
1258 |
||
1259 |
private boolean isEventHandler(Method m) { |
|
1260 |
// We assume that a method is an event handler if it has a single |
|
1261 |
// argument, whose type inherit from java.util.Event. |
|
13356 | 1262 |
Type argTypes[] = m.getGenericParameterTypes(); |
2 | 1263 |
if (argTypes.length != 1) { |
1264 |
return false; |
|
1265 |
} |
|
13356 | 1266 |
return isSubclass(TypeResolver.erase(TypeResolver.resolveInClass(beanClass, argTypes[0])), EventObject.class); |
2 | 1267 |
} |
1268 |
||
1269 |
/* |
|
1270 |
* Internal method to return *public* methods within a class. |
|
1271 |
*/ |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1272 |
private static Method[] getPublicDeclaredMethods(Class<?> clz) { |
2 | 1273 |
// Looking up Class.getDeclaredMethods is relatively expensive, |
1274 |
// so we cache the results. |
|
1275 |
if (!ReflectUtil.isPackageAccessible(clz)) { |
|
1276 |
return new Method[0]; |
|
1277 |
} |
|
11086
09b1d6383d0b
7064279: Introspector.getBeanInfo() should release some resources in timely manner
malenkov
parents:
9035
diff
changeset
|
1278 |
synchronized (declaredMethodCache) { |
4382
c0759b1ccb56
5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents:
3476
diff
changeset
|
1279 |
Method[] result = declaredMethodCache.get(clz); |
c0759b1ccb56
5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents:
3476
diff
changeset
|
1280 |
if (result == null) { |
c0759b1ccb56
5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents:
3476
diff
changeset
|
1281 |
result = clz.getMethods(); |
c0759b1ccb56
5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents:
3476
diff
changeset
|
1282 |
for (int i = 0; i < result.length; i++) { |
c0759b1ccb56
5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents:
3476
diff
changeset
|
1283 |
Method method = result[i]; |
c0759b1ccb56
5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents:
3476
diff
changeset
|
1284 |
if (!method.getDeclaringClass().equals(clz)) { |
c0759b1ccb56
5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents:
3476
diff
changeset
|
1285 |
result[i] = null; |
c0759b1ccb56
5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents:
3476
diff
changeset
|
1286 |
} |
2 | 1287 |
} |
4382
c0759b1ccb56
5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents:
3476
diff
changeset
|
1288 |
declaredMethodCache.put(clz, result); |
2 | 1289 |
} |
4382
c0759b1ccb56
5102804: Memory leak in Introspector.getBeanInfo(Class) for custom BeanInfo: Class param
malenkov
parents:
3476
diff
changeset
|
1290 |
return result; |
2 | 1291 |
} |
1292 |
} |
|
1293 |
||
1294 |
//====================================================================== |
|
1295 |
// Package private support methods. |
|
1296 |
//====================================================================== |
|
1297 |
||
6657
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1298 |
/** |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1299 |
* Internal support for finding a target methodName with a given |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1300 |
* parameter list on a given class. |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1301 |
*/ |
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1302 |
private static Method internalFindMethod(Class<?> start, String methodName, |
6657
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1303 |
int argCount, Class args[]) { |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1304 |
// For overriden methods we need to find the most derived version. |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1305 |
// So we start with the given class and walk up the superclass chain. |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1306 |
|
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1307 |
Method method = null; |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1308 |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1309 |
for (Class<?> cl = start; cl != null; cl = cl.getSuperclass()) { |
6657
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1310 |
Method methods[] = getPublicDeclaredMethods(cl); |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1311 |
for (int i = 0; i < methods.length; i++) { |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1312 |
method = methods[i]; |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1313 |
if (method == null) { |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1314 |
continue; |
2 | 1315 |
} |
6657
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1316 |
|
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1317 |
// make sure method signature matches. |
13356 | 1318 |
if (method.getName().equals(methodName)) { |
1319 |
Type[] params = method.getGenericParameterTypes(); |
|
1320 |
if (params.length == argCount) { |
|
1321 |
if (args != null) { |
|
1322 |
boolean different = false; |
|
1323 |
if (argCount > 0) { |
|
1324 |
for (int j = 0; j < argCount; j++) { |
|
1325 |
if (TypeResolver.erase(TypeResolver.resolveInClass(start, params[j])) != args[j]) { |
|
1326 |
different = true; |
|
1327 |
continue; |
|
1328 |
} |
|
1329 |
} |
|
1330 |
if (different) { |
|
6657
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1331 |
continue; |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1332 |
} |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1333 |
} |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1334 |
} |
13356 | 1335 |
return method; |
6657
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1336 |
} |
2 | 1337 |
} |
1338 |
} |
|
1339 |
} |
|
6657
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1340 |
method = null; |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1341 |
|
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1342 |
// Now check any inherited interfaces. This is necessary both when |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1343 |
// the argument class is itself an interface, and when the argument |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1344 |
// class is an abstract class. |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1345 |
Class ifcs[] = start.getInterfaces(); |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1346 |
for (int i = 0 ; i < ifcs.length; i++) { |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1347 |
// Note: The original implementation had both methods calling |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1348 |
// the 3 arg method. This is preserved but perhaps it should |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1349 |
// pass the args array instead of null. |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1350 |
method = internalFindMethod(ifcs[i], methodName, argCount, null); |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1351 |
if (method != null) { |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1352 |
break; |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1353 |
} |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1354 |
} |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1355 |
return method; |
2 | 1356 |
} |
1357 |
||
6657
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1358 |
/** |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1359 |
* Find a target methodName on a given class. |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1360 |
*/ |
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1361 |
static Method findMethod(Class<?> cls, String methodName, int argCount) { |
6657
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1362 |
return findMethod(cls, methodName, argCount, null); |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1363 |
} |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1364 |
|
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1365 |
/** |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1366 |
* Find a target methodName with specific parameter list on a given class. |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1367 |
* <p> |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1368 |
* Used in the contructors of the EventSetDescriptor, |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1369 |
* PropertyDescriptor and the IndexedPropertyDescriptor. |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1370 |
* <p> |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1371 |
* @param cls The Class object on which to retrieve the method. |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1372 |
* @param methodName Name of the method. |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1373 |
* @param argCount Number of arguments for the desired method. |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1374 |
* @param args Array of argument types for the method. |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1375 |
* @return the method or null if not found |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1376 |
*/ |
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1377 |
static Method findMethod(Class<?> cls, String methodName, int argCount, |
6657
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1378 |
Class args[]) { |
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1379 |
if (methodName == null) { |
2 | 1380 |
return null; |
1381 |
} |
|
6657
15dbb366c6a3
6976577: JCK7 api/java_beans/EventSetDescriptor/descriptions.html#Ctor1 fails since jdk7 b102
malenkov
parents:
5959
diff
changeset
|
1382 |
return internalFindMethod(cls, methodName, argCount, args); |
2 | 1383 |
} |
1384 |
||
1385 |
/** |
|
1386 |
* Return true if class a is either equivalent to class b, or |
|
1387 |
* if class a is a subclass of class b, i.e. if a either "extends" |
|
1388 |
* or "implements" b. |
|
1389 |
* Note tht either or both "Class" objects may represent interfaces. |
|
1390 |
*/ |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1391 |
static boolean isSubclass(Class<?> a, Class<?> b) { |
2 | 1392 |
// We rely on the fact that for any given java class or |
1393 |
// primtitive type there is a unqiue Class object, so |
|
1394 |
// we can use object equivalence in the comparisons. |
|
1395 |
if (a == b) { |
|
1396 |
return true; |
|
1397 |
} |
|
1398 |
if (a == null || b == null) { |
|
1399 |
return false; |
|
1400 |
} |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1401 |
for (Class<?> x = a; x != null; x = x.getSuperclass()) { |
2 | 1402 |
if (x == b) { |
1403 |
return true; |
|
1404 |
} |
|
1405 |
if (b.isInterface()) { |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1406 |
Class<?>[] interfaces = x.getInterfaces(); |
2 | 1407 |
for (int i = 0; i < interfaces.length; i++) { |
1408 |
if (isSubclass(interfaces[i], b)) { |
|
1409 |
return true; |
|
1410 |
} |
|
1411 |
} |
|
1412 |
} |
|
1413 |
} |
|
1414 |
return false; |
|
1415 |
} |
|
1416 |
||
1417 |
/** |
|
1418 |
* Return true iff the given method throws the given exception. |
|
1419 |
*/ |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1420 |
private boolean throwsException(Method method, Class<?> exception) { |
2 | 1421 |
Class exs[] = method.getExceptionTypes(); |
1422 |
for (int i = 0; i < exs.length; i++) { |
|
1423 |
if (exs[i] == exception) { |
|
1424 |
return true; |
|
1425 |
} |
|
1426 |
} |
|
1427 |
return false; |
|
1428 |
} |
|
1429 |
||
1430 |
/** |
|
1431 |
* Try to create an instance of a named class. |
|
1432 |
* First try the classloader of "sibling", then try the system |
|
1433 |
* classloader then the class loader of the current Thread. |
|
1434 |
*/ |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1435 |
static Object instantiate(Class<?> sibling, String className) |
2 | 1436 |
throws InstantiationException, IllegalAccessException, |
1437 |
ClassNotFoundException { |
|
1438 |
// First check with sibling's classloader (if any). |
|
1439 |
ClassLoader cl = sibling.getClassLoader(); |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1440 |
Class<?> cls = ClassFinder.findClass(className, cl); |
2 | 1441 |
return cls.newInstance(); |
1442 |
} |
|
1443 |
||
1444 |
} // end class Introspector |
|
1445 |
||
1446 |
//=========================================================================== |
|
1447 |
||
1448 |
/** |
|
1449 |
* Package private implementation support class for Introspector's |
|
1450 |
* internal use. |
|
1451 |
* <p> |
|
1452 |
* Mostly this is used as a placeholder for the descriptors. |
|
1453 |
*/ |
|
1454 |
||
1455 |
class GenericBeanInfo extends SimpleBeanInfo { |
|
1456 |
||
1457 |
private BeanDescriptor beanDescriptor; |
|
1458 |
private EventSetDescriptor[] events; |
|
1459 |
private int defaultEvent; |
|
1460 |
private PropertyDescriptor[] properties; |
|
1461 |
private int defaultProperty; |
|
1462 |
private MethodDescriptor[] methods; |
|
4851
4f7de5eeeac7
6921057: REGRESSION: persistence delegate issue on Windows and Linux against 5.u23b03/6u17b11
malenkov
parents:
4393
diff
changeset
|
1463 |
private final Reference<BeanInfo> targetBeanInfoRef; |
2 | 1464 |
|
1465 |
public GenericBeanInfo(BeanDescriptor beanDescriptor, |
|
1466 |
EventSetDescriptor[] events, int defaultEvent, |
|
1467 |
PropertyDescriptor[] properties, int defaultProperty, |
|
1468 |
MethodDescriptor[] methods, BeanInfo targetBeanInfo) { |
|
1469 |
this.beanDescriptor = beanDescriptor; |
|
1470 |
this.events = events; |
|
1471 |
this.defaultEvent = defaultEvent; |
|
1472 |
this.properties = properties; |
|
1473 |
this.defaultProperty = defaultProperty; |
|
1474 |
this.methods = methods; |
|
11120
f8576c769572
7116954: Misc warnings in java.beans/java.beans.context
mcimadamore
parents:
9035
diff
changeset
|
1475 |
this.targetBeanInfoRef = new SoftReference<>(targetBeanInfo); |
2 | 1476 |
} |
1477 |
||
1478 |
/** |
|
1479 |
* Package-private dup constructor |
|
1480 |
* This must isolate the new object from any changes to the old object. |
|
1481 |
*/ |
|
1482 |
GenericBeanInfo(GenericBeanInfo old) { |
|
1483 |
||
1484 |
beanDescriptor = new BeanDescriptor(old.beanDescriptor); |
|
1485 |
if (old.events != null) { |
|
1486 |
int len = old.events.length; |
|
1487 |
events = new EventSetDescriptor[len]; |
|
1488 |
for (int i = 0; i < len; i++) { |
|
1489 |
events[i] = new EventSetDescriptor(old.events[i]); |
|
1490 |
} |
|
1491 |
} |
|
1492 |
defaultEvent = old.defaultEvent; |
|
1493 |
if (old.properties != null) { |
|
1494 |
int len = old.properties.length; |
|
1495 |
properties = new PropertyDescriptor[len]; |
|
1496 |
for (int i = 0; i < len; i++) { |
|
1497 |
PropertyDescriptor oldp = old.properties[i]; |
|
1498 |
if (oldp instanceof IndexedPropertyDescriptor) { |
|
1499 |
properties[i] = new IndexedPropertyDescriptor( |
|
1500 |
(IndexedPropertyDescriptor) oldp); |
|
1501 |
} else { |
|
1502 |
properties[i] = new PropertyDescriptor(oldp); |
|
1503 |
} |
|
1504 |
} |
|
1505 |
} |
|
1506 |
defaultProperty = old.defaultProperty; |
|
1507 |
if (old.methods != null) { |
|
1508 |
int len = old.methods.length; |
|
1509 |
methods = new MethodDescriptor[len]; |
|
1510 |
for (int i = 0; i < len; i++) { |
|
1511 |
methods[i] = new MethodDescriptor(old.methods[i]); |
|
1512 |
} |
|
1513 |
} |
|
4851
4f7de5eeeac7
6921057: REGRESSION: persistence delegate issue on Windows and Linux against 5.u23b03/6u17b11
malenkov
parents:
4393
diff
changeset
|
1514 |
this.targetBeanInfoRef = old.targetBeanInfoRef; |
2 | 1515 |
} |
1516 |
||
1517 |
public PropertyDescriptor[] getPropertyDescriptors() { |
|
1518 |
return properties; |
|
1519 |
} |
|
1520 |
||
1521 |
public int getDefaultPropertyIndex() { |
|
1522 |
return defaultProperty; |
|
1523 |
} |
|
1524 |
||
1525 |
public EventSetDescriptor[] getEventSetDescriptors() { |
|
1526 |
return events; |
|
1527 |
} |
|
1528 |
||
1529 |
public int getDefaultEventIndex() { |
|
1530 |
return defaultEvent; |
|
1531 |
} |
|
1532 |
||
1533 |
public MethodDescriptor[] getMethodDescriptors() { |
|
1534 |
return methods; |
|
1535 |
} |
|
1536 |
||
1537 |
public BeanDescriptor getBeanDescriptor() { |
|
1538 |
return beanDescriptor; |
|
1539 |
} |
|
1540 |
||
1541 |
public java.awt.Image getIcon(int iconKind) { |
|
4851
4f7de5eeeac7
6921057: REGRESSION: persistence delegate issue on Windows and Linux against 5.u23b03/6u17b11
malenkov
parents:
4393
diff
changeset
|
1542 |
BeanInfo targetBeanInfo = this.targetBeanInfoRef.get(); |
2 | 1543 |
if (targetBeanInfo != null) { |
1544 |
return targetBeanInfo.getIcon(iconKind); |
|
1545 |
} |
|
1546 |
return super.getIcon(iconKind); |
|
1547 |
} |
|
1548 |
} |