org.oreodata
Interface FieldDescriptor

All Superinterfaces:
java.io.Serializable
All Known Subinterfaces:
ForeignKeyDescriptor
All Known Implementing Classes:
Field, ForeignKeyField

public interface FieldDescriptor
extends java.io.Serializable

An interface implemented by objects that describe the constraints on the field of an Oreo data record.

Author:
Jonathan Revusky

Method Summary
 void checkValidValue(Record rec, java.lang.Object o)
          Check whether this object is a valid value for this field of the given record.
 java.lang.Object convertFromJDBC(java.lang.Object obj)
          Method to support slurping records from a JDBC result set.
 java.lang.Object convertToJDBC(java.lang.Object obj)
          Method to support persisting records to a JDBC record set.
 HierarchicalHandler createSAXHandler(HierarchicalHandler parent, Record record)
           
 java.lang.Object defaultValue()
          returns this field's "default value".
 java.lang.Object getCopy(java.lang.Object o)
          Used when encapsulation requires Record::get() to return a clone of an object.
 java.lang.Class getJavaType()
          The kind of java object that can live in this record field.
 java.lang.String getLocalizedName(java.util.Locale locale)
           
 java.lang.String getName()
          A unique name that identifies the field
 java.lang.Object getObjectFromString(Record rec, java.lang.String s)
          Given the string representation of a field, return its internal java object representation.
 java.lang.String getProperty(java.lang.String propertyName)
          a hook so that implementors can add other properties
 java.lang.String getSQLType()
           
 boolean isFieldOf(Record rec)
          Does this FieldDescriptor describe a field of the Record? Useful for sanity checks.
 boolean isRequired()
          Used in the core validity checks.
 boolean isSetExternally()
           
 java.lang.String normalize(java.lang.String s)
          "normalize" the string passed in.
 java.lang.String valueToString(java.lang.Object o)
          returns the preferred String representation of the object in question.
 

Method Detail

getName

public java.lang.String getName()
A unique name that identifies the field


getJavaType

public java.lang.Class getJavaType()
The kind of java object that can live in this record field.


getSQLType

public java.lang.String getSQLType()
Returns:
the name of this type in SQL
Throws:
java.lang.UnsupportedOperationException

getLocalizedName

public java.lang.String getLocalizedName(java.util.Locale locale)
Returns:
the localized name of this field, used for localized error messages.

isRequired

public boolean isRequired()
Used in the core validity checks. Basically, this answers the question of whether a null (or the empty string in the case of a String field) is an acceptable value for the field.


getObjectFromString

public java.lang.Object getObjectFromString(Record rec,
                                            java.lang.String s)
                                     throws DataException
Given the string representation of a field, return its internal java object representation. Used in deserializing from a flat file.

DataException

valueToString

public java.lang.String valueToString(java.lang.Object o)
                               throws DataException
returns the preferred String representation of the object in question. Used to persist to a flat file.

DataException

getCopy

public java.lang.Object getCopy(java.lang.Object o)
Used when encapsulation requires Record::get() to return a clone of an object. In the case of immutable objects such as java.lang.String, getCopy() can just return the object passed in as a parameter.

Returns:
a copy of the object in question.

normalize

public java.lang.String normalize(java.lang.String s)
"normalize" the string passed in. For example, with a case-insensitive string field, this method would return the lower case version of the string (or upper case if that is the "normal" form.)

Returns:
the "normalized" string

checkValidValue

public void checkValidValue(Record rec,
                            java.lang.Object o)
                     throws DataException
Check whether this object is a valid value for this field of the given record. Used in the core validity checks.

Throws:
IOException - Description of Exception
DataException

isFieldOf

public boolean isFieldOf(Record rec)
Does this FieldDescriptor describe a field of the Record? Useful for sanity checks.


defaultValue

public java.lang.Object defaultValue()
returns this field's "default value". By default, this will be null.


convertFromJDBC

public java.lang.Object convertFromJDBC(java.lang.Object obj)
Method to support slurping records from a JDBC result set. Takes the result of a ResultSet.getObject() and converts it to the JavaObject type we use. In many cases, for strings and numbers, we should get away with this just being a pass-through.


convertToJDBC

public java.lang.Object convertToJDBC(java.lang.Object obj)
Method to support persisting records to a JDBC record set. Takes the result returned by this method and passes it to PreparedStatement.setObject(). In many cases, for strings and numbers, we should get away with this just being a pass-through.


createSAXHandler

public HierarchicalHandler createSAXHandler(HierarchicalHandler parent,
                                            Record record)

getProperty

public java.lang.String getProperty(java.lang.String propertyName)
a hook so that implementors can add other properties


isSetExternally

public boolean isSetExternally()
Returns:
whether the value of this field is set by an external database.