org.oreodata
Class AbstractRecord

java.lang.Object
  |
  +--org.oreodata.AbstractRecord
All Implemented Interfaces:
java.lang.Cloneable, java.io.Externalizable, OreoConstants, Record, java.io.Serializable
Direct Known Subclasses:
CompactRecord, DefaultRecord

public abstract class AbstractRecord
extends java.lang.Object
implements Record, java.io.Externalizable, java.lang.Cloneable, OreoConstants

An abstract base implementation of the Record interface In this implementation, the records can be written out as a human-readable string. This is the scheme used for serialization. DefaultRecord implements the java.io.Externalizable interface in order to avoid the general-purpose serialization scheme. The goal was that the resulting storage format should be human-readable and modifiable in a text editor in a pinch.

Author:
Serialized Form

Field Summary
 
Fields inherited from interface org.oreodata.OreoConstants
RECORD_STATUS_KEY, RECORD_TYPE_KEY
 
Constructor Summary
AbstractRecord()
           
 
Method Summary
 void checkValidity()
          Check if the record's data is valid.
 void clearFields()
          set the fields to their default values.
 boolean equals(java.lang.Object o)
           
 void freeze()
          make this record immutable.
 java.lang.Object get(FieldDescriptor field)
          Low-level method to query the value of a field in a Record.
protected abstract  java.lang.Object get(int i)
           
 java.lang.Object get(java.lang.Object o)
           
 java.lang.Object get(java.lang.String fieldname)
          Method to get the value of a field by name.
 java.util.List getChildren()
          In this base implementation, this always returns an empty list.
 RecordDescriptor getMetadata()
           
 Record getMutableCopy()
          create a clone.
 Record getParent()
          In this base implementation, this always returns null.
 java.lang.Object getPrimaryKey()
          Retrieve the value of the record's primary key.
 java.lang.String getType()
           
 boolean hasChildren()
          In this base implementation, this always returns false.
 boolean isRootElement()
          In this base implementation, this always returns true.
 boolean isStale()
          Has this record been deleted or superseded in the associated DataSource?
protected  void postCheck()
          Called after checking the fields.
protected  void preCheck()
          Called before checking the fields.
 void readExternal(java.io.ObjectInput in)
           
 void set(FieldDescriptor field, java.lang.Object value)
          Low-level method to set an individual field value
protected abstract  void set(int i, java.lang.Object value)
           
 void set(java.lang.String fieldname, java.lang.Object value)
          Method to set the value of a field by name.
 void setMetadata(RecordDescriptor descriptor)
          Method only used internally.
 void setPrimaryKey(java.lang.Object o)
          set the value of this record's primary key.
 java.lang.String setValuesFromTable(java.util.Map table)
          Set the values of the record's fields from a key-value mapping of the fields (or field names) to values.
 java.lang.String toString()
          Provides a default string representation of the record for a human-readable flat-file persistence scheme.
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.oreodata.Record
isImmutable
 

Constructor Detail

AbstractRecord

public AbstractRecord()
Method Detail

checkValidity

public final void checkValidity()
                         throws DataException
Check if the record's data is valid.

Throws:
DataException - if any of the fields are not valid. The appropriate error message is encoded in the exception.

isStale

public boolean isStale()
Description copied from interface: Record
Has this record been deleted or superseded in the associated DataSource?

Specified by:
isStale in interface Record

getPrimaryKey

public java.lang.Object getPrimaryKey()
Description copied from interface: Record
Retrieve the value of the record's primary key.

Specified by:
getPrimaryKey in interface Record
Returns:
the value of this record's primary key, or null if it has not been set.

setPrimaryKey

public void setPrimaryKey(java.lang.Object o)
Description copied from interface: Record
set the value of this record's primary key. The record must be in a mutable state AND the primary key must be unset.

Specified by:
setPrimaryKey in interface Record

toString

public java.lang.String toString()
Provides a default string representation of the record for a human-readable flat-file persistence scheme.

Overrides:
toString in class java.lang.Object
Returns:
string of form field=value \n field=value \n\n

preCheck

protected void preCheck()
                 throws DataException
Called before checking the fields. Does nothing in the base implementation. Overriding this method allows you to apply certain (possibly ad hoc) fixups before doing any validity checks. Basically, this gives a class a chance to massage data that wouldn't pass the validity check.

DataException

postCheck

protected void postCheck()
                  throws DataException
Called after checking the fields. Does nothing in the base implementaiton. If you want more, possibly cross-field or cross-record validity checks, override this method and put the checks here. If the data flunks, throw the appropriate data-related exception.

DataException

freeze

public void freeze()
            throws DataException
Description copied from interface: Record
make this record immutable. This will typically only be called by an OreoDataSource object.

Specified by:
freeze in interface Record
DataException

setValuesFromTable

public java.lang.String setValuesFromTable(java.util.Map table)
                                    throws DataException
Set the values of the record's fields from a key-value mapping of the fields (or field names) to values.

Parameters:
table - key-value string pairs to set values of fields.
Returns:
a string representing the status info contained in the table if any, possibly null.
DataException

get

public final java.lang.Object get(java.lang.String fieldname)
Description copied from interface: Record
Method to get the value of a field by name. Subclasses may wrap this with a higher-level get/set API.

Specified by:
get in interface Record
Parameters:
fieldname -

get

public final java.lang.Object get(FieldDescriptor field)
Description copied from interface: Record
Low-level method to query the value of a field in a Record.

Specified by:
get in interface Record
Parameters:
field - to query.
Returns:
an Object wrapper around field value.

set

public final void set(java.lang.String fieldname,
                      java.lang.Object value)
Description copied from interface: Record
Method to set the value of a field by name. Concrete implementations may wrap this with a higher-level get/set API.

Specified by:
set in interface Record
Parameters:
fieldname - the name of the field to set.

set

public final void set(FieldDescriptor field,
                      java.lang.Object value)
Description copied from interface: Record
Low-level method to set an individual field value

Specified by:
set in interface Record
Parameters:
field - to set.
value - Object wrapping the value

getMetadata

public final RecordDescriptor getMetadata()
Specified by:
getMetadata in interface Record
Returns:
an object that describes the data held in this record.
See Also:
RecordDescriptor

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
java.io.IOException
java.lang.ClassNotFoundException

getParent

public Record getParent()
                 throws MissingContextException
In this base implementation, this always returns null.

Specified by:
getParent in interface Record
Returns:
the parent element or null if there is none.
MissingContextException

getChildren

public java.util.List getChildren()
                           throws MissingContextException
In this base implementation, this always returns an empty list.

Specified by:
getChildren in interface Record
Returns:
a List of children.
MissingContextException

isRootElement

public boolean isRootElement()
In this base implementation, this always returns true.

Specified by:
isRootElement in interface Record

hasChildren

public boolean hasChildren()
In this base implementation, this always returns false.

Specified by:
hasChildren in interface Record

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
java.io.IOException

getMutableCopy

public Record getMutableCopy()
create a clone. A shallow copy of the values array should be enough for immutable records Note that a newly cloned object has its immutable flag set to false, so that it is in a modifiable state.

Specified by:
getMutableCopy in interface Record

get

public java.lang.Object get(java.lang.Object o)

clearFields

public void clearFields()
set the fields to their default values.

Specified by:
clearFields in interface Record

equals

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

setMetadata

public void setMetadata(RecordDescriptor descriptor)
Description copied from interface: Record
Method only used internally.

Specified by:
setMetadata in interface Record

getType

public final java.lang.String getType()
Specified by:
getType in interface Record
Returns:
the name of this record type subclasses must implement this. e.g. "reminder"

get

protected abstract java.lang.Object get(int i)

set

protected abstract void set(int i,
                            java.lang.Object value)