|
|||||||||
| Home >> All >> org >> apache >> commons >> [ beanutils overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.commons.beanutils
Class LazyDynaBean

java.lang.Objectorg.apache.commons.beanutils.LazyDynaBean
- All Implemented Interfaces:
- DynaBean, java.io.Serializable
- Direct Known Subclasses:
- LazyDynaMap
- public class LazyDynaBean
- extends java.lang.Object
- implements DynaBean, java.io.Serializable
- extends java.lang.Object
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:
- Simple property methods -
get(name)andset(name, value) - Indexed property methods -
get(name, index)andset(name, index, value) - Mapped property methods -
get(name, key)andset(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 newIndexedProperty(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 newMappedProperty(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.
| Field Summary | |
protected static java.math.BigDecimal |
BigDecimal_ZERO
|
protected static java.math.BigInteger |
BigInteger_ZERO
|
protected static java.lang.Byte |
Byte_ZERO
|
protected static java.lang.Character |
Character_SPACE
|
protected static java.lang.Double |
Double_ZERO
|
protected MutableDynaClass |
dynaClass
The MutableDynaClass "base class" that this DynaBean
is associated with. |
protected static java.lang.Float |
Float_ZERO
|
protected static java.lang.Integer |
Integer_ZERO
|
private static org.apache.commons.logging.Log |
logger
Commons Logging |
protected static java.lang.Long |
Long_ZERO
|
protected static java.lang.Short |
Short_ZERO
|
protected java.util.Map |
values
The MutableDynaClass "base class" that this DynaBean
is associated with. |
| Constructor Summary | |
LazyDynaBean()
Construct a new LazyDynaBean with a LazyDynaClass instance. |
|
LazyDynaBean(DynaClass dynaClass)
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. |
|
LazyDynaBean(java.lang.String name)
Construct a new LazyDynaBean with a LazyDynaClass instance. |
|
| Method Summary | |
boolean |
contains(java.lang.String name,
java.lang.String key)
Does the specified mapped property contain a value for the specified key value? |
protected java.lang.Object |
createDynaBeanProperty(java.lang.String name,
java.lang.Class type)
Create a new Instance of a 'Mapped' Property |
protected java.lang.Object |
createIndexedProperty(java.lang.String name,
java.lang.Class type)
Create a new Instance of an 'Indexed' Property |
protected java.lang.Object |
createMappedProperty(java.lang.String name,
java.lang.Class type)
Create a new Instance of a 'Mapped' Property |
protected java.lang.Object |
createNumberProperty(java.lang.String name,
java.lang.Class type)
Create a new Instance of a 'Primitive' Property |
protected java.lang.Object |
createOtherProperty(java.lang.String name,
java.lang.Class type)
Create a new Instance of a 'Mapped' Property |
protected java.lang.Object |
createPrimitiveProperty(java.lang.String name,
java.lang.Class type)
Create a new Instance of a 'Primitive' Property |
protected java.lang.Object |
createProperty(java.lang.String name,
java.lang.Class type)
Create a new Instance of a Property |
protected java.lang.Object |
defaultIndexedProperty(java.lang.String name)
Creates a new ArrayList for an 'indexed' property
which doesn't exist. |
protected java.util.Map |
defaultMappedProperty(java.lang.String name)
Creates a new HashMap for a 'mapped' property
which doesn't exist. |
java.lang.Object |
get(java.lang.String name)
Return the value of a simple property with the specified name. |
java.lang.Object |
get(java.lang.String name,
int index)
Return the value of an indexed property with the specified name. |
java.lang.Object |
get(java.lang.String name,
java.lang.String key)
Return the value of a mapped property with the specified name. |
DynaClass |
getDynaClass()
Return the DynaClass instance that describes the set of
properties available for this DynaBean. |
java.util.Map |
getMap()
Return the Map backing this DynaBean |
protected java.lang.Object |
growIndexedProperty(java.lang.String name,
java.lang.Object indexedProperty,
int index)
|
protected boolean |
isAssignable(java.lang.Class dest,
java.lang.Class source)
Is an object of the source class assignable to the destination class? |
protected boolean |
isDynaProperty(java.lang.String name)
Indicates if there is a property with the specified name. |
protected java.util.Map |
newMap()
Creates a new instance of the Map. |
void |
remove(java.lang.String name,
java.lang.String key)
Remove any existing value for the specified key on the specified mapped property. |
void |
set(java.lang.String name,
int index,
java.lang.Object value)
Set the value of an indexed property with the specified name. |
void |
set(java.lang.String name,
java.lang.Object value)
Set the value of a simple property with the specified name. |
void |
set(java.lang.String name,
java.lang.String key,
java.lang.Object value)
Set the value of a mapped property with the specified name. |
int |
size(java.lang.String name)
Return the size of an indexed or mapped property. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
logger
private static org.apache.commons.logging.Log logger
- Commons Logging
BigInteger_ZERO
protected static final java.math.BigInteger BigInteger_ZERO
BigDecimal_ZERO
protected static final java.math.BigDecimal BigDecimal_ZERO
Character_SPACE
protected static final java.lang.Character Character_SPACE
Byte_ZERO
protected static final java.lang.Byte Byte_ZERO
Short_ZERO
protected static final java.lang.Short Short_ZERO
Integer_ZERO
protected static final java.lang.Integer Integer_ZERO
Long_ZERO
protected static final java.lang.Long Long_ZERO
Float_ZERO
protected static final java.lang.Float Float_ZERO
Double_ZERO
protected static final java.lang.Double Double_ZERO
values
protected java.util.Map values
- The
MutableDynaClass"base class" that this DynaBean is associated with.
dynaClass
protected MutableDynaClass dynaClass
- The
MutableDynaClass"base class" that this DynaBean is associated with.
| Constructor Detail |
LazyDynaBean
public LazyDynaBean()
- Construct a new
LazyDynaBeanwith aLazyDynaClassinstance.
LazyDynaBean
public LazyDynaBean(java.lang.String name)
- Construct a new
LazyDynaBeanwith aLazyDynaClassinstance.
LazyDynaBean
public LazyDynaBean(DynaClass dynaClass)
- Construct a new
DynaBeanassociated with the specifiedDynaClassinstance - if its not aMutableDynaClassthen a newLazyDynaClassis created and the properties copied.
| Method Detail |
getMap
public java.util.Map getMap()
- Return the Map backing this
DynaBean
size
public int size(java.lang.String name)
Return the size of an indexed or mapped property.
contains
public boolean contains(java.lang.String name, java.lang.String key)
- Does the specified mapped property contain a value for the specified
key value?
get
public java.lang.Object get(java.lang.String name)
Return the value of a simple property with the specified name.
N.B. Returns
nullif there is no property of the specified name.
get
public java.lang.Object get(java.lang.String name, int index)
Return the value of an indexed property with the specified name.
N.B. Returns
nullif there is no 'indexed' property of the specified name.
get
public java.lang.Object get(java.lang.String name, java.lang.String key)
Return the value of a mapped property with the specified name.
N.B. Returns
nullif there is no 'mapped' property of the specified name.
getDynaClass
public DynaClass getDynaClass()
- Return the
DynaClassinstance that describes the set of properties available for this DynaBean.- Specified by:
getDynaClassin interfaceDynaBean
remove
public void remove(java.lang.String name, java.lang.String key)
- Remove any existing value for the specified key on the
specified mapped property.
set
public void set(java.lang.String name, java.lang.Object value)
set
public void set(java.lang.String name, int index, java.lang.Object value)
- Set the value of an indexed property with the specified name.
set
public void set(java.lang.String name, java.lang.String key, java.lang.Object value)
growIndexedProperty
protected java.lang.Object growIndexedProperty(java.lang.String name, java.lang.Object indexedProperty, int index)
createProperty
protected java.lang.Object createProperty(java.lang.String name, java.lang.Class type)
- Create a new Instance of a Property
createIndexedProperty
protected java.lang.Object createIndexedProperty(java.lang.String name, java.lang.Class type)
- Create a new Instance of an 'Indexed' Property
createMappedProperty
protected java.lang.Object createMappedProperty(java.lang.String name, java.lang.Class type)
- Create a new Instance of a 'Mapped' Property
createDynaBeanProperty
protected java.lang.Object createDynaBeanProperty(java.lang.String name, java.lang.Class type)
- Create a new Instance of a 'Mapped' Property
createPrimitiveProperty
protected java.lang.Object createPrimitiveProperty(java.lang.String name, java.lang.Class type)
- Create a new Instance of a 'Primitive' Property
createNumberProperty
protected java.lang.Object createNumberProperty(java.lang.String name, java.lang.Class type)
- Create a new Instance of a 'Primitive' Property
createOtherProperty
protected java.lang.Object createOtherProperty(java.lang.String name, java.lang.Class type)
- Create a new Instance of a 'Mapped' Property
defaultIndexedProperty
protected java.lang.Object defaultIndexedProperty(java.lang.String name)
Creates a new
ArrayListfor an 'indexed' property which doesn't exist.This method shouls be overriden if an alternative
ListorArrayimplementation is required for 'indexed' properties.
defaultMappedProperty
protected java.util.Map defaultMappedProperty(java.lang.String name)
Creates a new
HashMapfor a 'mapped' property which doesn't exist.This method can be overriden if an alternative
Mapimplementation is required for 'mapped' properties.
isDynaProperty
protected boolean isDynaProperty(java.lang.String name)
- Indicates if there is a property with the specified name.
isAssignable
protected boolean isAssignable(java.lang.Class dest, java.lang.Class source)
- Is an object of the source class assignable to the destination class?
newMap
protected java.util.Map newMap()
Creates a new instance of the
Map.
|
|||||||||
| Home >> All >> org >> apache >> commons >> [ beanutils overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.commons.beanutils.LazyDynaBean