org.oreodata.metadata
Class Field

java.lang.Object
  |
  +--org.oreodata.metadata.Field
All Implemented Interfaces:
FieldDescriptor, java.io.Serializable
Direct Known Subclasses:
BooleanField, DateField, ForeignKeyField, LocaleField, NumericalField, StringField, TimeZoneField

public abstract class Field
extends java.lang.Object
implements FieldDescriptor

abstract base class for objects that represent the metadata relating to a record field. This object knows how to set itself up from a DOM element.

Author:
Serialized Form

Field Summary
protected  java.lang.String defaultValueString
           
protected  boolean intern
           
protected  java.util.Properties properties
           
protected  java.lang.String sqlType
           
 
Constructor Summary
Field()
           
 
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 o)
          Method to support slurping records from a JDBC result set.
 java.lang.Object convertToJDBC(java.lang.Object o)
          Method to support persisting records to a JDBC record set.
 HierarchicalHandler createSAXHandler(HierarchicalHandler parent, Record rec)
           
 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.String getProperty(java.lang.String propertyName)
          a hook so that implementors can add other properties
 java.lang.String getSQLType()
           
 int hashCode()
           
protected  void init(org.w3c.dom.Element element)
           
protected  java.lang.Object intern(java.lang.Object o)
           
 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.
protected  void processDefaultValue()
           
protected  void processNormalization(org.w3c.dom.Element elem)
           
protected  void processProperties()
           
protected  void setDefaultValue(java.lang.Object o)
           
 java.lang.String toString()
           
 java.lang.String valueToString(java.lang.Object val)
          returns the preferred String representation of the object in question.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.oreodata.FieldDescriptor
getObjectFromString
 

Field Detail

sqlType

protected java.lang.String sqlType

defaultValueString

protected java.lang.String defaultValueString

properties

protected java.util.Properties properties

intern

protected boolean intern
Constructor Detail

Field

public Field()
Method Detail

init

protected void init(org.w3c.dom.Element element)
             throws org.xml.sax.SAXException
org.xml.sax.SAXException

processDefaultValue

protected void processDefaultValue()
                            throws java.io.IOException
java.io.IOException

processProperties

protected void processProperties()
                          throws org.xml.sax.SAXException
org.xml.sax.SAXException

processNormalization

protected void processNormalization(org.w3c.dom.Element elem)

getCopy

public java.lang.Object getCopy(java.lang.Object o)
Description copied from interface: FieldDescriptor
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.

Specified by:
getCopy in interface FieldDescriptor
Returns:
a copy of the object in question.

getName

public final java.lang.String getName()
Description copied from interface: FieldDescriptor
A unique name that identifies the field

Specified by:
getName in interface FieldDescriptor

toString

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

hashCode

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

isRequired

public boolean isRequired()
Description copied from interface: FieldDescriptor
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.

Specified by:
isRequired in interface FieldDescriptor

valueToString

public java.lang.String valueToString(java.lang.Object val)
Description copied from interface: FieldDescriptor
returns the preferred String representation of the object in question. Used to persist to a flat file.

Specified by:
valueToString in interface FieldDescriptor

getJavaType

public java.lang.Class getJavaType()
Description copied from interface: FieldDescriptor
The kind of java object that can live in this record field.

Specified by:
getJavaType in interface FieldDescriptor

getSQLType

public java.lang.String getSQLType()
Specified by:
getSQLType in interface FieldDescriptor
Returns:
the name of this type in SQL

checkValidValue

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

Specified by:
checkValidValue in interface FieldDescriptor
DataException

isFieldOf

public final boolean isFieldOf(Record rec)
Description copied from interface: FieldDescriptor
Does this FieldDescriptor describe a field of the Record? Useful for sanity checks.

Specified by:
isFieldOf in interface FieldDescriptor

defaultValue

public java.lang.Object defaultValue()
Description copied from interface: FieldDescriptor
returns this field's "default value". By default, this will be null.

Specified by:
defaultValue in interface FieldDescriptor

getLocalizedName

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

setDefaultValue

protected void setDefaultValue(java.lang.Object o)

normalize

public java.lang.String normalize(java.lang.String s)
Description copied from interface: FieldDescriptor
"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.)

Specified by:
normalize in interface FieldDescriptor
Returns:
the "normalized" string

convertFromJDBC

public java.lang.Object convertFromJDBC(java.lang.Object o)
Description copied from interface: FieldDescriptor
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.

Specified by:
convertFromJDBC in interface FieldDescriptor

convertToJDBC

public java.lang.Object convertToJDBC(java.lang.Object o)
Description copied from interface: FieldDescriptor
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.

Specified by:
convertToJDBC in interface FieldDescriptor

getProperty

public java.lang.String getProperty(java.lang.String propertyName)
Description copied from interface: FieldDescriptor
a hook so that implementors can add other properties

Specified by:
getProperty in interface FieldDescriptor

createSAXHandler

public HierarchicalHandler createSAXHandler(HierarchicalHandler parent,
                                            Record rec)
Specified by:
createSAXHandler in interface FieldDescriptor

isSetExternally

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

intern

protected java.lang.Object intern(java.lang.Object o)