Method from java.beans.Introspector Detail: |
public static String decapitalize(String name) {
if (name == null || name.length() == 0) {
return name;
}
if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) &&
Character.isUpperCase(name.charAt(0))){
return name;
}
char chars[] = name.toCharArray();
chars[0] = Character.toLowerCase(chars[0]);
return new String(chars);
}
Utility method to take a string and convert it to normal Java variable
name capitalization. This normally means converting the first
character from upper case to lower case, but in the (unusual) special
case when there is more than one character and both the first and
second characters are upper case, we leave it alone.
Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays
as "URL". |
static Method findMethod(Class cls,
String methodName,
int argCount) {
return findMethod(cls, methodName, argCount, null);
}
Find a target methodName on a given class. |
static Method findMethod(Class cls,
String methodName,
int argCount,
Class[] args) {
if (methodName == null) {
return null;
}
return internalFindMethod(cls, methodName, argCount, args);
}
Find a target methodName with specific parameter list on a given class.
Used in the contructors of the EventSetDescriptor,
PropertyDescriptor and the IndexedPropertyDescriptor.
|
public static void flushCaches() {
synchronized (BEANINFO_CACHE) {
Map beanInfoCache = (Map) AppContext.getAppContext().get(BEANINFO_CACHE);
if (beanInfoCache != null) {
beanInfoCache.clear();
}
declaredMethodCache.clear();
}
}
Flush all of the Introspector's internal caches. This method is
not normally required. It is normally only needed by advanced
tools that update existing "Class" objects in-place and need
to make the Introspector re-analyze existing Class objects. |
public static void flushFromCaches(Class<?> clz) {
if (clz == null) {
throw new NullPointerException();
}
synchronized (BEANINFO_CACHE) {
Map beanInfoCache = (Map) AppContext.getAppContext().get(BEANINFO_CACHE);
if (beanInfoCache != null) {
beanInfoCache.put(clz, null);
}
declaredMethodCache.put(clz, null);
}
}
Flush the Introspector's internal cached information for a given class.
This method is not normally required. It is normally only needed
by advanced tools that update existing "Class" objects in-place
and need to make the Introspector re-analyze an existing Class object.
Note that only the direct state associated with the target Class
object is flushed. We do not flush state for other Class objects
with the same name, nor do we flush state for any related Class
objects (such as subclasses), even though their state may include
information indirectly obtained from the target Class object. |
public static BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
if (!ReflectUtil.isPackageAccessible(beanClass)) {
return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
}
Map< Class< ? >, BeanInfo > beanInfoCache;
BeanInfo beanInfo;
synchronized (BEANINFO_CACHE) {
beanInfoCache = (Map< Class< ? >, BeanInfo >) AppContext.getAppContext().get(BEANINFO_CACHE);
if (beanInfoCache == null) {
beanInfoCache = new WeakHashMap< Class< ? >, BeanInfo >();
AppContext.getAppContext().put(BEANINFO_CACHE, beanInfoCache);
}
beanInfo = beanInfoCache.get(beanClass);
}
if (beanInfo == null) {
beanInfo = new Introspector(beanClass, null, USE_ALL_BEANINFO).getBeanInfo();
synchronized (BEANINFO_CACHE) {
beanInfoCache.put(beanClass, beanInfo);
}
}
return beanInfo;
}
Introspect on a Java Bean and learn about all its properties, exposed
methods, and events.
If the BeanInfo class for a Java Bean has been previously Introspected
then the BeanInfo class is retrieved from the BeanInfo cache. |
public static BeanInfo getBeanInfo(Class<?> beanClass,
int flags) throws IntrospectionException {
return getBeanInfo(beanClass, null, flags);
}
Introspect on a Java bean and learn about all its properties, exposed
methods, and events, subject to some control flags.
If the BeanInfo class for a Java Bean has been previously Introspected
based on the same arguments then the BeanInfo class is retrieved
from the BeanInfo cache. |
public static BeanInfo getBeanInfo(Class<?> beanClass,
Class<?> stopClass) throws IntrospectionException {
return getBeanInfo(beanClass, stopClass, USE_ALL_BEANINFO);
}
Introspect on a Java bean and learn all about its properties, exposed
methods, below a given "stop" point.
If the BeanInfo class for a Java Bean has been previously Introspected
based on the same arguments, then the BeanInfo class is retrieved
from the BeanInfo cache. |
public static BeanInfo getBeanInfo(Class<?> beanClass,
Class<?> stopClass,
int flags) throws IntrospectionException {
BeanInfo bi;
if (stopClass == null && flags == USE_ALL_BEANINFO) {
// Same parameters to take advantage of caching.
bi = getBeanInfo(beanClass);
} else {
bi = (new Introspector(beanClass, stopClass, flags)).getBeanInfo();
}
return bi;
// Old behaviour: Make an independent copy of the BeanInfo.
//return new GenericBeanInfo(bi);
}
Introspect on a Java Bean and learn about all its properties,
exposed methods and events, below a given {@code stopClass} point
subject to some control {@code flags}.
- USE_ALL_BEANINFO
- Any BeanInfo that can be discovered will be used.
- IGNORE_IMMEDIATE_BEANINFO
- Any BeanInfo associated with the specified {@code beanClass} will be ignored.
- IGNORE_ALL_BEANINFO
- Any BeanInfo associated with the specified {@code beanClass}
or any of its parent classes will be ignored.
Any methods/properties/events in the {@code stopClass}
or in its parent classes will be ignored in the analysis.
If the BeanInfo class for a Java Bean has been
previously introspected based on the same arguments then
the BeanInfo class is retrieved from the BeanInfo cache. |
public static String[] getBeanInfoSearchPath() {
return getFinder().getPackages();
}
Gets the list of package names that will be used for
finding BeanInfo classes. |
static Object instantiate(Class sibling,
String className) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
// First check with sibling's classloader (if any).
ClassLoader cl = sibling.getClassLoader();
Class cls = ClassFinder.findClass(className, cl);
return cls.newInstance();
}
Try to create an instance of a named class.
First try the classloader of "sibling", then try the system
classloader then the class loader of the current Thread. |
static boolean isSubclass(Class a,
Class b) {
// We rely on the fact that for any given java class or
// primtitive type there is a unqiue Class object, so
// we can use object equivalence in the comparisons.
if (a == b) {
return true;
}
if (a == null || b == null) {
return false;
}
for (Class x = a; x != null; x = x.getSuperclass()) {
if (x == b) {
return true;
}
if (b.isInterface()) {
Class interfaces[] = x.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
if (isSubclass(interfaces[i], b)) {
return true;
}
}
}
}
return false;
}
Return true if class a is either equivalent to class b, or
if class a is a subclass of class b, i.e. if a either "extends"
or "implements" b.
Note tht either or both "Class" objects may represent interfaces. |
public static void setBeanInfoSearchPath(String[] path) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPropertiesAccess();
}
getFinder().setPackages(path);
}
Change the list of package names that will be used for
finding BeanInfo classes. The behaviour of
this method is undefined if parameter path
is null.
First, if there is a security manager, its checkPropertiesAccess
method is called. This could result in a SecurityException. |