equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright 1996-2006 Sun Microsystems, Inc. All Rights Reserved. |
2 * Copyright 1996-2009 Sun Microsystems, Inc. All Rights Reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Sun designates this |
7 * published by the Free Software Foundation. Sun designates this |
43 import java.util.Iterator; |
43 import java.util.Iterator; |
44 import java.util.EventListener; |
44 import java.util.EventListener; |
45 import java.util.List; |
45 import java.util.List; |
46 import java.util.WeakHashMap; |
46 import java.util.WeakHashMap; |
47 import java.util.TreeMap; |
47 import java.util.TreeMap; |
|
48 import sun.awt.AppContext; |
48 import sun.reflect.misc.ReflectUtil; |
49 import sun.reflect.misc.ReflectUtil; |
49 |
50 |
50 /** |
51 /** |
51 * The Introspector class provides a standard way for tools to learn about |
52 * The Introspector class provides a standard way for tools to learn about |
52 * the properties, events, and methods supported by a target Java Bean. |
53 * the properties, events, and methods supported by a target Java Bean. |
109 public final static int IGNORE_ALL_BEANINFO = 3; |
110 public final static int IGNORE_ALL_BEANINFO = 3; |
110 |
111 |
111 // Static Caches to speed up introspection. |
112 // Static Caches to speed up introspection. |
112 private static Map declaredMethodCache = |
113 private static Map declaredMethodCache = |
113 Collections.synchronizedMap(new WeakHashMap()); |
114 Collections.synchronizedMap(new WeakHashMap()); |
114 private static Map beanInfoCache = |
115 |
115 Collections.synchronizedMap(new WeakHashMap()); |
116 private static final Object BEANINFO_CACHE = new Object(); |
116 |
117 |
117 private Class beanClass; |
118 private Class beanClass; |
118 private BeanInfo explicitBeanInfo; |
119 private BeanInfo explicitBeanInfo; |
119 private BeanInfo superBeanInfo; |
120 private BeanInfo superBeanInfo; |
120 private BeanInfo additionalBeanInfo[]; |
121 private BeanInfo additionalBeanInfo[]; |
173 throws IntrospectionException |
174 throws IntrospectionException |
174 { |
175 { |
175 if (!ReflectUtil.isPackageAccessible(beanClass)) { |
176 if (!ReflectUtil.isPackageAccessible(beanClass)) { |
176 return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo(); |
177 return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo(); |
177 } |
178 } |
178 BeanInfo bi = (BeanInfo)beanInfoCache.get(beanClass); |
179 Map<Class<?>, BeanInfo> map; |
|
180 synchronized (BEANINFO_CACHE) { |
|
181 map = (Map<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE); |
|
182 if (map == null) { |
|
183 map = Collections.synchronizedMap(new WeakHashMap<Class<?>, BeanInfo>()); |
|
184 AppContext.getAppContext().put(BEANINFO_CACHE, map); |
|
185 } |
|
186 } |
|
187 BeanInfo bi = map.get(beanClass); |
179 if (bi == null) { |
188 if (bi == null) { |
180 bi = (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo(); |
189 bi = (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo(); |
181 beanInfoCache.put(beanClass, bi); |
190 map.put(beanClass, bi); |
182 } |
191 } |
183 return bi; |
192 return bi; |
184 } |
193 } |
185 |
194 |
186 /** |
195 /** |
349 * tools that update existing "Class" objects in-place and need |
358 * tools that update existing "Class" objects in-place and need |
350 * to make the Introspector re-analyze existing Class objects. |
359 * to make the Introspector re-analyze existing Class objects. |
351 */ |
360 */ |
352 |
361 |
353 public static void flushCaches() { |
362 public static void flushCaches() { |
354 beanInfoCache.clear(); |
363 Map map = (Map) AppContext.getAppContext().get(BEANINFO_CACHE); |
|
364 if (map != null) { |
|
365 map.clear(); |
|
366 } |
355 declaredMethodCache.clear(); |
367 declaredMethodCache.clear(); |
356 } |
368 } |
357 |
369 |
358 /** |
370 /** |
359 * Flush the Introspector's internal cached information for a given class. |
371 * Flush the Introspector's internal cached information for a given class. |
372 */ |
384 */ |
373 public static void flushFromCaches(Class<?> clz) { |
385 public static void flushFromCaches(Class<?> clz) { |
374 if (clz == null) { |
386 if (clz == null) { |
375 throw new NullPointerException(); |
387 throw new NullPointerException(); |
376 } |
388 } |
377 beanInfoCache.remove(clz); |
389 Map map = (Map) AppContext.getAppContext().get(BEANINFO_CACHE); |
|
390 if (map != null) { |
|
391 map.remove(clz); |
|
392 } |
378 declaredMethodCache.remove(clz); |
393 declaredMethodCache.remove(clz); |
379 } |
394 } |
380 |
395 |
381 //====================================================================== |
396 //====================================================================== |
382 // Private implementation methods |
397 // Private implementation methods |