Package net.sf.cglib.beans
Class BeanMap
- java.lang.Object
-
- net.sf.cglib.beans.BeanMap
-
- All Implemented Interfaces:
java.util.Map
public abstract class BeanMap extends java.lang.Object implements java.util.MapAMap-based view of a JavaBean. The default set of keys is the union of all property names (getters or setters). An attempt to set a read-only property will be ignored, and write-only properties will be returned asnull. Removal of objects is not a supported (the key set is fixed).- Author:
- Chris Nokleberg
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBeanMap.Generator
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Objectbeanstatic intREQUIRE_GETTERLimit the properties reflected in the key set of the map to readable properties.static intREQUIRE_SETTERLimit the properties reflected in the key set of the map to writable properties.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)static BeanMapcreate(java.lang.Object bean)Helper method to create a newBeanMap.java.util.SetentrySet()booleanequals(java.lang.Object o)java.lang.Objectget(java.lang.Object key)abstract java.lang.Objectget(java.lang.Object bean, java.lang.Object key)Get the property of a bean.java.lang.ObjectgetBean()Return the bean currently in use by this map.abstract java.lang.ClassgetPropertyType(java.lang.String name)Get the type of a property.inthashCode()booleanisEmpty()abstract BeanMapnewInstance(java.lang.Object bean)Create a newBeanMapinstance using the specified bean.java.lang.Objectput(java.lang.Object key, java.lang.Object value)abstract java.lang.Objectput(java.lang.Object bean, java.lang.Object key, java.lang.Object value)Set the property of a bean.voidputAll(java.util.Map t)java.lang.Objectremove(java.lang.Object key)voidsetBean(java.lang.Object bean)Change the underlying bean this map should use.intsize()java.lang.StringtoString()java.util.Collectionvalues()
-
-
-
Field Detail
-
REQUIRE_GETTER
public static final int REQUIRE_GETTER
Limit the properties reflected in the key set of the map to readable properties.
-
REQUIRE_SETTER
public static final int REQUIRE_SETTER
Limit the properties reflected in the key set of the map to writable properties.
-
bean
protected java.lang.Object bean
-
-
Method Detail
-
create
public static BeanMap create(java.lang.Object bean)
Helper method to create a newBeanMap. For finer control over the generated instance, use a new instance ofBeanMap.Generatorinstead of this static method.- Parameters:
bean- the JavaBean underlying the map- Returns:
- a new
BeanMapinstance
-
newInstance
public abstract BeanMap newInstance(java.lang.Object bean)
Create a newBeanMapinstance using the specified bean. This is faster than using thecreate(java.lang.Object)static method.- Parameters:
bean- the JavaBean underlying the map- Returns:
- a new
BeanMapinstance
-
getPropertyType
public abstract java.lang.Class getPropertyType(java.lang.String name)
Get the type of a property.- Parameters:
name- the name of the JavaBean property- Returns:
- the type of the property, or null if the property does not exist
-
get
public java.lang.Object get(java.lang.Object key)
- Specified by:
getin interfacejava.util.Map
-
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)- Specified by:
putin interfacejava.util.Map
-
get
public abstract java.lang.Object get(java.lang.Object bean, java.lang.Object key)Get the property of a bean. This allows aBeanMapto be used statically for multiple beans--the bean instance tied to the map is ignored and the bean passed to this method is used instead.- Parameters:
bean- the bean to query; must be compatible with the type of thisBeanMapkey- must be a String- Returns:
- the current value, or null if there is no matching property
-
put
public abstract java.lang.Object put(java.lang.Object bean, java.lang.Object key, java.lang.Object value)Set the property of a bean. This allows aBeanMapto be used statically for multiple beans--the bean instance tied to the map is ignored and the bean passed to this method is used instead.- Parameters:
key- must be a String- Returns:
- the old value, if there was one, or null
-
setBean
public void setBean(java.lang.Object bean)
Change the underlying bean this map should use.- Parameters:
bean- the new JavaBean- See Also:
getBean()
-
getBean
public java.lang.Object getBean()
Return the bean currently in use by this map.- Returns:
- the current JavaBean
- See Also:
setBean(java.lang.Object)
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Map
-
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKeyin interfacejava.util.Map
-
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValuein interfacejava.util.Map
-
size
public int size()
- Specified by:
sizein interfacejava.util.Map
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Map
-
remove
public java.lang.Object remove(java.lang.Object key)
- Specified by:
removein interfacejava.util.Map
-
putAll
public void putAll(java.util.Map t)
- Specified by:
putAllin interfacejava.util.Map
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equalsin interfacejava.util.Map- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Map- Overrides:
hashCodein classjava.lang.Object
-
entrySet
public java.util.Set entrySet()
- Specified by:
entrySetin interfacejava.util.Map
-
values
public java.util.Collection values()
- Specified by:
valuesin interfacejava.util.Map
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-