org.codehaus.spice.converter
Class AbstractConverter

java.lang.Object
  |
  +--org.codehaus.spice.converter.AbstractConverter
All Implemented Interfaces:
Converter
Direct Known Subclasses:
ObjectToStringConverter, StringToBigDecimalConverter, StringToBigIntegerConverter, StringToBooleanConverter, StringToByteConverter, StringToClassConverter, StringToDateConverter, StringToDoubleConverter, StringToFileConverter, StringToFloatConverter, StringToIntegerConverter, StringToLongConverter, StringToShortConverter, StringToSQLDateConverter, StringToTimeConverter, StringToTimestampConverter, StringToURLConverter

public abstract class AbstractConverter
extends Object
implements Converter

Instances of this interface are used to convert between different types.

Version:
$Revision: 1.1 $ $Date: 2003/12/02 08:37:56 $
Author:
Peter Donald

Constructor Summary
protected AbstractConverter(Class source, Class destination)
          Constructor for a converter between types source and destination
protected AbstractConverter(Class source, Class destination, Object defaultValue)
          Constructor for a converter between types source and destination with a default value.
 
Method Summary
 Object convert(Class destination, Object original, Object context)
          Convert an object from original to destination types
protected abstract  Object convert(Object original, Object context)
          Overide this in a particular converter to do the conversion.
protected  Object noConvert(Object value, Throwable throwable)
          A helper method to throw an exception indicating that could not perform conversion of specified object due to an exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractConverter

protected AbstractConverter(Class source,
                            Class destination)
Constructor for a converter between types source and destination

Parameters:
source - the source type
destination - the destination type

AbstractConverter

protected AbstractConverter(Class source,
                            Class destination,
                            Object defaultValue)
Constructor for a converter between types source and destination with a default value.

Parameters:
source - the source type
destination - the destination type
defaultValue - the default value
Method Detail

convert

public Object convert(Class destination,
                      Object original,
                      Object context)
               throws ConverterException
Convert an object from original to destination types

Specified by:
convert in interface Converter
Parameters:
destination - the destination type
original - the original Object
context - the context in which to convert
Returns:
the converted object
Throws:
ConverterException - if an error occurs

noConvert

protected final Object noConvert(Object value,
                                 Throwable throwable)
                          throws ConverterException
A helper method to throw an exception indicating that could not perform conversion of specified object due to an exception.

ConverterException

convert

protected abstract Object convert(Object original,
                                  Object context)
                           throws ConverterException
Overide this in a particular converter to do the conversion.

Parameters:
original - the original Object
context - the context in which to convert
Returns:
the converted object
Throws:
ConverterException - if an error occurs


Copyright © 2000-2003 Codehaus. All Rights Reserved.