java.lang.Object | |
↳ | org.apache.commons.beanutils.LazyDynaBean |
Known Direct Subclasses |
DynaBean which automatically adds properties to the DynaClass
and provides Lazy List and Lazy Map features.
DynaBeans deal with three types of properties - simple, indexed and mapped and
have the following get()
and set()
methods for
each of these types:
get(name)
and
set(name, value)
get(name, index)
and
set(name, index, value)
get(name, key)
and
set(name, key, value)
Getting Property Values
Calling any of the get()
methods, for a property which
doesn't exist, returns null
in this implementation.
Setting Simple Properties
The LazyDynaBean
will automatically add a property to the DynaClass
if it doesn't exist when the set(name, value)
method is called.
DynaBean myBean = new LazyDynaBean();
myBean.set("myProperty", "myValue");
Setting Indexed Properties
If the property doesn't exist, the LazyDynaBean
will automatically add
a property with an ArrayList
type to the DynaClass
when
the set(name, index, value)
method is called.
It will also instantiate a new ArrayList
and automatically grow
the List
so that it is big enough to accomodate the index being set.
ArrayList
is the default indexed property that LazyDynaBean uses but
this can be easily changed by overriding the defaultIndexedProperty(name)
method.
DynaBean myBean = new LazyDynaBean();
myBean.set("myIndexedProperty", 0, "myValue1");
myBean.set("myIndexedProperty", 1, "myValue2");
If the indexed property does exist in the DynaClass
but is set to
null
in the LazyDynaBean
, then it will instantiate a
new List
or Array
as specified by the property's type
in the DynaClass
and automatically grow the List
or Array
so that it is big enough to accomodate the index being set.
DynaBean myBean = new LazyDynaBean();
MutableDynaClass myClass = (MutableDynaClass)myBean.getDynaClass();
myClass.add("myIndexedProperty", int[].class);
myBean.set("myIndexedProperty", 0, new Integer(10));
myBean.set("myIndexedProperty", 1, new Integer(20));
Setting Mapped Properties
If the property doesn't exist, the LazyDynaBean
will automatically add
a property with a HashMap
type to the DynaClass
and
instantiate a new HashMap
in the DynaBean when the
set(name, key, value)
method is called. HashMap
is the default
mapped property that LazyDynaBean uses but this can be easily changed by overriding
the defaultMappedProperty(name)
method.
DynaBean myBean = new LazyDynaBean();
myBean.set("myMappedProperty", "myKey", "myValue");
If the mapped property does exist in the DynaClass
but is set to
null
in the LazyDynaBean
, then it will instantiate a
new Map
as specified by the property's type in the DynaClass
.
DynaBean myBean = new LazyDynaBean();
MutableDynaClass myClass = (MutableDynaClass)myBean.getDynaClass();
myClass.add("myMappedProperty", TreeMap.class);
myBean.set("myMappedProperty", "myKey", "myValue");
Restricted DynaClass
MutableDynaClass
have a facility to restrict the DynaClass
so that its properties cannot be modified. If the MutableDynaClass
is
restricted then calling any of the set()
methods for a property which
doesn't exist will result in a IllegalArgumentException
being thrown.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
BigDecimal_ZERO | BigDecimal Zero | ||||||||||
BigInteger_ZERO | BigInteger Zero | ||||||||||
Byte_ZERO | Byte Zero | ||||||||||
Character_SPACE | Character Space | ||||||||||
Double_ZERO | Double Zero | ||||||||||
Float_ZERO | Float Zero | ||||||||||
Integer_ZERO | Integer Zero | ||||||||||
Long_ZERO | Long Zero | ||||||||||
Short_ZERO | Short Zero | ||||||||||
dynaClass | The MutableDynaClass "base class" that this DynaBean
is associated with. |
||||||||||
values | The MutableDynaClass "base class" that this DynaBean
is associated with. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Construct a new
LazyDynaBean with a LazyDynaClass instance. | |||||||||||
Construct a new
LazyDynaBean with a LazyDynaClass instance. | |||||||||||
Construct a new
DynaBean associated with the specified
DynaClass instance - if its not a MutableDynaClass
then a new LazyDynaClass is created and the properties copied. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Does the specified mapped property contain a value for the specified
key value?
| |||||||||||
Return the value of an indexed property with the specified name. | |||||||||||
Return the value of a mapped property with the specified name. | |||||||||||
Return the value of a simple property with the specified name. | |||||||||||
Return the
DynaClass instance that describes the set of
properties available for this DynaBean. | |||||||||||
Return a Map representation of this DynaBean.
| |||||||||||
Remove any existing value for the specified key on the
specified mapped property.
| |||||||||||
Set the value of an indexed property with the specified name.
| |||||||||||
Set the value of a mapped property with the specified name.
| |||||||||||
Set the value of a simple property with the specified name.
| |||||||||||
Return the size of an indexed or mapped property. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new Instance of a 'DynaBean' Property.
| |||||||||||
Create a new Instance of an 'Indexed' Property
| |||||||||||
Create a new Instance of a 'Mapped' Property
| |||||||||||
Create a new Instance of a
java.lang.Number Property. | |||||||||||
Create a new Instance of other Property types
| |||||||||||
Create a new Instance of a 'Primitive' Property.
| |||||||||||
Create a new Instance of a Property
| |||||||||||
Creates a new | |||||||||||
Creates a new | |||||||||||
Grow the size of an indexed property
| |||||||||||
Is an object of the source class assignable to the destination class?
| |||||||||||
Indicates if there is a property with the specified name.
| |||||||||||
Creates a new instance of the |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
org.apache.commons.beanutils.DynaBean
|
The MutableDynaClass
"base class" that this DynaBean
is associated with.
Construct a new LazyDynaBean
with a LazyDynaClass
instance.
Construct a new LazyDynaBean
with a LazyDynaClass
instance.
name | Name of this DynaBean class |
---|
Construct a new DynaBean
associated with the specified
DynaClass
instance - if its not a MutableDynaClass
then a new LazyDynaClass
is created and the properties copied.
dynaClass | The DynaClass we are associated with |
---|
Does the specified mapped property contain a value for the specified key value?
name | Name of the property to check |
---|---|
key | Name of the key to check |
true if the mapped property contains a value for
the specified key, otherwise false
IllegalArgumentException | if no property name is specified |
---|
Return the value of an indexed property with the specified name.
N.B. Returns null
if there is no 'indexed'
property of the specified name.
name | Name of the property whose value is to be retrieved |
---|---|
index | Index of the value to be retrieved |
IllegalArgumentException | if the specified property exists, but is not indexed |
---|---|
IndexOutOfBoundsException | if the specified index is outside the range of the underlying property |
Return the value of a mapped property with the specified name.
N.B. Returns null
if there is no 'mapped'
property of the specified name.
name | Name of the property whose value is to be retrieved |
---|---|
key | Key of the value to be retrieved |
IllegalArgumentException | if the specified property exists, but is not mapped |
---|
Return the value of a simple property with the specified name.
N.B. Returns null
if there is no property
of the specified name.
name | Name of the property whose value is to be retrieved. |
---|
IllegalArgumentException | if no property name is specified |
---|
Return the DynaClass
instance that describes the set of
properties available for this DynaBean.
Return a Map representation of this DynaBean.
This, for example, could be used in JSTL in the following way to access a DynaBean'sfooProperty
:
${myDynaBean.map.fooProperty}
Remove any existing value for the specified key on the specified mapped property.
name | Name of the property for which a value is to be removed |
---|---|
key | Key of the value to be removed |
IllegalArgumentException | if there is no property of the specified name |
---|
Set the value of an indexed property with the specified name.
name | Name of the property whose value is to be set |
---|---|
index | Index of the property to be set |
value | Value to which this property is to be set |
ConversionException | if the specified value cannot be converted to the type required for this property |
---|---|
IllegalArgumentException | if there is no property of the specified name |
IllegalArgumentException | if the specified property exists, but is not indexed |
IndexOutOfBoundsException | if the specified index is outside the range of the underlying property |
Set the value of a mapped property with the specified name.
name | Name of the property whose value is to be set |
---|---|
key | Key of the property to be set |
value | Value to which this property is to be set |
ConversionException | if the specified value cannot be converted to the type required for this property |
---|---|
IllegalArgumentException | if there is no property of the specified name |
IllegalArgumentException | if the specified property exists, but is not mapped |
Set the value of a simple property with the specified name.
name | Name of the property whose value is to be set |
---|---|
value | Value to which this property is to be set |
IllegalArgumentException | if this is not an existing property name for our DynaClass and the MutableDynaClass is restricted |
---|---|
ConversionException | if the specified value cannot be converted to the type required for this property |
NullPointerException | if an attempt is made to set a primitive property to null |
Return the size of an indexed or mapped property.
name | Name of the property |
---|
IllegalArgumentException | if no property name is specified |
---|
Create a new Instance of a 'DynaBean' Property.
name | The name of the property |
---|---|
type | The class of the property |
Create a new Instance of an 'Indexed' Property
name | The name of the property |
---|---|
type | The class of the property |
Create a new Instance of a 'Mapped' Property
name | The name of the property |
---|---|
type | The class of the property |
Create a new Instance of a java.lang.Number
Property.
name | The name of the property |
---|---|
type | The class of the property |
Create a new Instance of other Property types
name | The name of the property |
---|---|
type | The class of the property |
Create a new Instance of a 'Primitive' Property.
name | The name of the property |
---|---|
type | The class of the property |
Create a new Instance of a Property
name | The name of the property |
---|---|
type | The class of the property |
Creates a new ArrayList
for an 'indexed' property
which doesn't exist.
This method shouls be overriden if an alternative List
or Array
implementation is required for 'indexed' properties.
name | Name of the 'indexed property. |
---|
Creates a new HashMap
for a 'mapped' property
which doesn't exist.
This method can be overriden if an alternative Map
implementation is required for 'mapped' properties.
name | Name of the 'mapped property. |
---|
Grow the size of an indexed property
name | The name of the property |
---|---|
indexedProperty | The current property value |
index | The indexed value to grow the property to (i.e. one less than the required size) |
Is an object of the source class assignable to the destination class?
dest | Destination class |
---|---|
source | Source class |
true if the source class is assignable to the
destination class, otherwise false
Indicates if there is a property with the specified name.
name | The name of the property to check |
---|
true if there is a property of the
specified name, otherwise false