APIdia Launch Partner
Top Description Fields Constructors Methods
java.beans

public Class Introspector

Additional top-level class in compilation unit: GenericBeanInfo.

extends Object
Class Inheritance
Imports
java.awt.Component, java.lang.ref.Reference, .SoftReference, java.lang.reflect.Constructor, .InvocationTargetException, .Method, .Type, java.util.ArrayList, .EventObject, .HashMap, .Iterator, .List, .Map, .TreeMap, com.sun.beans.TypeResolver, com.sun.beans.finder.ClassFinder, com.sun.beans.introspect.ClassInfo, .EventSetInfo, .PropertyInfo, jdk.internal.access.JavaBeansAccess, .SharedSecrets

The Introspector class provides a standard way for tools to learn about the properties, events, and methods supported by a target Java Bean.

For each of those three kinds of information, the Introspector will separately analyze the bean's class and superclasses looking for either explicit or implicit information and use that information to build a BeanInfo object that comprehensively describes the target bean.

For each class "Foo", explicit information may be available if there exists a corresponding "FooBeanInfo" class that provides a non-null value when queried for the information. We first look for the BeanInfo class by taking the full package-qualified name of the target bean class and appending "BeanInfo" to form a new class name. If this fails, then we take the final classname component of this name, and look for that class in each of the packages specified in the BeanInfo package search path.

Thus for a class such as "sun.xyz.OurButton" we would first look for a BeanInfo class called "sun.xyz.OurButtonBeanInfo" and if that failed we'd look in each package in the BeanInfo search path for an OurButtonBeanInfo class. With the default search path, this would mean looking for "sun.beans.infos.OurButtonBeanInfo".

If a class provides explicit BeanInfo about itself then we add that to the BeanInfo information we obtained from analyzing any derived classes, but we regard the explicit information as being definitive for the current class and its base classes, and do not proceed any further up the superclass chain.

If we don't find explicit BeanInfo on a class, we use low-level reflection to study the methods of the class and apply standard design patterns to identify property accessors, event sources, or public methods. We then proceed to analyze the class's superclass and add in the information from it (and possibly on up the superclass chain).

For more information about introspection and design patterns, please consult the JavaBeans specification.

Since
1.1

Field Summary

Modifier and TypeField and Description
pack-priv static final String
private BeanInfo[]
private Class<?>
private int
private String
private int
private String
private static final EventSetDescriptor[]
private Map<String, EventSetDescriptor>
private BeanInfo
pack-priv static final String
public static final int
IGNORE_ALL_BEANINFO

Flag to indicate to ignore all beaninfo.

public static final int
IGNORE_IMMEDIATE_BEANINFO

Flag to indicate to ignore immediate beaninfo.

pack-priv static final String
private Map<String, MethodDescriptor>
private HashMap<String, List<PropertyDescriptor>>
private Map<String, PropertyDescriptor>
private boolean
pack-priv static final String
pack-priv static final String
private BeanInfo
public static final int
USE_ALL_BEANINFO

Flag to indicate to use of all beaninfo.

Constructor Summary

AccessConstructor and Description
private
Introspector(Class<?> beanClass, Class<?> stopClass, int flags)

Method Summary

Modifier and TypeMethod and Description
private void
private void
private void
addPropertyDescriptor(PropertyDescriptor pd)

Adds the property descriptor to the list store.

private void
public static String

Returns:

The decapitalized version of the string.
decapitalize
(String
The string to be decapitalized.
name
)

Utility method to take a string and convert it to normal Java variable name capitalization.

private static Class<?>
private static BeanInfo

Returns:

Instance of an explicit BeanInfo class or null if one isn't found.
findExplicitBeanInfo
(Class<?>
the class type of the bean
beanClass
)

Looks for an explicit BeanInfo class that corresponds to the Class.

pack-priv static Method
findMethod(Class<?> cls, String methodName, int argCount)

Find a target methodName on a given class.

pack-priv static Method

Returns:

the method or null if not found
findMethod
(Class<?>
The Class object on which to retrieve the method.
cls
,
String
Name of the method.
methodName
,
int
Number of arguments for the desired method.
argCount
,
Class<?>[]
Array of argument types for the method.
args
)

Find a target methodName with specific parameter list on a given class.

public static void
flushCaches()

Flush all of the Introspector's internal caches.

public static void
flushFromCaches(Class<?>
Class object to be flushed.
clz
)

Flush the Introspector's internal cached information for a given class.

public static BeanInfo

Returns:

A BeanInfo object describing the target bean.
getBeanInfo
(Class<?>
The bean class to be analyzed.
beanClass
)

Introspect on a Java Bean and learn about all its properties, exposed methods, and events.

public static BeanInfo

Returns:

A BeanInfo object describing the target bean.
getBeanInfo
(Class<?>
The bean class to be analyzed.
beanClass
,
int
Flags to control the introspection. If flags == USE_ALL_BEANINFO then we use all of the BeanInfo classes we can discover. If flags == IGNORE_IMMEDIATE_BEANINFO then we ignore any BeanInfo associated with the specified beanClass. If flags == IGNORE_ALL_BEANINFO then we ignore all BeanInfo associated with the specified beanClass or any of its parent classes.
flags
)

Introspect on a Java bean and learn about all its properties, exposed methods, and events, subject to some control flags.

public static BeanInfo

Returns:

the BeanInfo for the bean
getBeanInfo
(Class<?>
The bean class to be analyzed.
beanClass
,
Class<?>
The baseclass at which to stop the analysis. Any methods/properties/events in the stopClass or in its baseclasses will be ignored in the analysis.
stopClass
)

Introspect on a Java bean and learn all about its properties, exposed methods, below a given "stop" point.

public static BeanInfo

Returns:

a BeanInfo object describing the target bean
getBeanInfo
(Class<?>
the bean class to be analyzed
beanClass
,
Class<?>
the parent class at which to stop the analysis
stopClass
,
int
flags to control the introspection
flags
)

Introspect on a Java Bean and learn about all its properties, exposed methods and events, below a given stopClass point subject to some control flags.

private BeanInfo
getBeanInfo()

Constructs a GenericBeanInfo class from the state of the Introspector

public static String[]

Returns:

The array of package names that will be searched in order to find BeanInfo classes. The default value for this array is implementation-dependent; e.g. Sun implementation initially sets to {"sun.beans.infos"}.
getBeanInfoSearchPath
()

Gets the list of package names that will be used for finding BeanInfo classes.

private PropertyDescriptor[]
private BeanDescriptor
private int
private int
private EventSetDescriptor[]
getTargetEventInfo()

Returns: An array of EventSetDescriptors describing the kinds of events fired by the target bean.

private MethodDescriptor[]
getTargetMethodInfo()

Returns: An array of MethodDescriptors describing the private methods supported by the target bean.

private PropertyDescriptor[]
getTargetPropertyInfo()

Returns: An array of PropertyDescriptors describing the editable properties supported by the target bean.

pack-priv static Object
instantiate(Class<?> sibling, String className)

Try to create an instance of a named class.

private static Method
internalFindMethod(Class<?> start, String methodName, int argCount, Class<?>[] args)

Internal support for finding a target methodName with a given parameter list on a given class.

private static boolean
isAssignable(Class<?> current, Class<?> candidate)

private boolean
pack-priv static boolean
isSubclass(Class<?> a, Class<?> b)

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.

private static String
makeQualifiedMethodName(String name, String[] params)

Creates a key for a method in a method cache.

private PropertyDescriptor
mergePropertyDescriptor(IndexedPropertyDescriptor ipd, PropertyDescriptor pd)

Adds the property descriptor to the indexedproperty descriptor only if the types are the same.

private PropertyDescriptor
private IndexedPropertyDescriptor
private PropertyDescriptor
private void
processPropertyDescriptors()

Populates the property descriptor table by merging the lists of Property descriptors.

public static void
setBeanInfoSearchPath(String[]
Array of package names.
path
)

Change the list of package names that will be used for finding BeanInfo classes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ADD_PREFIXback to summary
pack-priv static final String ADD_PREFIX
additionalBeanInfoback to summary
private BeanInfo[] additionalBeanInfo
beanClassback to summary
private Class<?> beanClass
defaultEventIndexback to summary
private int defaultEventIndex
defaultEventNameback to summary
private String defaultEventName
defaultPropertyIndexback to summary
private int defaultPropertyIndex
defaultPropertyNameback to summary
private String defaultPropertyName
EMPTY_EVENTSETDESCRIPTORSback to summary
private static final EventSetDescriptor[] EMPTY_EVENTSETDESCRIPTORS
eventsback to summary
private Map<String, EventSetDescriptor> events
explicitBeanInfoback to summary
private BeanInfo explicitBeanInfo
GET_PREFIXback to summary
pack-priv static final String GET_PREFIX
IGNORE_ALL_BEANINFOback to summary
public static final int IGNORE_ALL_BEANINFO

Flag to indicate to ignore all beaninfo.

Since
1.2
IGNORE_IMMEDIATE_BEANINFOback to summary
public static final int IGNORE_IMMEDIATE_BEANINFO

Flag to indicate to ignore immediate beaninfo.

Since
1.2
IS_PREFIXback to summary
pack-priv static final String IS_PREFIX
methodsback to summary
private Map<String, MethodDescriptor> methods
pdStoreback to summary
private HashMap<String, List<PropertyDescriptor>> pdStore
propertiesback to summary
private Map<String, PropertyDescriptor> properties
propertyChangeSourceback to summary
private boolean propertyChangeSource
REMOVE_PREFIXback to summary
pack-priv static final String REMOVE_PREFIX
SET_PREFIXback to summary
pack-priv static final String SET_PREFIX
superBeanInfoback to summary
private BeanInfo superBeanInfo
USE_ALL_BEANINFOback to summary
public static final int USE_ALL_BEANINFO

Flag to indicate to use of all beaninfo.

Since
1.2

Constructor Detail

Introspectorback to summary
private Introspector(Class<?> beanClass, Class<?> stopClass, int flags) throws IntrospectionException

Method Detail

addEventback to summary
private void addEvent(EventSetDescriptor esd)
addMethodback to summary
private void addMethod(MethodDescriptor md)
addPropertyDescriptorback to summary
private void addPropertyDescriptor(PropertyDescriptor pd)

Adds the property descriptor to the list store.

addPropertyDescriptorsback to summary
private void addPropertyDescriptors(PropertyDescriptor[] descriptors)
decapitalizeback to summary
public static String decapitalize(String name)

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".

Parameters
name:String

The string to be decapitalized.

Returns:String

The decapitalized version of the string.

findCustomizerClassback to summary
private static Class<?> findCustomizerClass(Class<?> type)
findExplicitBeanInfoback to summary
private static BeanInfo findExplicitBeanInfo(Class<?> beanClass)

Looks for an explicit BeanInfo class that corresponds to the Class. First it looks in the existing package that the Class is defined in, then it checks to see if the class is its own BeanInfo. Finally, the BeanInfo search path is prepended to the class and searched.

Parameters
beanClass:Class<?>

the class type of the bean

Returns:BeanInfo

Instance of an explicit BeanInfo class or null if one isn't found.

findMethodback to summary
pack-priv static Method findMethod(Class<?> cls, String methodName, int argCount)

Find a target methodName on a given class.

findMethodback to summary
pack-priv static Method findMethod(Class<?> cls, String methodName, int argCount, Class<?>[] args)

Find a target methodName with specific parameter list on a given class.

Used in the constructors of the EventSetDescriptor, PropertyDescriptor and the IndexedPropertyDescriptor.

Parameters
cls:Class<?>

The Class object on which to retrieve the method.

methodName:String

Name of the method.

argCount:int

Number of arguments for the desired method.

args:Class<?>[]

Array of argument types for the method.

Returns:Method

the method or null if not found

flushCachesback to summary
public static void flushCaches()

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.

Since
1.2
flushFromCachesback to summary
public static void flushFromCaches(Class<?> clz)

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.

Parameters
clz:Class<?>

Class object to be flushed.

Exceptions
NullPointerException:
If the Class object is null.
Since
1.2
getBeanInfoback to summary
public static BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException

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.

Parameters
beanClass:Class<?>

The bean class to be analyzed.

Returns:BeanInfo

A BeanInfo object describing the target bean.

Exceptions
IntrospectionException:
if an exception occurs during introspection.
See Also
flushCaches, flushFromCaches
getBeanInfoback to summary
public static BeanInfo getBeanInfo(Class<?> beanClass, int flags) throws IntrospectionException

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.

Parameters
beanClass:Class<?>

The bean class to be analyzed.

flags:int

Flags to control the introspection. If flags == USE_ALL_BEANINFO then we use all of the BeanInfo classes we can discover. If flags == IGNORE_IMMEDIATE_BEANINFO then we ignore any BeanInfo associated with the specified beanClass. If flags == IGNORE_ALL_BEANINFO then we ignore all BeanInfo associated with the specified beanClass or any of its parent classes.

Returns:BeanInfo

A BeanInfo object describing the target bean.

Exceptions
IntrospectionException:
if an exception occurs during introspection.
Since
1.2
getBeanInfoback to summary
public static BeanInfo getBeanInfo(Class<?> beanClass, Class<?> stopClass) throws IntrospectionException

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.

Parameters
beanClass:Class<?>

The bean class to be analyzed.

stopClass:Class<?>

The baseclass at which to stop the analysis. Any methods/properties/events in the stopClass or in its baseclasses will be ignored in the analysis.

Returns:BeanInfo

the BeanInfo for the bean

Exceptions
IntrospectionException:
if an exception occurs during introspection.
getBeanInfoback to summary
public static BeanInfo getBeanInfo(Class<?> beanClass, Class<?> stopClass, int flags) throws IntrospectionException

Introspect on a Java Bean and learn about all its properties, exposed methods and events, below a given stopClass point subject to some control flags.

USE_ALL_BEANINFO
Any BeanInfo that can be discovered will be used.
IGNORE_IMMEDIATE_BEANINFO
Any BeanInfo associated with the specified beanClass will be ignored.
IGNORE_ALL_BEANINFO
Any BeanInfo associated with the specified beanClass or any of its parent classes will be ignored.
Any methods/properties/events in the 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.

Parameters
beanClass:Class<?>

the bean class to be analyzed

stopClass:Class<?>

the parent class at which to stop the analysis

flags:int

flags to control the introspection

Returns:BeanInfo

a BeanInfo object describing the target bean

Exceptions
IntrospectionException:
if an exception occurs during introspection
Since
1.7
getBeanInfoback to summary
private BeanInfo getBeanInfo() throws IntrospectionException

Constructs a GenericBeanInfo class from the state of the Introspector

getBeanInfoSearchPathback to summary
public static String[] getBeanInfoSearchPath()

Gets the list of package names that will be used for finding BeanInfo classes.

Returns:String[]

The array of package names that will be searched in order to find BeanInfo classes. The default value for this array is implementation-dependent; e.g. Sun implementation initially sets to {"sun.beans.infos"}.

getPropertyDescriptorsback to summary
private PropertyDescriptor[] getPropertyDescriptors(BeanInfo info)
getTargetBeanDescriptorback to summary
private BeanDescriptor getTargetBeanDescriptor()
getTargetDefaultEventIndexback to summary
private int getTargetDefaultEventIndex()
getTargetDefaultPropertyIndexback to summary
private int getTargetDefaultPropertyIndex()
getTargetEventInfoback to summary
private EventSetDescriptor[] getTargetEventInfo() throws IntrospectionException
Returns:EventSetDescriptor[]

An array of EventSetDescriptors describing the kinds of events fired by the target bean.

getTargetMethodInfoback to summary
private MethodDescriptor[] getTargetMethodInfo()
Returns:MethodDescriptor[]

An array of MethodDescriptors describing the private methods supported by the target bean.

getTargetPropertyInfoback to summary
private PropertyDescriptor[] getTargetPropertyInfo()
Returns:PropertyDescriptor[]

An array of PropertyDescriptors describing the editable properties supported by the target bean.

instantiateback to summary
pack-priv static Object instantiate(Class<?> sibling, String className) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, ClassNotFoundException

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.

Annotations
@SuppressWarnings:deprecation
internalFindMethodback to summary
private static Method internalFindMethod(Class<?> start, String methodName, int argCount, Class<?>[] args)

Internal support for finding a target methodName with a given parameter list on a given class.

isAssignableback to summary
private static boolean isAssignable(Class<?> current, Class<?> candidate)
isEventHandlerback to summary
private boolean isEventHandler(Method m)
isSubclassback to summary
pack-priv static boolean isSubclass(Class<?> a, Class<?> b)

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 that either or both "Class" objects may represent interfaces.

makeQualifiedMethodNameback to summary
private static String makeQualifiedMethodName(String name, String[] params)

Creates a key for a method in a method cache.

mergePropertyDescriptorback to summary
private PropertyDescriptor mergePropertyDescriptor(IndexedPropertyDescriptor ipd, PropertyDescriptor pd)

Adds the property descriptor to the indexedproperty descriptor only if the types are the same. The most specific property descriptor will take precedence.

mergePropertyDescriptorback to summary
private PropertyDescriptor mergePropertyDescriptor(PropertyDescriptor pd1, PropertyDescriptor pd2)
mergePropertyDescriptorback to summary
private IndexedPropertyDescriptor mergePropertyDescriptor(IndexedPropertyDescriptor ipd1, IndexedPropertyDescriptor ipd2)
mergePropertyWithIndexedPropertyback to summary
private PropertyDescriptor mergePropertyWithIndexedProperty(PropertyDescriptor pd, IndexedPropertyDescriptor ipd)
processPropertyDescriptorsback to summary
private void processPropertyDescriptors()

Populates the property descriptor table by merging the lists of Property descriptors.

setBeanInfoSearchPathback to summary
public static void setBeanInfoSearchPath(String[] 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.

Parameters
path:String[]

Array of package names.