org.jlf.dataMap
Class DataAttribute

java.lang.Object
  |
  +--org.jlf.dataMap.DataAttribute
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
DateAttribute, DoubleAttribute, LongAttribute, StringAttribute

public class DataAttribute
extends java.lang.Object
implements java.io.Serializable

This class is used as the base of all attributes in the data mapping framework

See Also:
DataAttributeDescriptor, Serialized Form

Field Summary
protected  boolean hasChanged
          Keeps track of whether the attribute has changed since it was originally read in from the database.
protected  java.lang.String name
          Name of the attribute.
protected  java.lang.Object originalValue
          Original value of the attribute.
protected  java.lang.Object value
          Normal value of the attribute.
 
Constructor Summary
DataAttribute()
          Default constructor.
DataAttribute(java.lang.String name)
          Normal attribute constructor.
 
Method Summary
protected  void basicSetValue(java.lang.Object newValue)
          Sets the value variable.
 double getDoubleValue()
          Returns the double value of the attribute if the attribute has one.
 long getLongValue()
          Returns the long value of the attribute if the attribute has one.
 java.lang.String getName()
          Returns the name of the attribute.
 java.lang.Object getOriginalValue()
          Returns the original value of the attribute.
 java.lang.String getStringValue()
          Returns the current value of the attribute as a string.
 java.lang.Object getValue()
          Returns the current value of the attribute.
 boolean hasChanged()
          Checks to see if the value of the attribute has changed since it was originally read in from a data source.
 DataAttribute resetAndSetValue(java.lang.Object newValue)
          Resets/sets the attribute on an initial read from a data source.
 void resetHasChanged()
          Sets the original value to the value, resets the has changed variable.
 void setName(java.lang.String name)
          Sets the name of the attribute.
 void setValue(java.lang.Object newValue)
          Sets the value of the attribute, retaining an originalValue.
 java.lang.String toString()
          Dispatch this method back to getValue()'s object if not null, otherwise return empty string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
Name of the attribute.


value

protected java.lang.Object value
Normal value of the attribute. NOTE: Be careful when setting this value. Most methods should be going through the basicSetValue() method so validation at the subclass level can take place!!!


originalValue

protected java.lang.Object originalValue
Original value of the attribute. If the value was changed since the object was read from a source, this attribute contains the originally-read value.


hasChanged

protected boolean hasChanged
Keeps track of whether the attribute has changed since it was originally read in from the database.

Constructor Detail

DataAttribute

public DataAttribute()
Default constructor. Try to use a parameterized constructor with at least the attribute name to construct the attribute.


DataAttribute

public DataAttribute(java.lang.String name)
Normal attribute constructor.

Method Detail

getName

public java.lang.String getName()
Returns the name of the attribute.


setName

public void setName(java.lang.String name)
Sets the name of the attribute.


getValue

public java.lang.Object getValue()
Returns the current value of the attribute.


getOriginalValue

public java.lang.Object getOriginalValue()
Returns the original value of the attribute.


basicSetValue

protected void basicSetValue(java.lang.Object newValue)
Sets the value variable. This method provides a hook for subclasses to do validation of the value variable before it is set.


setValue

public void setValue(java.lang.Object newValue)
Sets the value of the attribute, retaining an originalValue.


resetAndSetValue

public DataAttribute resetAndSetValue(java.lang.Object newValue)
Resets/sets the attribute on an initial read from a data source. Returns the current attribute for convenience.


resetHasChanged

public void resetHasChanged()
Sets the original value to the value, resets the has changed variable. Use this method after commiting to a database, because the attribute's value matches the DB.


hasChanged

public boolean hasChanged()
Checks to see if the value of the attribute has changed since it was originally read in from a data source.


getStringValue

public java.lang.String getStringValue()
Returns the current value of the attribute as a string. If the attribute is null, returns the empty string. If the attribute is not null, uses the toString() method to convert it.


getLongValue

public long getLongValue()
Returns the long value of the attribute if the attribute has one.

Throws:
DataMapError - if the attribute cannot be safely converted to a long or if the attribute is null.

getDoubleValue

public double getDoubleValue()
Returns the double value of the attribute if the attribute has one.

Throws:
DataMapError - if the attribute cannot be safely converted to a double or if the attribute is null.

toString

public java.lang.String toString()
Dispatch this method back to getValue()'s object if not null, otherwise return empty string.

Overrides:
toString in class java.lang.Object