org.apache.commons.betwixt.strategy
Class ObjectStringConverter

java.lang.Object
  |
  +--org.apache.commons.betwixt.strategy.ObjectStringConverter
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ConvertUtilsObjectStringConverter

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

Strategy class for string <-> object conversions. Implementations of this interface are used by Betwixt to perform string <-> object conversions. This performs only the most basic conversions. Most applications will use a subclass.

It is strongly recommended that (in order to support round tripping) that objectToString and stringToObject are inverse functions. In other words, given the same flavour, context and type the applying objectToString to the result of stringToObject should be equal to the original input.

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

Constructor Summary
ObjectStringConverter()
           
 
Method Summary
 java.lang.String objectToString(java.lang.Object object, java.lang.Class type, java.lang.String flavour, org.apache.commons.betwixt.expression.Context context)
          Converts an object to a string representation.
 java.lang.Object stringToObject(java.lang.String value, java.lang.Class type, java.lang.String flavour, org.apache.commons.betwixt.expression.Context context)
          Converts a string representation to an object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectStringConverter

public ObjectStringConverter()
Method Detail

objectToString

public java.lang.String objectToString(java.lang.Object object,
                                       java.lang.Class type,
                                       java.lang.String flavour,
                                       org.apache.commons.betwixt.expression.Context context)
Converts an object to a string representation. This basic implementation returns object.toString() or an empty string if the given object is null.

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
context - the 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,
                                       org.apache.commons.betwixt.expression.Context context)
Converts a string representation to an object. It is acceptable for an implementation to return the string if it cannot convert the string to the given class type. This basic implementation just returns a string.

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


Copyright © 2002-2004 The Apache Software Foundation. All Rights Reserved.