Class BaseDynaBeanMapDecorator<K>

  • Type Parameters:
    K - the type of the keys in the decorated map
    All Implemented Interfaces:
    java.util.Map<K,​java.lang.Object>
    Direct Known Subclasses:
    DynaBeanMapDecorator, DynaBeanPropertyMapDecorator

    public abstract class BaseDynaBeanMapDecorator<K>
    extends java.lang.Object
    implements java.util.Map<K,​java.lang.Object>

    A base class for decorators providing Map behavior on DynaBeans.

    The motivation for this implementation is to provide access to DynaBean properties in technologies that are unaware of BeanUtils and DynaBeans - such as the expression languages of JSTL and JSF.

    This rather technical base class implements the methods of the Map interface on top of a DynaBean. It was introduced to handle generic parameters in a meaningful way without breaking backwards compatibility of the DynaBeanMapDecorator class: A map wrapping a DynaBean should be of type Map<String, Object>. However, when using these generic parameters in DynaBeanMapDecorator this would be an incompatible change (as method signatures would have to be adapted). To solve this problem, this generic base class is added which allows specifying the key type as parameter. This makes it easy to have a new subclass using the correct generic parameters while DynaBeanMapDecorator could still remain with compatible parameters.

    Since:
    BeanUtils 1.9.0
    Version:
    $Id$
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  BaseDynaBeanMapDecorator.MapEntry<K>
      Map.Entry implementation.
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      clear() operation is not supported.
      boolean containsKey​(java.lang.Object key)
      Indicate whether the DynaBean contains a specified value for one (or more) of its properties.
      boolean containsValue​(java.lang.Object value)
      Indicates whether the decorated DynaBean contains a specified value.
      protected abstract K convertKey​(java.lang.String propertyName)
      Converts the name of a property to the key type of this decorator.
      java.util.Set<java.util.Map.Entry<K,​java.lang.Object>> entrySet()
      Returns the Set of the property/value mappings in the decorated DynaBean.
      java.lang.Object get​(java.lang.Object key)
      Return the value for the specified key from the decorated DynaBean.
      DynaBean getDynaBean()
      Provide access to the underlying DynaBean this Map decorates.
      private DynaProperty[] getDynaProperties()
      Convenience method to retrieve the DynaPropertys for this DynaClass.
      boolean isEmpty()
      Indicate whether the decorated DynaBean has any properties.
      boolean isReadOnly()
      Indicate whether the Map is read only.
      java.util.Set<K> keySet()
      Returns the Set of the property names in the decorated DynaBean.
      java.lang.Object put​(K key, java.lang.Object value)
      Set the value for the specified property in the decorated DynaBean.
      void putAll​(java.util.Map<? extends K,​? extends java.lang.Object> map)
      Copy the contents of a Map to the decorated DynaBean.
      java.lang.Object remove​(java.lang.Object key)
      remove() operation is not supported.
      int size()
      Returns the number properties in the decorated DynaBean.
      private java.lang.String toString​(java.lang.Object obj)
      Convenience method to convert an Object to a String.
      java.util.Collection<java.lang.Object> values()
      Returns the set of property values in the decorated DynaBean.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • dynaBean

        private final DynaBean dynaBean
      • readOnly

        private final boolean readOnly
      • keySet

        private transient java.util.Set<K> keySet
    • Constructor Detail

      • BaseDynaBeanMapDecorator

        public BaseDynaBeanMapDecorator​(DynaBean dynaBean)
        Constructs a read only Map for the specified DynaBean.
        Parameters:
        dynaBean - The dyna bean being decorated
        Throws:
        java.lang.IllegalArgumentException - if the DynaBean is null.
      • BaseDynaBeanMapDecorator

        public BaseDynaBeanMapDecorator​(DynaBean dynaBean,
                                        boolean readOnly)
        Construct a Map for the specified DynaBean.
        Parameters:
        dynaBean - The dyna bean being decorated
        readOnly - true if the Map is read only otherwise false
        Throws:
        java.lang.IllegalArgumentException - if the DynaBean is null.
    • Method Detail

      • isReadOnly

        public boolean isReadOnly()
        Indicate whether the Map is read only.
        Returns:
        true if the Map is read only, otherwise false.
      • clear

        public void clear()
        clear() operation is not supported.
        Specified by:
        clear in interface java.util.Map<K,​java.lang.Object>
        Throws:
        java.lang.UnsupportedOperationException
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Indicate whether the DynaBean contains a specified value for one (or more) of its properties.
        Specified by:
        containsKey in interface java.util.Map<K,​java.lang.Object>
        Parameters:
        key - The DynaBean's property name
        Returns:
        true if one of the DynaBean's properties contains a specified value.
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Indicates whether the decorated DynaBean contains a specified value.
        Specified by:
        containsValue in interface java.util.Map<K,​java.lang.Object>
        Parameters:
        value - The value to check for.
        Returns:
        true if one of the the DynaBean's properties contains the specified value, otherwise false.
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​java.lang.Object>> entrySet()

        Returns the Set of the property/value mappings in the decorated DynaBean.

        Each element in the Set is a Map.Entry type.

        Specified by:
        entrySet in interface java.util.Map<K,​java.lang.Object>
        Returns:
        An unmodifiable set of the DynaBean property name/value pairs
      • get

        public java.lang.Object get​(java.lang.Object key)
        Return the value for the specified key from the decorated DynaBean.
        Specified by:
        get in interface java.util.Map<K,​java.lang.Object>
        Parameters:
        key - The DynaBean's property name
        Returns:
        The value for the specified property.
      • isEmpty

        public boolean isEmpty()
        Indicate whether the decorated DynaBean has any properties.
        Specified by:
        isEmpty in interface java.util.Map<K,​java.lang.Object>
        Returns:
        true if the DynaBean has no properties, otherwise false.
      • keySet

        public java.util.Set<K> keySet()

        Returns the Set of the property names in the decorated DynaBean.

        N.B.For DynaBeans whose associated DynaClass is a MutableDynaClass a new Set is created every time, otherwise the Set is created only once and cached.

        Specified by:
        keySet in interface java.util.Map<K,​java.lang.Object>
        Returns:
        An unmodifiable set of the DynaBeans property names.
      • put

        public java.lang.Object put​(K key,
                                    java.lang.Object value)
        Set the value for the specified property in the decorated DynaBean.
        Specified by:
        put in interface java.util.Map<K,​java.lang.Object>
        Parameters:
        key - The DynaBean's property name
        value - The value for the specified property.
        Returns:
        The previous property's value.
        Throws:
        java.lang.UnsupportedOperationException - if isReadOnly() is true.
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends java.lang.Object> map)
        Copy the contents of a Map to the decorated DynaBean.
        Specified by:
        putAll in interface java.util.Map<K,​java.lang.Object>
        Parameters:
        map - The Map of values to copy.
        Throws:
        java.lang.UnsupportedOperationException - if isReadOnly() is true.
      • remove

        public java.lang.Object remove​(java.lang.Object key)
        remove() operation is not supported.
        Specified by:
        remove in interface java.util.Map<K,​java.lang.Object>
        Parameters:
        key - The DynaBean's property name
        Returns:
        the value removed
        Throws:
        java.lang.UnsupportedOperationException
      • size

        public int size()
        Returns the number properties in the decorated DynaBean.
        Specified by:
        size in interface java.util.Map<K,​java.lang.Object>
        Returns:
        The number of properties.
      • values

        public java.util.Collection<java.lang.Object> values()
        Returns the set of property values in the decorated DynaBean.
        Specified by:
        values in interface java.util.Map<K,​java.lang.Object>
        Returns:
        Unmodifiable collection of values.
      • getDynaBean

        public DynaBean getDynaBean()
        Provide access to the underlying DynaBean this Map decorates.
        Returns:
        the decorated DynaBean.
      • convertKey

        protected abstract K convertKey​(java.lang.String propertyName)
        Converts the name of a property to the key type of this decorator.
        Parameters:
        propertyName - the name of a property
        Returns:
        the converted key to be used in the decorated map
      • toString

        private java.lang.String toString​(java.lang.Object obj)
        Convenience method to convert an Object to a String.
        Parameters:
        obj - The Object to convert
        Returns:
        String representation of the object