Class Introspector
Introspector
is a utility for developers to figure out
which properties, events, and methods a JavaBean supports.
The Introspector
class walks over the class/superclass chain
of the target bean class. At each level it checks if there is a matching
BeanInfo
class which provides explicit information about the
bean, and if so uses that explicit information. Otherwise it uses the low
level reflection APIs to study the target class and uses design patterns to
analyze its behaviour and then proceeds to continue the introspection with
its baseclass.
To look for the explicit information of a bean:
- The
Introspector
appends "BeanInfo" to the qualified name of the bean class, try to use the new class as the "BeanInfo" class. If the "BeanInfo" class exsits and returns non-null value when queried for explicit information, use the explicit information - If the first step fails, the
Introspector
will extract a simple class name of the bean class by removing the package name from the qualified name of the bean class, append "BeanInfo" to it. And look for the simple class name in the packages defined in the "BeanInfo" search path (The default "BeanInfo" search path issun.beans.infos
). If it finds a "BeanInfo" class and the "BeanInfo" class returns non-null value when queried for explicit information, use the explicit information
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Constant values to indicate that theIntrospector
will ignore allBeanInfo
class.static final int
Constant values to indicate that theIntrospector
will ignore theBeanInfo
class of the current bean class.static final int
Constant values to indicate that theIntrospector
will use allBeanInfo
class which have been found. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
decapitalize
(String name) Decapitalizes a given string according to the rule: If the first or only character is Upper Case, it is made Lower Case UNLESS the second character is also Upper Case, when the String is returned unchangedstatic void
Flushes allBeanInfo
caches.static void
flushFromCaches
(Class<?> clazz) Flushes theBeanInfo
caches of the specified bean classstatic BeanInfo
getBeanInfo
(Class<?> beanClass) Gets theBeanInfo
object which contains the information of the properties, events and methods of the specified bean class.static BeanInfo
getBeanInfo
(Class<?> beanClass, int flags) Gets theBeanInfo
object which contains the information of the properties, events and methods of the specified bean class.static BeanInfo
getBeanInfo
(Class<?> beanClass, Class<?> stopClass) Gets theBeanInfo
object which contains the information of the properties, events and methods of the specified bean class.static String[]
Gets an array of search packages.static void
setBeanInfoSearchPath
(String[] path) Sets the search packages.
-
Field Details
-
IGNORE_ALL_BEANINFO
public static final int IGNORE_ALL_BEANINFOConstant values to indicate that theIntrospector
will ignore allBeanInfo
class.- See Also:
-
IGNORE_IMMEDIATE_BEANINFO
public static final int IGNORE_IMMEDIATE_BEANINFOConstant values to indicate that theIntrospector
will ignore theBeanInfo
class of the current bean class.- See Also:
-
USE_ALL_BEANINFO
public static final int USE_ALL_BEANINFOConstant values to indicate that theIntrospector
will use allBeanInfo
class which have been found. This is the default one.- See Also:
-
-
Method Details
-
decapitalize
Decapitalizes a given string according to the rule:- If the first or only character is Upper Case, it is made Lower Case
- UNLESS the second character is also Upper Case, when the String is
returned unchanged
- Parameters:
name
- - the String to decapitalize- Returns:
- the decapitalized version of the String
-
flushCaches
public static void flushCaches()Flushes allBeanInfo
caches. -
flushFromCaches
Flushes theBeanInfo
caches of the specified bean class- Parameters:
clazz
- the specified bean class
-
getBeanInfo
Gets theBeanInfo
object which contains the information of the properties, events and methods of the specified bean class.The
Introspector
will cache theBeanInfo
object. Subsequent calls to this method will be answered with the cached data.- Parameters:
beanClass
- the specified bean class.- Returns:
- the
BeanInfo
of the bean class. - Throws:
IntrospectionException
-
getBeanInfo
public static BeanInfo getBeanInfo(Class<?> beanClass, Class<?> stopClass) throws IntrospectionException Gets theBeanInfo
object which contains the information of the properties, events and methods of the specified bean class. It will not introspect the "stopclass" and its super class.The
Introspector
will cache theBeanInfo
object. Subsequent calls to this method will be answered with the cached data.- Parameters:
beanClass
- the specified beanClass.stopClass
- the sopt class which should be super class of the bean class. May be null.- Returns:
- the
BeanInfo
of the bean class. - Throws:
IntrospectionException
-
getBeanInfo
Gets theBeanInfo
object which contains the information of the properties, events and methods of the specified bean class.- If
flag==IGNORE_ALL_BEANINFO
, theIntrospector
will ignore allBeanInfo
class. - If
flag==IGNORE_IMMEDIATE_BEANINFO
, theIntrospector
will ignore theBeanInfo
class of the current bean class. - If
flag==USE_ALL_BEANINFO
, theIntrospector
will use allBeanInfo
class which have been found.
The
Introspector
will cache theBeanInfo
object. Subsequent calls to this method will be answered with the cached data.- Parameters:
beanClass
- the specified bean class.flags
- the flag to control the usage of the explicitBeanInfo
class.- Returns:
- the
BeanInfo
of the bean class. - Throws:
IntrospectionException
- If
-
getBeanInfoSearchPath
Gets an array of search packages.- Returns:
- an array of search packages.
-
setBeanInfoSearchPath
Sets the search packages.- Parameters:
path
- the new search packages to be set.
-