com.ivata.mask.field
Class FieldValueConvertor

java.lang.Object
  extended bycom.ivata.mask.field.FieldValueConvertor
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ClassFieldValueConvertor, DateFieldValueConvertor, NumberFieldValueConvertor, ValueObjectFieldValueConvertor

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

Retrieve the value from a value object for a given field.

Since:
ivata masks 0.1 (2004-05-14)
Version:
$Revision: 1.7 $
Author:
Colin MacLeod colin.macleod@ivata.com
See Also:
Serialized Form

Nested Class Summary
static class FieldValueConvertor.FieldValueException
           Wraps any error encountered when trying retrieve a field value via reflection.
 
Constructor Summary
FieldValueConvertor()
           
 
Method Summary
 java.lang.Object convertFromString(java.lang.Class propertyClassParam, java.lang.String stringValue)
           Convert a value from a string.
protected  java.lang.Object getObjectValue(java.lang.Object object, java.lang.String propertyName, java.lang.Object defaultValue)
           Get the value of a named property within an object.
 java.lang.String getStringValue(java.lang.Object object, java.lang.String propertyName, java.lang.String defaultValue)
           Get the value of the field provided, in the value object supplied, and return the string equivalent.
 ValidationErrors setStringValue(java.lang.Object object, Field field, java.lang.String stringValue)
           Set the value of the field provided, in the value object supplied.
protected  java.lang.String toString(java.lang.Object objectValue)
           Convert a field object value into a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FieldValueConvertor

public FieldValueConvertor()
Method Detail

convertFromString

public java.lang.Object convertFromString(java.lang.Class propertyClassParam,
                                          java.lang.String stringValue)

Convert a value from a string. Override this method to choose how your class converts string values to your object class values.

This implementation attempts to instantiate an object of the desired class by locating a constructor which takes a single string as an argument.

Parameters:
propertyClassParam - exact class to be converted to.
stringValue - value to be converted.
Returns:
valid object value converted from a string.

getObjectValue

protected final java.lang.Object getObjectValue(java.lang.Object object,
                                                java.lang.String propertyName,
                                                java.lang.Object defaultValue)

Get the value of a named property within an object.

Parameters:
object - POJO for which to return the field value.
propertyName - name of the property/field to return the value for.
defaultValue - value to use if none is set.
Returns:
the value of the named property.

getStringValue

public final java.lang.String getStringValue(java.lang.Object object,
                                             java.lang.String propertyName,
                                             java.lang.String defaultValue)

Get the value of the field provided, in the value object supplied, and return the string equivalent.

Parameters:
object - POJO for which to return the field value.
propertyName - name of the property/field to return the value for.
defaultValue - value to use if none is set.
Returns:
the value of the named property, as a string.

setStringValue

public final ValidationErrors setStringValue(java.lang.Object object,
                                             Field field,
                                             java.lang.String stringValue)

Set the value of the field provided, in the value object supplied.

This implementation attempts to instantiate an object of the desired class by locating a constructor which takes a single string as an argument.

Parameters:
object - POJO for which to set the field value.
field - field to be set.
stringValue - new string equivalent value of this field.
Returns:
errors, if there are any errors with the field values, otherwise an empty collection.

toString

protected java.lang.String toString(java.lang.Object objectValue)

Convert a field object value into a string. Override this method to convert for a specific type.

Parameters:
objectValue - object to be converted.
Returns:
string equivalent.


Copyright © 2001-2005 ivata limited. All Rights Reserved.