org.apache.commons.betwixt.strategy
Class DefaultObjectStringConverter

java.lang.Object
  extended by org.apache.commons.betwixt.strategy.ObjectStringConverter
      extended by org.apache.commons.betwixt.strategy.ConvertUtilsObjectStringConverter
          extended by org.apache.commons.betwixt.strategy.DefaultObjectStringConverter
All Implemented Interfaces:
java.io.Serializable

public class DefaultObjectStringConverter
extends ConvertUtilsObjectStringConverter

Default string <-> object conversion strategy.

This delegates to ConvertUtils except when the type is assignable from java.util.Date but not from java.sql.Date. In this case, the format used is (in SimpleDateFormat terms) EEE MMM dd HH:mm:ss zzz yyyy. This is the same as the output of the toString method on java.util.Date.

This should preserve the existing symantic behaviour whilst allowing round tripping of dates (given the default settings).

Since:
0.5
Author:
Robert Burrell Donkin
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.commons.betwixt.strategy.ObjectStringConverter
FLAVOUR_OPTION_NAME
 
Constructor Summary
DefaultObjectStringConverter()
           
 
Method Summary
protected  void handleException(java.lang.Exception e)
          Allow subclasses to use a different exception handling strategy.
 java.lang.String objectToString(java.lang.Object object, java.lang.Class type, java.lang.String flavour, Context context)
          Converts an object to a string representation using ConvertUtils.
 java.lang.Object stringToObject(java.lang.String value, java.lang.Class type, java.lang.String flavour, Context context)
          Converts an object to a string representation using ConvertUtils.
 
Methods inherited from class org.apache.commons.betwixt.strategy.ObjectStringConverter
objectToString, stringToObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultObjectStringConverter

public DefaultObjectStringConverter()
Method Detail

objectToString

public java.lang.String objectToString(java.lang.Object object,
                                       java.lang.Class type,
                                       java.lang.String flavour,
                                       Context context)
Converts an object to a string representation using ConvertUtils. If the object is a java.util.Date and the type is java.util.Date but not java.sql.Date then SimpleDateFormat formatting to EEE MMM dd HH:mm:ss zzz yyyy will be used. (This is the same as java.util.Date toString would return.)

Overrides:
objectToString in class ConvertUtilsObjectStringConverter
Parameters:
object - the object to be converted, possibly null
type - the property class of the object, not null
flavour - a string allow symantic differences in formatting to be communicated (ignored)
context - convert against this context not null
Returns:
a String representation, not null

stringToObject

public java.lang.Object stringToObject(java.lang.String value,
                                       java.lang.Class type,
                                       java.lang.String flavour,
                                       Context context)
Converts an object to a string representation using ConvertUtils.

Overrides:
stringToObject in class ConvertUtilsObjectStringConverter
Parameters:
value - the String to be converted, not null
type - the property class to be returned (if possible), not null
flavour - a string allow symantic differences in formatting to be communicated (ignored)
context - not null
Returns:
an Object converted from the String, not null

handleException

protected void handleException(java.lang.Exception e)
Allow subclasses to use a different exception handling strategy. This class throws a org.apache.commons.beanutils.ConversionException when conversion fails.

Parameters:
e - the Exception to be handled
Throws:
org.apache.commons.beanutils.ConversionException - when conversion fails


Copyright 2002-2008 The Apache Software Foundation. All Rights Reserved.