Class PropertyAdapter

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
IterableAdapter, SerializableAdapter, SimpleAdapter, XmlElementAdapter, XmlSerializableAdapter

public abstract class PropertyAdapter extends ExternalizableHelper implements Serializable
The PropertyAdapter is the base class for handling the operations that can occur on any property.

 <property>
   <name>People</name>
   <xml-name>people</xml-name>     <!-- optional, empty name indicates anonymous element -->
   <adapter>...</adapter>          <!-- optional -->
   <type>...</type>                <!-- defaults via reflection -->
   <class>...</class>              <!-- defaults to <type> -->
 <property>
 
Version:
1.00 2001.03.06
Author:
cp
See Also:
  • Field Details

    • NOPARAMS

      protected static final Class[] NOPARAMS
      Parameters for finding no-parameter methods.
    • m_infoBean

      protected XmlBean.BeanInfo m_infoBean
      The BeanInfo object that contains this PropertyAdapter.
    • m_sName

      protected String m_sName
      The property name.
    • m_sXml

      protected String m_sXml
      The XML element name used to store this property.
    • m_fAttribute

      protected boolean m_fAttribute
      True if the property is stored in an attribute instead of an XML element.
    • m_clzType

      protected Class m_clzType
      The type of the property.
    • m_methodGet

      protected Method m_methodGet
      The property "accessor" method.
    • m_methodSet

      protected Method m_methodSet
      The property "mutator" method.
    • m_methodClone

      protected Method m_methodClone
      The "public Object clone()" method for the property type, if available.
    • m_sNmsUri

      protected String m_sNmsUri
      The namespace URI for this property.
    • m_sNmsPrefix

      protected String m_sNmsPrefix
      The namespace prefix for this property.
  • Constructor Details

    • PropertyAdapter

      protected PropertyAdapter(XmlBean.BeanInfo infoBean, Class clzType, String sName, String sXml, XmlElement xml)
      Construct a PropertyAdapter.

      Note: This constructor may narrow the specified property type to match the declared property accessor return type; therefore, subclasses should not assume that the specified property type will be equal to that returned by the getType() method.

      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 Details

    • getBeanInfo

      public XmlBean.BeanInfo getBeanInfo()
      Obtain the containing BeanInfo object.
      Returns:
      the BeanInfo that describes an XML bean containing this property
    • getName

      public String getName()
      Obtain the name of the property that this PropertyAdapter handles.
      Returns:
      the property name
    • getLocalXmlName

      public String getLocalXmlName()
      Determine the "local" XML element name that will be used to hold the property value.
      Returns:
      the local XML element name for the property value
    • getXmlName

      public String getXmlName()
      Return the XML element name used to generate an XML.
      Returns:
      the outgoing XML element name for the property value
    • isElementMatch

      public boolean isElementMatch(XmlElement xml)
      Check whether or not the passed element matches to the property's local name and Namespace URI.
      Parameters:
      xml - the XML element
      Returns:
      true if the specified element represents a value for a property represented by this adapter
    • findElement

      public XmlElement findElement(XmlElement xml)
      Find a child element of the specified XmlElement that represents a value for a property represented by this adapter.
      Parameters:
      xml - the parent XmlElement
      Returns:
      an element that can be processed by this adapther; null if none could be found
    • getElements

      public Iterator getElements(XmlElement xml)
      Get an iterator of child elements of the specified XmlElement that represent values for a property represented by this adapter.
      Parameters:
      xml - the parent XmlElement
      Returns:
      an iterator containing all child elements that can be processed by this adapther
    • findAttribute

      public XmlValue findAttribute(XmlElement xml)
      Find an attribute of the specified XmlElement that represents a value for a property represented by this adapter.
      Parameters:
      xml - the parent XmlElement
      Returns:
      an attribute that can be processed by this adapther; null if none could be found
    • getNamespaceUri

      public String getNamespaceUri()
      Determine the namespace URI for the property.
      Returns:
      the URI that qualifies the Namespace for this property
    • getNamespacePrefix

      public String getNamespacePrefix()
      Determine the default namespace prefix for the property.
      Returns:
      the default Namespace prefix for this property
    • setNamespacePrefix

      public void setNamespacePrefix(String sPrefix)
      Set the default Namespace prefix for this property.
      Parameters:
      sPrefix - the new default namespace for this property
    • getType

      public Class getType()
      Obtain the type of the property (the class of the object declared as being returned by the accessor and passed to the mutator).
      Returns:
      the property type
    • getAccessor

      public Method getAccessor()
      Obtain the Method object that is used to call the property accessor.
      Returns:
      the accessor (getter) method for the property
    • getMutator

      public Method getMutator()
      Obtain the Method object that is used to call the property mutator.
      Returns:
      the mutator (setter) method for the property or null if the property is not settable
    • getCloner

      public Method getCloner()
      Obtain the Method object that is used to deep-clone the property value.
      Returns:
      the clone method for the property or null if none is applicable or available
    • isAnonymous

      public boolean isAnonymous()
      Determine if this property does not have a designated element name.
      Returns:
      true if the property doesn't have an associated XmlElement
    • isAttribute

      public boolean isAttribute()
      Determine if the property is stored in an XML attribute instead of an XML element.
      Returns:
      true if the property is attribute bound
    • isCloneRequired

      public abstract boolean isCloneRequired()
      Determine if the property value must be deep-cloned. Typically, a property value must be deep-cloned if it is a mutable reference type, e.g. StringBuffer, Date, byte[].
      Returns:
      true if the property value must be "deep" cloned when the containing object is cloned
    • get

      public Object get(XmlBean bean)
      Extract the property value from the passed bean reference.
      Parameters:
      bean - the XML bean object to obtain the property value from
      Returns:
      the property value
    • isEmpty

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

      public void set(XmlBean bean, Object o)
      Store the property value in the passed bean.
      Parameters:
      bean - the XML bean object to store the property value into
      o - the property value
    • hash

      public int hash(Object o)
      compute a hash code for the passed object.
      Parameters:
      o - the object to compute a hash code for
      Returns:
      an integer hash code
    • equalsValue

      public boolean equalsValue(Object o1, Object o2)
      Compare the two passed objects for equality.
      Parameters:
      o1 - the first object
      o2 - the second object
      Returns:
      true if the two objects are equal
    • clone

      public Object clone(Object o)
      Make a clone of the passed object.
      Parameters:
      o - the object to clone
      Returns:
      a clone of the passed object
    • fromXml

      public Object fromXml(XmlElement xml)
      Deserialize an object from an XML element.
      Parameters:
      xml - the XML element to deserialize from
      Returns:
      the object deserialized from the XML element
      Throws:
      UnsupportedOperationException - if the property cannot be read from a single XML element
    • toXml

      public XmlElement toXml(Object o)
      Serialize an object into an XML element.
      Parameters:
      o - the object to serialize
      Returns:
      the XML element representing the serialized form of the passed object
      Throws:
      UnsupportedOperationException - if the property cannot be written to a single XML element
    • readXml

      public Object readXml(XmlElement xml)
      Deserialize an object from XML. Note that the parent element is the one passed to this method; this method is responsible for finding all of the necessarily elements within the parent element. This method is intended to allow collection properties to read their data from multiple XML elements.
      Parameters:
      xml - the XML element containing the XML elements to deserialize from
      Returns:
      the object deserialized from the XML (may be null)
    • writeXml

      public void writeXml(XmlElement xml, Object o)
      Serialize an object into an XML element. Note that the parent element is the one passed to this method; this method is responsible for creating the necessarily elements within the parent element. This method is intended to allow collection properties to write their data to multiple XML elements.
      Parameters:
      xml - the XML element containing the XML elements to serialize to
      o - the object to serialize (may be null)
    • fromUri

      public Object fromUri(String sUri)
      Deserialize an object from a URI element.
      Parameters:
      sUri - the URI element to deserialize from
      Returns:
      the object deserialized from the URI element
      Throws:
      UnsupportedOperationException - if the property cannot be read from a URI element
    • toUri

      public String toUri(Object o)
      Serialize an object into a URI element.
      Parameters:
      o - the object to serialize
      Returns:
      the URI element representing the serialized form of the passed object
      Throws:
      UnsupportedOperationException - if the property cannot be written to a URI element
    • readExternal

      public Object readExternal(DataInput in) throws IOException
      Read a value from the passed DataInput object.
      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.
      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
    • toString

      public String toString()
      Debugging support.
      Overrides:
      toString in class Object
      Returns:
      a String description of this PropertyAdapter object