org.springframework.binding.convert.support
Class AbstractConverter

java.lang.Object
  extended by org.springframework.binding.convert.support.AbstractConverter
All Implemented Interfaces:
Converter
Direct Known Subclasses:
AbstractFormattingConverter, ConversionServiceAwareConverter, TextToBoolean, TextToExpression, TextToLabeledEnum

public abstract class AbstractConverter
extends java.lang.Object
implements Converter

Base class for converters provided as a convenience to implementors.

Author:
Keith Donald

Constructor Summary
AbstractConverter()
           
 
Method Summary
 java.lang.Object convert(java.lang.Object source)
          Convenience convert method that converts the provided source to the first target object supported by this converter.
 java.lang.Object convert(java.lang.Object source, java.lang.Class targetClass)
          Convenience convert method that converts the provided source to the target class specified with an empty conversion context.
 java.lang.Object convert(java.lang.Object source, java.lang.Class targetClass, ConversionContext context)
          Convert the provided source object argument to an instance of the specified target class.
 java.lang.Object convert(java.lang.Object source, ConversionContext context)
          Convenience convert method that converts the provided source to the first target object supported by this converter.
protected abstract  java.lang.Object doConvert(java.lang.Object source, java.lang.Class targetClass, ConversionContext context)
          Template method subclasses should override to actually perform the type conversion.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.binding.convert.Converter
getSourceClasses, getTargetClasses
 

Constructor Detail

AbstractConverter

public AbstractConverter()
Method Detail

convert

public java.lang.Object convert(java.lang.Object source)
                         throws ConversionException
Convenience convert method that converts the provided source to the first target object supported by this converter. Useful when a converter only supports conversion to a single target.

Parameters:
source - the source to convert
Returns:
the converted object
Throws:
ConversionException - an exception occured converting the source value

convert

public java.lang.Object convert(java.lang.Object source,
                                java.lang.Class targetClass)
                         throws ConversionException
Convenience convert method that converts the provided source to the target class specified with an empty conversion context.

Parameters:
source - the source to convert
targetClass - the target class to convert the source to, must be one of the supported targetClasses
Returns:
the converted object
Throws:
ConversionException - an exception occured converting the source value

convert

public java.lang.Object convert(java.lang.Object source,
                                ConversionContext context)
                         throws ConversionException
Convenience convert method that converts the provided source to the first target object supported by this converter. Useful when a converter only supports conversion to a single target.

Parameters:
source - the source to convert
context - the conversion context, useful for influencing the behavior of the converter
Returns:
the converted object
Throws:
ConversionException - an exception occured converting the source value

convert

public java.lang.Object convert(java.lang.Object source,
                                java.lang.Class targetClass,
                                ConversionContext context)
                         throws ConversionException
Description copied from interface: Converter
Convert the provided source object argument to an instance of the specified target class.

Specified by:
convert in interface Converter
Parameters:
source - the source object to convert, its class must be one of the supported sourceClasses
targetClass - the target class to convert the source to, must be one of the supported targetClasses
context - an optional conversion context that may be used to influence the conversion process
Returns:
the converted object, an instance of the target type
Throws:
ConversionException - an exception occured during the conversion

doConvert

protected abstract java.lang.Object doConvert(java.lang.Object source,
                                              java.lang.Class targetClass,
                                              ConversionContext context)
                                       throws java.lang.Exception
Template method subclasses should override to actually perform the type conversion.

Parameters:
source - the source to convert from
targetClass - the target type to convert to
context - an optional conversion context that may be used to influence the conversion process, could be null
Returns:
the converted source value
Throws:
java.lang.Exception - an exception occured, will be wrapped in a conversion exception if necessary


Copyright � 2004-2007. All Rights Reserved.