Class WrapDynaClass
- java.lang.Object
-
- org.apache.commons.beanutils.WrapDynaClass
-
- All Implemented Interfaces:
DynaClass
public class WrapDynaClass extends java.lang.Object implements DynaClass
Implements
DynaClassfor DynaBeans that wrap standard JavaBean instances.It is suggested that this class should not usually need to be used directly to create new
WrapDynaBeaninstances. It's usually better to call theWrapDynaBeanconstructor directly. For example:Object javaBean = ...; DynaBean wrapper = new WrapDynaBean(javaBean);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classWrapDynaClass.CacheKeyA class representing the combined key for the cache ofWrapDynaClassinstances.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Class<?>beanClassDeprecated.No longer initialized, use getBeanClass() method insteadprivate java.lang.StringbeanClassNameName of the JavaBean class represented by this WrapDynaClass.private java.lang.ref.Reference<java.lang.Class<?>>beanClassRefReference to the JavaBean class represented by this WrapDynaClass.private static ContextClassLoaderLocal<java.util.Map<WrapDynaClass.CacheKey,WrapDynaClass>>CLASSLOADER_CACHEprotected java.beans.PropertyDescriptor[]descriptorsThe set of PropertyDescriptors for this bean class.protected java.util.HashMap<java.lang.String,java.beans.PropertyDescriptor>descriptorsMapThe set of PropertyDescriptors for this bean class, keyed by the property name.protected static java.util.HashMap<java.lang.Object,java.lang.Object>dynaClassesDeprecated.The dynaClasses Map will be removed in a subsequent releaseprotected DynaProperty[]propertiesThe set of dynamic properties that are part of this DynaClass.protected java.util.HashMap<java.lang.String,DynaProperty>propertiesMapThe set of dynamic properties that are part of this DynaClass, keyed by the property name.private PropertyUtilsBeanpropertyUtilsBeanStores the associatedPropertyUtilsBeaninstance.
-
Constructor Summary
Constructors Modifier Constructor Description privateWrapDynaClass(java.lang.Class<?> beanClass, PropertyUtilsBean propUtils)Construct a new WrapDynaClass for the specified JavaBean class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidclear()Clear our cache of WrapDynaClass instances.static WrapDynaClasscreateDynaClass(java.lang.Class<?> beanClass)Create (if necessary) and return a newWrapDynaClassinstance for the specified bean class.static WrapDynaClasscreateDynaClass(java.lang.Class<?> beanClass, PropertyUtilsBean pu)Create (if necessary) and return a newWrapDynaClassinstance for the specified bean class using the givenPropertyUtilsBeaninstance for introspection.protected java.lang.Class<?>getBeanClass()Return the class of the underlying wrapped bean.private static java.util.Map<WrapDynaClass.CacheKey,WrapDynaClass>getClassesCache()Returns the cache for the already created class instances.private static java.util.Map<java.lang.Object,java.lang.Object>getDynaClassesMap()Get the wrap dyna classes cache.DynaProperty[]getDynaProperties()Return an array ofProperyDescriptorsfor the properties currently defined in this DynaClass.DynaPropertygetDynaProperty(java.lang.String name)Return a property descriptor for the specified property, if it exists; otherwise, returnnull.java.lang.StringgetName()Return the name of this DynaClass (analogous to thegetName()method ofjava.lang.Class), which allows the sameDynaClassimplementation class to support different dynamic classes, with different sets of properties.java.beans.PropertyDescriptorgetPropertyDescriptor(java.lang.String name)Return the PropertyDescriptor for the specified property name, if any; otherwise returnnull.protected PropertyUtilsBeangetPropertyUtilsBean()Returns thePropertyUtilsBeaninstance associated with this class.protected voidintrospect()Introspect our bean class to identify the supported properties.DynaBeannewInstance()Instantiates a new standard JavaBean instance associated with this DynaClass and return it wrapped in a new WrapDynaBean instance.
-
-
-
Field Detail
-
CLASSLOADER_CACHE
private static final ContextClassLoaderLocal<java.util.Map<WrapDynaClass.CacheKey,WrapDynaClass>> CLASSLOADER_CACHE
-
dynaClasses
@Deprecated protected static java.util.HashMap<java.lang.Object,java.lang.Object> dynaClasses
Deprecated.The dynaClasses Map will be removed in a subsequent releaseThe set ofWrapDynaClassinstances that have ever been created, keyed by the underlying bean Class. The keys to this map are Class objects, and the values are corresponding WrapDynaClass objects.This static variable is safe even when this code is deployed via a shared classloader because it is keyed via a Class object. The same class loaded via two different classloaders will result in different entries in this map.
Note, however, that this HashMap can result in a memory leak. When this class is in a shared classloader it will retain references to classes loaded via a webapp classloader even after the webapp has been undeployed. That will prevent the entire classloader and all the classes it refers to and all their static members from being freed. !!!!!!!!!!!! PLEASE NOTE !!!!!!!!!!!! ************* THE FOLLOWING IS A NASTY HACK TO SO THAT BEANUTILS REMAINS BINARY COMPATIBLE WITH PREVIOUS RELEASES. There are two issues here: 1) Memory Issues: The static HashMap caused memory problems (See BEANUTILS-59) to resolve this it has been moved into a ContextClassLoaderLocal instance (named CLASSLOADER_CACHE above) which holds one copy per ClassLoader in a WeakHashMap. 2) Binary Compatibility: As the "dynaClasses" static HashMap is "protected" removing it breaks BeanUtils binary compatibility with previous versions. To resolve this all the methods have been overriden to delegate to the Map for the ClassLoader in the ContextClassLoaderLocal.
-
beanClassName
private final java.lang.String beanClassName
Name of the JavaBean class represented by this WrapDynaClass.
-
beanClassRef
private final java.lang.ref.Reference<java.lang.Class<?>> beanClassRef
Reference to the JavaBean class represented by this WrapDynaClass.
-
propertyUtilsBean
private final PropertyUtilsBean propertyUtilsBean
Stores the associatedPropertyUtilsBeaninstance.
-
beanClass
@Deprecated protected java.lang.Class<?> beanClass
Deprecated.No longer initialized, use getBeanClass() method insteadThe JavaBeanClasswhich is represented by thisWrapDynaClass.
-
descriptors
protected java.beans.PropertyDescriptor[] descriptors
The set of PropertyDescriptors for this bean class.
-
descriptorsMap
protected java.util.HashMap<java.lang.String,java.beans.PropertyDescriptor> descriptorsMap
The set of PropertyDescriptors for this bean class, keyed by the property name. Individual descriptor instances will be the same instances as those in thedescriptorslist.
-
properties
protected DynaProperty[] properties
The set of dynamic properties that are part of this DynaClass.
-
propertiesMap
protected java.util.HashMap<java.lang.String,DynaProperty> propertiesMap
The set of dynamic properties that are part of this DynaClass, keyed by the property name. Individual descriptor instances will be the same instances as those in thepropertieslist.
-
-
Constructor Detail
-
WrapDynaClass
private WrapDynaClass(java.lang.Class<?> beanClass, PropertyUtilsBean propUtils)Construct a new WrapDynaClass for the specified JavaBean class. This constructor is private; WrapDynaClass instances will be created as needed via calls to thecreateDynaClass(Class)method.- Parameters:
beanClass- JavaBean class to be introspected aroundpropUtils- thePropertyUtilsBeanassociated with this class
-
-
Method Detail
-
clear
public static void clear()
Clear our cache of WrapDynaClass instances.
-
createDynaClass
public static WrapDynaClass createDynaClass(java.lang.Class<?> beanClass)
Create (if necessary) and return a newWrapDynaClassinstance for the specified bean class.- Parameters:
beanClass- Bean class for which a WrapDynaClass is requested- Returns:
- A new Wrap
DynaClass
-
createDynaClass
public static WrapDynaClass createDynaClass(java.lang.Class<?> beanClass, PropertyUtilsBean pu)
Create (if necessary) and return a newWrapDynaClassinstance for the specified bean class using the givenPropertyUtilsBeaninstance for introspection. Using this method a specially configuredPropertyUtilsBeaninstance can be hooked into the introspection mechanism of the managed bean. The argument is optional; if noPropertyUtilsBeanobject is provided, the default instance is used.- Parameters:
beanClass- Bean class for which a WrapDynaClass is requestedpu- the optionalPropertyUtilsBeanto be used for introspection- Returns:
- A new Wrap
DynaClass - Since:
- 1.9
-
getClassesCache
private static java.util.Map<WrapDynaClass.CacheKey,WrapDynaClass> getClassesCache()
Returns the cache for the already created class instances. For each combination of bean class andPropertyUtilsBeaninstance an entry is created in the cache.- Returns:
- the cache for already created
WrapDynaClassinstances
-
getDynaClassesMap
private static java.util.Map<java.lang.Object,java.lang.Object> getDynaClassesMap()
Get the wrap dyna classes cache. Note: This method only exists to satisfy the deprecateddynaClasseshash map.
-
getBeanClass
protected java.lang.Class<?> getBeanClass()
Return the class of the underlying wrapped bean.- Returns:
- the class of the underlying wrapped bean
- Since:
- 1.8.0
-
getDynaProperties
public DynaProperty[] getDynaProperties()
Return an array of
ProperyDescriptorsfor the properties currently defined in this DynaClass. If no properties are defined, a zero-length array will be returned.FIXME - Should we really be implementing
getBeanInfo()instead, which returns property descriptors and a bunch of other stuff?- Specified by:
getDynaPropertiesin interfaceDynaClass- Returns:
- the set of properties for this DynaClass
-
getDynaProperty
public DynaProperty getDynaProperty(java.lang.String name)
Return a property descriptor for the specified property, if it exists; otherwise, returnnull.- Specified by:
getDynaPropertyin interfaceDynaClass- Parameters:
name- Name of the dynamic property for which a descriptor is requested- Returns:
- The descriptor for the specified property
- Throws:
java.lang.IllegalArgumentException- if no property name is specified
-
getName
public java.lang.String getName()
Return the name of this DynaClass (analogous to thegetName()method ofjava.lang.Class), which allows the sameDynaClassimplementation class to support different dynamic classes, with different sets of properties.
-
getPropertyDescriptor
public java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.String name)
Return the PropertyDescriptor for the specified property name, if any; otherwise returnnull.- Parameters:
name- Name of the property to be retrieved- Returns:
- The descriptor for the specified property
-
getPropertyUtilsBean
protected PropertyUtilsBean getPropertyUtilsBean()
Returns thePropertyUtilsBeaninstance associated with this class. This bean is used for introspection.- Returns:
- the associated
PropertyUtilsBeaninstance - Since:
- 1.9
-
introspect
protected void introspect()
Introspect our bean class to identify the supported properties.
-
newInstance
public DynaBean newInstance() throws java.lang.IllegalAccessException, java.lang.InstantiationException
Instantiates a new standard JavaBean instance associated with this DynaClass and return it wrapped in a new WrapDynaBean instance. NOTE the JavaBean should have a no argument constructor.
NOTE - Most common use cases should not need to use this method. It is usually better to create new
WrapDynaBeaninstances by calling its constructor. For example:Object javaBean = ...; DynaBean wrapper = new WrapDynaBean(javaBean);
(This method is needed for some kinds of
DynaBeanframework.)- Specified by:
newInstancein interfaceDynaClass- Returns:
- A new
DynaBeaninstance - Throws:
java.lang.IllegalAccessException- if the Class or the appropriate constructor is not accessiblejava.lang.InstantiationException- if this Class represents an abstract class, an array class, a primitive type, or void; or if instantiation fails for some other reason
-
-