Class MapAdapter

  • All Implemented Interfaces:
    Serializable

    public class MapAdapter
    extends IterableAdapter
    A MapAdapter supports properties whose types implement the java.util.Map interface.
    
     <property>
       <name>People</name>
       <xml-name>people</xml-name>         <!-- defaults to <name> -->
       <type>java.util.Map</type>          <!-- defaults via reflection -->
       <class>java.util.HashMap</class>    <!-- defaults to <type> -->
       <empty-is-null>true</empty-is-null> <!-- defaults to false -->
       <element>
         <xml-name>person</xml-name>       <!-- required -->
         <key>
           <name>ssn</name>                <!-- defaults to "key" -->
           <xml-name>ssn</xml-name>        <!-- defaults to <name> -->
           <type>String</type>             <!-- required -->
           <adapter>...</adapter>          <!-- optional -->
           <...>                           <!-- for the type-specific adapter -->
         </key>
         <value>
           <name>info</name>               <!-- defaults to "value" -->
           <xml-name>info</xml-name>       <!-- defaults to <name> -->
           <type>com...PersonBean</type>   <!-- required -->
           <adapter>...</adapter>          <!-- optional -->
           <...>                           <!-- for the type-specific adapter -->
         </value>
       </elelemt>  
     </property>
    
     Example of map nested within collection tags:
    
       <doc>
         <people>
           <person>
             <ssn>...</ssn>
             <info>...</info>
           </person>
           <person>
             <ssn>...</ssn>
             <info>...</info>
           </person>
           ...
         </people>
       </doc>
     
    Version:
    1.00 2001.03.18
    Author:
    cp
    See Also:
    Serialized Form
    • Constructor Detail

      • MapAdapter

        public MapAdapter​(XmlBean.BeanInfo infoBean,
                          Class clzType,
                          String sName,
                          String sXml,
                          XmlElement xml)
        Construct a MapAdapter.
        Parameters:
        infoBean - BeanInfo for a bean containing this property
        clzType - the type of the property
        sName - the property name
        sXml - the XML tag name
        xml - additional XML information
    • Method Detail

      • clone

        public Object clone​(Object o)
        Make a clone of the passed object.
        Overrides:
        clone in class PropertyAdapter
        Parameters:
        o - the object to clone
        Returns:
        a clone of the passed object
      • readElements

        protected Object readElements​(XmlElement xml)
        Specified by:
        readElements in class IterableAdapter
        Parameters:
        xml - the XML element containing the XML elements to deserialize from
        Returns:
        the object deserialized from the XML (not null)
      • writeElements

        protected void writeElements​(XmlElement xml,
                                     Object o)
        Specified by:
        writeElements in class IterableAdapter
        Parameters:
        xml - the XML element to which the iterable elements are written
        o - the object to serialize (not null)
      • readExternal

        public Object readExternal​(DataInput in)
                            throws IOException
        Read a value from the passed DataInput object.
        Overrides:
        readExternal in class PropertyAdapter
        Parameters:
        in - the DataInput stream to read property data from
        Returns:
        the data read from the DataInput; never null
        Throws:
        IOException - if an I/O exception occurs
      • writeExternal

        public void writeExternal​(DataOutput out,
                                  Object o)
                           throws IOException
        Write the specified data to the passed DataOutput object.
        Overrides:
        writeExternal in class PropertyAdapter
        Parameters:
        out - the DataOutput stream to write to
        o - the data to write to the DataOutput; never null
        Throws:
        IOException - if an I/O exception occurs
      • isEmpty

        public boolean isEmpty​(Object o)
        Determine if the specified value is empty.
        Overrides:
        isEmpty in class PropertyAdapter
        Parameters:
        o - the value
        Returns:
        true if the object is considered to be empty for persistence and XML-generation purposes
      • getKeyAdapter

        public PropertyAdapter getKeyAdapter()
        Returns:
        a PropertyAdapter for map entry keys
      • getValueAdapter

        public PropertyAdapter getValueAdapter()
        Returns:
        a PropertyAdapter for map entry values
      • instantiateMap

        protected Map instantiateMap()
        Returns:
        a new Map instance