001    package com.sptci.rwt;
002    
003    import java.io.Serializable;
004    
005    /**
006     * An abstract base class for all value objects that represent metadata for
007     * database objects.
008     *
009     * <p>&copy; Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
010     * @author Rakesh Vidyadharan 2007-09-25
011     * @version $Id: MetaData.java 4123 2008-05-25 21:49:01Z rakesh $
012     */
013    public abstract class MetaData implements Serializable
014    {
015      /**
016       * The name of the object.
017       */
018      private String name;
019    
020      /**
021       * Return a string representation of this instance.  By default return
022       * {@link #getName}.
023       *
024       * @return The string representation of this object.
025       */
026      @Override
027      public String toString()
028      {
029        return getName();
030      }
031    
032      /**
033       * Default implementation of the equality comparison method.  Compares
034       * the class types and {@link #name} values.
035       *
036       * @param object The object that is to be compared with this for equality.
037       * @return Returns <code>true</code> if the object is of the same type
038       *   and has the same {@link #name}.
039       */
040      @Override
041      public boolean equals( Object object )
042      {
043        if ( this == object ) return true;
044        boolean result = false;
045    
046        if ( getClass() == object.getClass() )
047        {
048          MetaData md = (MetaData) object;
049          result = ( ( getName() == md.getName() ) ||
050              ( ( getName() != null ) && getName().equals( md.getName() ) ) );
051        }
052    
053        return result;
054      }
055    
056      /**
057       * Return a hash code for this object.
058       *
059       * @return The hash code value computed out of the class of this object
060       *   and {@link #name}.
061       */
062      @Override
063      public int hashCode()
064      {
065        int hash = 7;
066        hash += ( 31 * 7 ) + getClass().getName().hashCode();
067        hash += ( 31 * 7 ) + ( ( getName() == null ) ? 0 : getName().hashCode() );
068        return hash;
069      }
070      
071      /**
072       * Returns {@link #name}.
073       *
074       * @return The value/reference of/to name.
075       */
076      public String getName()
077      {
078        return name;
079      }
080      
081      /**
082       * Set {@link #name}.
083       *
084       * @param name The value to set.
085       */
086      protected void setName( final String name )
087      {
088        this.name = name;
089      }
090    }