org.oddjob.values.types
Class PropertyTypeDynaClass

java.lang.Object
  extended by org.oddjob.values.types.PropertyTypeDynaClass
All Implemented Interfaces:
Serializable, org.apache.commons.beanutils.DynaClass, org.apache.commons.beanutils.MutableDynaClass

public class PropertyTypeDynaClass
extends Object
implements org.apache.commons.beanutils.MutableDynaClass, Serializable

A DynaClass for the PropertyType which always returns PropertyType as the type for all properties.

See Also:
org.apche.commons.beanutils.LazyDynaBean, Serialized Form
Author:
Rob Gordon

Constructor Summary
PropertyTypeDynaClass(String name)
          Constructor.
 
Method Summary
protected  void add(org.apache.commons.beanutils.DynaProperty property)
          Add a new dynamic property.
 void add(String name)
           
 void add(String name, Class type)
          Add a new dynamic property with the specified data type, but with no restrictions on readability or writeability.
 void add(String name, Class type, boolean readable, boolean writeable)
          Add a new dynamic property with the specified data type, readability, and writeability.
 org.apache.commons.beanutils.DynaProperty[] getDynaProperties()
           
 org.apache.commons.beanutils.DynaProperty getDynaProperty(String name)
          Return a property descriptor for the specified property.
 String getName()
           
 boolean isRestricted()
          This MutableDynaClass is never restricted.
 org.apache.commons.beanutils.DynaBean newInstance()
           
 void remove(String name)
          Remove the specified dynamic property, and any associated data type, readability, and writeability, from this dynamic class.
 void setRestricted(boolean restricted)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyTypeDynaClass

public PropertyTypeDynaClass(String name)
Constructor.

Parameters:
name - The name.
Method Detail

isRestricted

public boolean isRestricted()
This MutableDynaClass is never restricted.

Specified by:
isRestricted in interface org.apache.commons.beanutils.MutableDynaClass
See Also:
MutableDynaClass.isRestricted()

setRestricted

public void setRestricted(boolean restricted)
Specified by:
setRestricted in interface org.apache.commons.beanutils.MutableDynaClass

add

public void add(String name)
Specified by:
add in interface org.apache.commons.beanutils.MutableDynaClass

add

public void add(String name,
                Class type)
Add a new dynamic property with the specified data type, but with no restrictions on readability or writeability.

Specified by:
add in interface org.apache.commons.beanutils.MutableDynaClass
Parameters:
name - Name of the new dynamic property
type - Data type of the new dynamic property (null for no restrictions)
Throws:
IllegalArgumentException - if name is null
IllegalStateException - if this DynaClass is currently restricted, so no new properties can be added

add

public void add(String name,
                Class type,
                boolean readable,
                boolean writeable)

Add a new dynamic property with the specified data type, readability, and writeability.

N.B.Support for readable/writeable properties has not been implemented and this method always throws a UnsupportedOperationException.

I'm not sure the intention of the original authors for this method, but it seems to me that readable/writable should be attributes of the DynaProperty class (which they are not) and is the reason this method has not been implemented.

Specified by:
add in interface org.apache.commons.beanutils.MutableDynaClass
Parameters:
name - Name of the new dynamic property
type - Data type of the new dynamic property (null for no restrictions)
readable - Set to true if this property value should be readable
writeable - Set to true if this property value should be writeable
Throws:
UnsupportedOperationException - anytime this method is called

add

protected void add(org.apache.commons.beanutils.DynaProperty property)
Add a new dynamic property.

Parameters:
property - Property the new dynamic property to add.
Throws:
IllegalArgumentException - if name is null
IllegalStateException - if this DynaClass is currently restricted, so no new properties can be added

remove

public void remove(String name)
Remove the specified dynamic property, and any associated data type, readability, and writeability, from this dynamic class. NOTE - This does NOT cause any corresponding property values to be removed from DynaBean instances associated with this DynaClass.

Specified by:
remove in interface org.apache.commons.beanutils.MutableDynaClass
Parameters:
name - Name of the dynamic property to remove
Throws:
IllegalArgumentException - if name is null
IllegalStateException - if this DynaClass is currently restricted, so no properties can be removed

getDynaProperty

public org.apache.commons.beanutils.DynaProperty getDynaProperty(String name)

Return a property descriptor for the specified property.

If the property is not found and the returnNull indicator is true, this method always returns null.

If the property is not found and the returnNull indicator is false a new property descriptor is created and returned (although its not actually added to the DynaClass's properties). This is the default beahviour.

The reason for not returning a null property descriptor is that BeanUtils uses this method to check if a property exists before trying to set it - since these Lazy implementations automatically add any new properties when they are set, returning null from this method would defeat their purpose.

Specified by:
getDynaProperty in interface org.apache.commons.beanutils.DynaClass
Parameters:
name - Name of the dynamic property for which a descriptor is requested
Throws:
IllegalArgumentException - if no property name is specified

getDynaProperties

public org.apache.commons.beanutils.DynaProperty[] getDynaProperties()
Specified by:
getDynaProperties in interface org.apache.commons.beanutils.DynaClass

getName

public String getName()
Specified by:
getName in interface org.apache.commons.beanutils.DynaClass

newInstance

public org.apache.commons.beanutils.DynaBean newInstance()
                                                  throws IllegalAccessException,
                                                         InstantiationException
Specified by:
newInstance in interface org.apache.commons.beanutils.DynaClass
Throws:
IllegalAccessException
InstantiationException