Class BeanMap

java.lang.Object
org.springframework.cglib.beans.BeanMap
All Implemented Interfaces:
Map

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
  • Field Details

  • Constructor Details

    • BeanMap

      protected BeanMap()
    • BeanMap

      protected BeanMap(Object bean)
  • Method Details

    • 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
    • newInstance

      public abstract BeanMap newInstance(Object bean)
      Create a new BeanMap instance using the specified bean. This is faster than using the create(java.lang.Object) static method.
      Parameters:
      bean - the JavaBean underlying the map
      Returns:
      a new BeanMap instance
    • 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
    • get

      public Object get(Object key)
      Specified by:
      get in interface Map
    • put

      public Object put(Object key, Object value)
      Specified by:
      put in interface Map
    • 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
    • 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
    • setBean

      public void setBean(Object bean)
      Change the underlying bean this map should use.
      Parameters:
      bean - the new JavaBean
      See Also:
    • getBean

      public Object getBean()
      Return the bean currently in use by this map.
      Returns:
      the current JavaBean
      See Also:
    • clear

      public void clear()
      Specified by:
      clear in interface Map
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map
    • size

      public int size()
      Specified by:
      size in interface Map
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map
    • remove

      public Object remove(Object key)
      Specified by:
      remove in interface Map
    • putAll

      public void putAll(Map t)
      Specified by:
      putAll in interface Map
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Map
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map
      Overrides:
      hashCode in class Object
    • entrySet

      public Set entrySet()
      Specified by:
      entrySet in interface Map
    • values

      public Collection values()
      Specified by:
      values in interface Map
    • toString

      public String toString()
      Overrides:
      toString in class Object