Expresso 5-5-0

com.jcorporate.expresso.core.dataobjects
Class DefaultDataField

java.lang.Object
  extended bycom.jcorporate.expresso.core.dataobjects.DefaultDataField
All Implemented Interfaces:
DataField, Serializable

public class DefaultDataField
extends Object
implements DataField, Serializable

Default implementation of the DataField interface. This class provides some basic conversion capabilities between different Java types as well as provides all use change logging capabilities.

Since:
Expresso 5.0
Author:
Michael Rimov
See Also:
Serialized Form

Field Summary
static String ATTRIBUTE_ERROR
          Attribute String for if there's an error with the field.
static String ATTRIBUTE_ERROR_MESSAGE
          Attribute String for what message to display if there's an error with thie field.
protected  Map attributes
          A generic map of attribute keys to attribute values
protected  Object currentValue
          The Current Value
protected  boolean isChanged
          Flag to signify if the field is changed
protected  boolean isValueSet
          Flag to signify if the field value has been set - the retrieved value may be null
protected  DataFieldMetaData myMetaData
          A link to my metadata.
protected  Object originalValue
          The very first original value... set if the field is changed so we know what's changed
protected  DataObject owner
          A link to the DataObject that contains me.
 
Constructor Summary
protected DefaultDataField(DataFieldMetaData metaData, DataObject parentObject)
          Creates a new DefaultDataField object.
 
Method Summary
 BigDecimal asBigDecimal()
          Retrieve the wrapped object as a BigDecimal object or zero if we're unable to convert it.
 Boolean asBoolean()
          Retrieve the boolean object value.
 Date asDate()
          Retrieve the wrapped object as a Date object or possibly null if we can't convert it or the object is null.
 Double asDouble()
          Retrieve the wrapped object as a Double object or zero if we can't convert i
 Integer asInteger()
          Retrieves the wrapped object as an Integer or zero if it's an invalid format.
 InputStream asStream()
          Retrieve the field as a InputStream.
 String asString()
          Retrieves the wrapped object as a String
 void checkValue()
          Make sure the value of the field is valid.
 Map getAllAttributes()
          Returns a Read Only Map of all attributes in name-value pairs.
 Object getAttribute(String attributeName)
          Retrieves any user defined attributes for this field.
protected  String getBooleanFieldValue(Boolean theFieldValue)
          Internal refactoring for getting what a boolean field should be set to.
 DataFieldMetaData getFieldMetaData()
          Returns a handle to the Field MetaData object.
static DefaultDataField getInstance(DataFieldMetaData metaData, DataObject parentObject)
          DOCUMENT ME!
 Object getOriginalValue()
          Retrieve the last original value if the data has changed.
 DataObject getOwner()
          Returns a handle to the DataObject that is the container for this Data Field
protected  org.apache.oro.text.regex.PatternMatcher getPatternMatcher()
          Retrieve a thread local instance of the Perl5 pattern matcher.
 Object getSerializedForm()
          Returns the form in a way suitable for storage in a database or other data source.
 Object getValue()
          DOCUMENT ME!
 boolean isChanged()
          Used for change logging and updating only changed fields. change is true IF the field has been set once (after object is born or reset), and subsequently the value is changed in the field.
 boolean isNull()
          Returns true if the object is null.
 boolean isValueSet()
          Used for change logging.
 void release()
          DOCUMENT ME!
 void removeAttribute(String attribute)
          Removes an attribute
 void resetChanged()
          Resets the changed flag and sets the original value field to null
 void setAttribute(String attributeName, Object value)
          Sets an attribute for this particular instance of the Data field
 void setFieldMetaData(DataFieldMetaData newMetadata)
          Sets the metadata object for this field.
 void setOwner(DataObject newOwner)
          Sets the owner of a given DataObject
 void setSerializedForm(Object o)
          Used for setting raw data from a JDBC connection.
 void setValue(Object newValue)
          Sets the wrapped object for the data field
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTRIBUTE_ERROR

public static final String ATTRIBUTE_ERROR
Attribute String for if there's an error with the field.

See Also:
Constant Field Values

ATTRIBUTE_ERROR_MESSAGE

public static final String ATTRIBUTE_ERROR_MESSAGE
Attribute String for what message to display if there's an error with thie field.

See Also:
Constant Field Values

myMetaData

protected transient DataFieldMetaData myMetaData
A link to my metadata.


owner

protected transient DataObject owner
A link to the DataObject that contains me.


attributes

protected Map attributes
A generic map of attribute keys to attribute values


currentValue

protected Object currentValue
The Current Value


originalValue

protected Object originalValue
The very first original value... set if the field is changed so we know what's changed


isChanged

protected boolean isChanged
Flag to signify if the field is changed


isValueSet

protected boolean isValueSet
Flag to signify if the field value has been set - the retrieved value may be null

Constructor Detail

DefaultDataField

protected DefaultDataField(DataFieldMetaData metaData,
                           DataObject parentObject)
Creates a new DefaultDataField object.

Parameters:
metaData - DOCUMENT ME!
parentObject - DOCUMENT ME!
Method Detail

getInstance

public static DefaultDataField getInstance(DataFieldMetaData metaData,
                                           DataObject parentObject)
DOCUMENT ME!

Parameters:
metaData - DOCUMENT ME!
parentObject - DOCUMENT ME!
Returns:
DOCUMENT ME!

getAllAttributes

public Map getAllAttributes()
Returns a Read Only Map of all attributes in name-value pairs. If there are no attributes then getAllAttributes will return a null map.

Specified by:
getAllAttributes in interface DataField
Returns:
java.util.map

setAttribute

public void setAttribute(String attributeName,
                         Object value)
Sets an attribute for this particular instance of the Data field

Specified by:
setAttribute in interface DataField
Parameters:
attributeName - the name of the attribute to set
value - the value to set it to

getAttribute

public Object getAttribute(String attributeName)
Retrieves any user defined attributes for this field.

Specified by:
getAttribute in interface DataField
Parameters:
attributeName - the name of the attribute to retrieve
Returns:
an object or null if the attribute doesn't exist

isChanged

public boolean isChanged()
Used for change logging and updating only changed fields. change is true IF the field has been set once (after object is born or reset), and subsequently the value is changed in the field.

Specified by:
isChanged in interface DataField
Returns:
true if the field has changed since the last reset (i.e. since object was constructed or reset)

setFieldMetaData

public void setFieldMetaData(DataFieldMetaData newMetadata)
Sets the metadata object for this field.

Specified by:
setFieldMetaData in interface DataField
Parameters:
newMetadata - the new Field Meta data object... for example DBField

getFieldMetaData

public DataFieldMetaData getFieldMetaData()
Returns a handle to the Field MetaData object.

Specified by:
getFieldMetaData in interface DataField
Returns:
DataFieldMetaData

isNull

public boolean isNull()
Returns true if the object is null.

Specified by:
isNull in interface DataField
Returns:
true if the object is null

getOriginalValue

public Object getOriginalValue()
Retrieve the last original value if the data has changed. Will return null if isChanged() is false

Specified by:
getOriginalValue in interface DataField
Returns:
the original object or null

setOwner

public void setOwner(DataObject newOwner)
Sets the owner of a given DataObject

Specified by:
setOwner in interface DataField
Parameters:
newOwner - The new parent object.

getOwner

public DataObject getOwner()
Returns a handle to the DataObject that is the container for this Data Field

Specified by:
getOwner in interface DataField
Returns:
DataObject the containing data object.

setSerializedForm

public void setSerializedForm(Object o)
Used for setting raw data from a JDBC connection. Allows for special processing such as decryption.

Parameters:
o - the object to set.

getSerializedForm

public Object getSerializedForm()
                         throws DataException
Returns the form in a way suitable for storage in a database or other data source.

Returns:
java.lang.Object
Throws:
DataException - upon error

setValue

public void setValue(Object newValue)
Sets the wrapped object for the data field

Specified by:
setValue in interface DataField
Parameters:
newValue - a new Object to set the value to

getValue

public Object getValue()
DOCUMENT ME!

Specified by:
getValue in interface DataField
Returns:
DOCUMENT ME!

isValueSet

public boolean isValueSet()
Used for change logging.

Specified by:
isValueSet in interface DataField
Returns:
true if the field has had the value set since the last reset

asBigDecimal

public BigDecimal asBigDecimal()
Retrieve the wrapped object as a BigDecimal object or zero if we're unable to convert it.

Specified by:
asBigDecimal in interface DataField
Returns:
a properly instantiated BigDecimal Object if we're able to convert it.

asBoolean

public Boolean asBoolean()
Retrieve the boolean object value.

Specified by:
asBoolean in interface DataField
Returns:
Boolean object. Null if the object's value is null

asDate

public Date asDate()
Retrieve the wrapped object as a Date object or possibly null if we can't convert it or the object is null.

Specified by:
asDate in interface DataField
Returns:
a properly instantiated Date Object if we're able to convert it.

asDouble

public Double asDouble()
Retrieve the wrapped object as a Double object or zero if we can't convert i

Specified by:
asDouble in interface DataField
Returns:
a properly instantiated Double Object if we're able to convert it.

asInteger

public Integer asInteger()
Retrieves the wrapped object as an Integer or zero if it's an invalid format.

Specified by:
asInteger in interface DataField
Returns:
a java.lang.Integer object, or null if the object is null.

asStream

public InputStream asStream()
Retrieve the field as a InputStream. If the object's native type is an input stream, it returns that. If it is a serializable object, it returns a ByteArrayInputStream that was created using a ByteArrayOutputStream as well as a ObjectOutputStream.

Specified by:
asStream in interface DataField
Returns:
java.io.InputSTream or null if there was an IO Exception getting the value, the value was null, of if the native object is not serializable

asString

public String asString()
Retrieves the wrapped object as a String

Specified by:
asString in interface DataField
Returns:
a String value representing the object as a string

checkValue

public void checkValue()
                throws DataException
Make sure the value of the field is valid. Checks mask and for null.

Specified by:
checkValue in interface DataField
Throws:
DataException - if the field value is not valid

release

public void release()
DOCUMENT ME!


removeAttribute

public void removeAttribute(String attribute)
Removes an attribute

Parameters:
attribute - The attribute key to remove

resetChanged

public void resetChanged()
Resets the changed flag and sets the original value field to null

Specified by:
resetChanged in interface DataField

getBooleanFieldValue

protected String getBooleanFieldValue(Boolean theFieldValue)
Internal refactoring for getting what a boolean field should be set to.

Parameters:
theFieldValue - The target value
Returns:
the string value
Throws:
IllegalArgumentException - If we can't get the data context

getPatternMatcher

protected org.apache.oro.text.regex.PatternMatcher getPatternMatcher()
Retrieve a thread local instance of the Perl5 pattern matcher. Allows for optimization of # of instances of pattern matcher vs synchronization.

Returns:
PatternMatcher

Expresso 5-5-0

Please see www.jcorporate.com for information about new Expresso releases.