org.apache.camel.support
Class TypeConverterSupport

java.lang.Object
  extended by org.apache.camel.support.TypeConverterSupport
All Implemented Interfaces:
TypeConverter
Direct Known Subclasses:
ArrayTypeConverter, AsyncProcessorTypeConverter, EnumTypeConverter, FutureTypeConverter, InstanceMethodFallbackTypeConverter, InstanceMethodTypeConverter, StaticMethodFallbackTypeConverter, StaticMethodTypeConverter, ToStringTypeConverter

public abstract class TypeConverterSupport
extends Object
implements TypeConverter

Base class for TypeConverter implementations.

Implementators need only to implement the TypeConverter.convertTo(Class, org.apache.camel.Exchange, Object) method, and can rely on the default implementations of the other methods from this support class.


Constructor Summary
TypeConverterSupport()
           
 
Method Summary
<T> T
convertTo(Class<T> type, Object value)
          Converts the value to the specified type
<T> T
mandatoryConvertTo(Class<T> type, Exchange exchange, Object value)
          Converts the value to the specified type in the context of an exchange

Used when conversion requires extra information from the current exchange (such as encoding).

<T> T
mandatoryConvertTo(Class<T> type, Object value)
          Converts the value to the specified type
<T> T
tryConvertTo(Class<T> type, Exchange exchange, Object value)
          Tries to convert the value to the specified type in the context of an exchange, returning null if not possible to convert.
<T> T
tryConvertTo(Class<T> type, Object value)
          Tries to convert the value to the specified type, returning null if not possible to convert.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.camel.TypeConverter
convertTo
 

Constructor Detail

TypeConverterSupport

public TypeConverterSupport()
Method Detail

convertTo

public <T> T convertTo(Class<T> type,
                       Object value)
            throws TypeConversionException
Description copied from interface: TypeConverter
Converts the value to the specified type

Specified by:
convertTo in interface TypeConverter
Parameters:
type - the requested type
value - the value to be converted
Returns:
the converted value, or null if not possible to convert
Throws:
TypeConversionException - is thrown if error during type conversion

mandatoryConvertTo

public <T> T mandatoryConvertTo(Class<T> type,
                                Object value)
                     throws TypeConversionException,
                            NoTypeConversionAvailableException
Description copied from interface: TypeConverter
Converts the value to the specified type

Specified by:
mandatoryConvertTo in interface TypeConverter
Parameters:
type - the requested type
value - the value to be converted
Returns:
the converted value, is never null
Throws:
TypeConversionException - is thrown if error during type conversion
NoTypeConversionAvailableException

mandatoryConvertTo

public <T> T mandatoryConvertTo(Class<T> type,
                                Exchange exchange,
                                Object value)
                     throws TypeConversionException,
                            NoTypeConversionAvailableException
Description copied from interface: TypeConverter
Converts the value to the specified type in the context of an exchange

Used when conversion requires extra information from the current exchange (such as encoding).

Specified by:
mandatoryConvertTo in interface TypeConverter
Parameters:
type - the requested type
exchange - the current exchange
value - the value to be converted
Returns:
the converted value, is never null
Throws:
TypeConversionException - is thrown if error during type conversion
NoTypeConversionAvailableException

tryConvertTo

public <T> T tryConvertTo(Class<T> type,
                          Object value)
Description copied from interface: TypeConverter
Tries to convert the value to the specified type, returning null if not possible to convert.

This method will not throw an exception if an exception occurred during conversion.

Specified by:
tryConvertTo in interface TypeConverter
Parameters:
type - the requested type
value - the value to be converted
Returns:
the converted value, or null if not possible to convert

tryConvertTo

public <T> T tryConvertTo(Class<T> type,
                          Exchange exchange,
                          Object value)
Description copied from interface: TypeConverter
Tries to convert the value to the specified type in the context of an exchange, returning null if not possible to convert.

This method will not throw an exception if an exception occurred during conversion. Converts the value to the specified type in the context of an exchange

Used when conversion requires extra information from the current exchange (such as encoding).

Specified by:
tryConvertTo in interface TypeConverter
Parameters:
type - the requested type
exchange - the current exchange
value - the value to be converted
Returns:
the converted value, or null if not possible to convert


Apache CAMEL