Package org.apache.commons.beanutils
Class DefaultIntrospectionContext
- java.lang.Object
-
- org.apache.commons.beanutils.DefaultIntrospectionContext
-
- All Implemented Interfaces:
IntrospectionContext
class DefaultIntrospectionContext extends java.lang.Object implements IntrospectionContext
An implementation of the
IntrospectionContextinterface used byPropertyUtilsBeanwhen doing introspection of a bean class.This class implements the methods required by the
IntrospectionContextinterface in a straight-forward manner based on a map. It is used internally only. It is not thread-safe.- Since:
- 1.9
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Class<?>currentClassThe current class for introspection.private java.util.Map<java.lang.String,java.beans.PropertyDescriptor>descriptorsA map for storing the already added property descriptors.private static java.beans.PropertyDescriptor[]EMPTY_DESCRIPTORSConstant for an empty array of property descriptors.
-
Constructor Summary
Constructors Constructor Description DefaultIntrospectionContext(java.lang.Class<?> cls)Creates a new instance ofDefaultIntrospectionContextand sets the current class for introspection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPropertyDescriptor(java.beans.PropertyDescriptor desc)Adds the given property descriptor to this context.voidaddPropertyDescriptors(java.beans.PropertyDescriptor[] descs)Adds an array of property descriptors to this context.java.beans.PropertyDescriptorgetPropertyDescriptor(java.lang.String name)Returns the descriptor for the property with the given name or null if this property is unknown.java.beans.PropertyDescriptor[]getPropertyDescriptors()Returns an array with all descriptors added to this context.java.lang.Class<?>getTargetClass()Returns the class that is subject of introspection.booleanhasProperty(java.lang.String name)Tests whether a descriptor for the property with the given name is already contained in this context.java.util.Set<java.lang.String>propertyNames()Returns a set with the names of all properties known to this context.voidremovePropertyDescriptor(java.lang.String name)Removes the descriptor for the property with the given name.
-
-
-
Field Detail
-
EMPTY_DESCRIPTORS
private static final java.beans.PropertyDescriptor[] EMPTY_DESCRIPTORS
Constant for an empty array of property descriptors.
-
currentClass
private final java.lang.Class<?> currentClass
The current class for introspection.
-
descriptors
private final java.util.Map<java.lang.String,java.beans.PropertyDescriptor> descriptors
A map for storing the already added property descriptors.
-
-
Method Detail
-
addPropertyDescriptor
public void addPropertyDescriptor(java.beans.PropertyDescriptor desc)
Description copied from interface:IntrospectionContextAdds the given property descriptor to this context. This method is called by aBeanIntrospectorduring introspection for each detected property. If this context already contains a descriptor for the affected property, it is overridden.- Specified by:
addPropertyDescriptorin interfaceIntrospectionContext- Parameters:
desc- the property descriptor
-
addPropertyDescriptors
public void addPropertyDescriptors(java.beans.PropertyDescriptor[] descs)
Description copied from interface:IntrospectionContextAdds an array of property descriptors to this context. Using this method multiple descriptors can be added at once.- Specified by:
addPropertyDescriptorsin interfaceIntrospectionContext- Parameters:
descs- the array of descriptors to be added
-
getPropertyDescriptor
public java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.String name)
Description copied from interface:IntrospectionContextReturns the descriptor for the property with the given name or null if this property is unknown.- Specified by:
getPropertyDescriptorin interfaceIntrospectionContext- Parameters:
name- the name of the property in question- Returns:
- the descriptor for this property or null if this property is unknown
-
getPropertyDescriptors
public java.beans.PropertyDescriptor[] getPropertyDescriptors()
Returns an array with all descriptors added to this context. This method is used to obtain the results of introspection.- Returns:
- an array with all known property descriptors
-
getTargetClass
public java.lang.Class<?> getTargetClass()
Description copied from interface:IntrospectionContextReturns the class that is subject of introspection.- Specified by:
getTargetClassin interfaceIntrospectionContext- Returns:
- the current class
-
hasProperty
public boolean hasProperty(java.lang.String name)
Description copied from interface:IntrospectionContextTests whether a descriptor for the property with the given name is already contained in this context. This method can be used for instance to prevent that an already existing property descriptor is overridden.- Specified by:
hasPropertyin interfaceIntrospectionContext- Parameters:
name- the name of the property in question- Returns:
- true if a descriptor for this property has already been added, false otherwise
-
propertyNames
public java.util.Set<java.lang.String> propertyNames()
Description copied from interface:IntrospectionContextReturns a set with the names of all properties known to this context.- Specified by:
propertyNamesin interfaceIntrospectionContext- Returns:
- a set with the known property names
-
removePropertyDescriptor
public void removePropertyDescriptor(java.lang.String name)
Description copied from interface:IntrospectionContextRemoves the descriptor for the property with the given name.- Specified by:
removePropertyDescriptorin interfaceIntrospectionContext- Parameters:
name- the name of the affected property
-
-