org.cementj.base
Class ValueObject

java.lang.Object
  extended by org.cementj.base.ValueObject
All Implemented Interfaces:
java.io.Serializable, Describable, DescribableAsXML

public abstract class ValueObject
extends java.lang.Object
implements java.io.Serializable, Describable, DescribableAsXML

Generic functionality for objects used to transfer data between objects. All VOs or value objects extending this class will have pre-built implementations of equals(), and hashcode(). In addition, these extended classes will have meaningful implementations of Describable and DescribableAsXML.

This class is named after the "Data Transfer Object" pattern. Some references use the term "Value Object" instead. They mean the same thing.

To keep VOs usable as distributed objects, it's recommended that they don't contain fields which aren't Serializable.

The implementations of equals() and hashcode() make extensions of this object automatically usable in HashMaps and Hashtables.

An example extension follows:

 public class CustomerVO extends ValueObject
{

  public CustomerVO() {}

  public String          getCustomerId()         {return _customerId;}
  public void            setCustomerId(String id)
  {
    if (id == null)  throw new IllegalArgumentException
                               ("Null customer Id not allowed.");
    if (id.equals(""))  throw new IllegalArgumentException
                                  ("Blank customer Id not allowed.");
    _customerId = id;
  }

  //  All other accessors and mutators omitted.

  private String          _customerId = null;
  private String          _firstName = null;
  private String          _lastName = null;
  private String          _address = null;
  private String          _city = null;
  private String          _state = null;
  private String          _zipCode = null;
}
 

Copyright: Delta Vortex Technologies, 2003.

See Also:
Serialized Form

Constructor Summary
protected ValueObject()
           
 
Method Summary
 java.lang.String describe()
          Provides a textual version of description and state.
 java.lang.String describeAsXMLDocument()
          Provides XML Document Text for a given instance.
 java.lang.String describeAsXMLElement()
          Provides XML Element Text for a given instance.
 java.lang.String describeAsXMLElement(java.lang.String fieldName)
          Provides XML Element Text for a given instance.
 java.lang.String encodeAsXML()
           
 boolean equals(java.lang.Object obj)
           
 java.lang.String getReasonForNotEquals(java.lang.Object obj)
          Provides a textual reason that two ValueObjects are not equal.
 int hashCode()
           
protected  void init()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ValueObject

protected ValueObject()
Method Detail

init

protected void init()

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

getReasonForNotEquals

public java.lang.String getReasonForNotEquals(java.lang.Object obj)
Provides a textual reason that two ValueObjects are not equal.

Parameters:
obj -
Returns:
text

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

describe

public java.lang.String describe()
Description copied from interface: Describable
Provides a textual version of description and state.

Specified by:
describe in interface Describable

encodeAsXML

public java.lang.String encodeAsXML()

describeAsXMLDocument

public java.lang.String describeAsXMLDocument()
Description copied from interface: DescribableAsXML
Provides XML Document Text for a given instance.

Specified by:
describeAsXMLDocument in interface DescribableAsXML
Returns:
XML Text

describeAsXMLElement

public java.lang.String describeAsXMLElement()
Description copied from interface: DescribableAsXML
Provides XML Element Text for a given instance.

Specified by:
describeAsXMLElement in interface DescribableAsXML
Returns:
XML Text

describeAsXMLElement

public java.lang.String describeAsXMLElement(java.lang.String fieldName)
Description copied from interface: DescribableAsXML
Provides XML Element Text for a given instance.

Specified by:
describeAsXMLElement in interface DescribableAsXML
Returns:
XML Text


Copyright © 2003 Delta Vortex Technologies, Inc. All Rights Reserved.