net.sf.cglib.beans

Class BeanMap

public abstract class BeanMap extends Object implements Map

A Map-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 as null. Removal of objects is not a supported (the key set is fixed).

Author: Chris Nokleberg

Nested Class Summary
static classBeanMap.Generator
Field Summary
static intREQUIRE_GETTER
Limit the properties reflected in the key set of the map to readable properties.
static intREQUIRE_SETTER
Limit the properties reflected in the key set of the map to writable properties.
Method Summary
voidclear()
booleancontainsKey(Object key)
booleancontainsValue(Object value)
static BeanMapcreate(Object bean)
Helper method to create a new BeanMap.
SetentrySet()
booleanequals(Object o)
Objectget(Object key)
abstract Objectget(Object bean, Object key)
Get the property of a bean.
ObjectgetBean()
Return the bean currently in use by this map.
abstract ClassgetPropertyType(String name)
Get the type of a property.
inthashCode()
booleanisEmpty()
abstract BeanMapnewInstance(Object bean)
Create a new BeanMap instance using the specified bean.
Objectput(Object key, Object value)
abstract Objectput(Object bean, Object key, Object value)
Set the property of a bean.
voidputAll(Map t)
Objectremove(Object key)
voidsetBean(Object bean)
Change the underlying bean this map should use.
intsize()
StringtoString()
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.

See Also: Generator

REQUIRE_SETTER

public static final int REQUIRE_SETTER
Limit the properties reflected in the key set of the map to writable properties.

See Also: Generator

Method Detail

clear

public void clear()

containsKey

public boolean containsKey(Object key)

containsValue

public boolean containsValue(Object value)

create

public static BeanMap create(Object bean)
Helper method to create a new BeanMap. For finer control over the generated instance, use a new instance of BeanMap.Generator instead of this static method.

Parameters: bean the JavaBean underlying the map

Returns: a new BeanMap instance

entrySet

public Set entrySet()

equals

public boolean equals(Object o)

get

public Object get(Object key)

get

public abstract Object get(Object bean, Object key)
Get the property of a bean. This allows a BeanMap to 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 this BeanMap key must be a String

Returns: the current value, or null if there is no matching property

getBean

public Object getBean()
Return the bean currently in use by this map.

Returns: the current JavaBean

See Also: BeanMap

getPropertyType

public abstract Class getPropertyType(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

hashCode

public int hashCode()

isEmpty

public boolean isEmpty()

newInstance

public abstract BeanMap newInstance(Object bean)
Create a new BeanMap instance using the specified bean. This is faster than using the BeanMap static method.

Parameters: bean the JavaBean underlying the map

Returns: a new BeanMap instance

put

public Object put(Object key, Object value)

put

public abstract Object put(Object bean, Object key, Object value)
Set the property of a bean. This allows a BeanMap to 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

putAll

public void putAll(Map t)

remove

public Object remove(Object key)

setBean

public void setBean(Object bean)
Change the underlying bean this map should use.

Parameters: bean the new JavaBean

See Also: BeanMap

size

public int size()

toString

public String toString()

values

public Collection values()
Copyright (c) 2001 - Apache Software Foundation