org.apache.camel.impl.converter
Class DefaultTypeConverter

java.lang.Object
  extended by org.apache.camel.impl.converter.DefaultTypeConverter
All Implemented Interfaces:
TypeConverterRegistry, TypeConverter

public class DefaultTypeConverter
extends Object
implements TypeConverter, TypeConverterRegistry

Default implementation of a type converter registry used for type converters in Camel.

Version:
$Revision: 772598 $

Nested Class Summary
protected static class DefaultTypeConverter.TypeMapping
          Represents a mapping from one type (which can be null) to another
 
Constructor Summary
DefaultTypeConverter(PackageScanClassResolver resolver, Injector injector, FactoryFinder factoryFinder)
           
 
Method Summary
 void addFallbackTypeConverter(TypeConverter typeConverter)
          Registers a new fallback type converter
 void addTypeConverter(Class toType, Class fromType, TypeConverter typeConverter)
          Registers a new type converter
protected  void checkLoaded()
          Checks if the registry is loaded and if not lazily load it
<T> T
convertTo(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
convertTo(Class<T> type, Object value)
          Converts the value to the specified type
 Object doConvertTo(Class type, Exchange exchange, Object value)
           
 Set<Class> getFromClassMappings()
           
 Injector getInjector()
          Gets the injector
protected
<T> TypeConverter
getOrFindTypeConverter(Class toType, Object value)
           
 Map<Class,TypeConverter> getToClassMappings(Class fromClass)
           
 TypeConverter getTypeConverter(Class toType, Class fromType)
           
 List<TypeConverterLoader> getTypeConverterLoaders()
           
 Map<DefaultTypeConverter.TypeMapping,TypeConverter> getTypeMappings()
           
protected  void loadFallbackTypeConverters()
           
 TypeConverter lookup(Class toType, Class fromType)
          Performs a lookup for a given type converter.
<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
 void setInjector(Injector injector)
          Sets the injector to be used for creating new instances during type convertions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultTypeConverter

public DefaultTypeConverter(PackageScanClassResolver resolver,
                            Injector injector,
                            FactoryFinder factoryFinder)
Method Detail

getTypeConverterLoaders

public List<TypeConverterLoader> getTypeConverterLoaders()

convertTo

public <T> T convertTo(Class<T> type,
                       Object value)
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

convertTo

public <T> T convertTo(Class<T> type,
                       Exchange exchange,
                       Object value)
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:
convertTo 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

mandatoryConvertTo

public <T> T mandatoryConvertTo(Class<T> type,
                                Object value)
                     throws 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:
NoTypeConversionAvailableException - if conversion not possible

mandatoryConvertTo

public <T> T mandatoryConvertTo(Class<T> type,
                                Exchange exchange,
                                Object value)
                     throws 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:
NoTypeConversionAvailableException

doConvertTo

public Object doConvertTo(Class type,
                          Exchange exchange,
                          Object value)

addTypeConverter

public void addTypeConverter(Class toType,
                             Class fromType,
                             TypeConverter typeConverter)
Description copied from interface: TypeConverterRegistry
Registers a new type converter

Specified by:
addTypeConverter in interface TypeConverterRegistry
Parameters:
toType - the type to convert to
fromType - the type to convert from
typeConverter - the type converter to use

addFallbackTypeConverter

public void addFallbackTypeConverter(TypeConverter typeConverter)
Description copied from interface: TypeConverterRegistry
Registers a new fallback type converter

Specified by:
addFallbackTypeConverter in interface TypeConverterRegistry
Parameters:
typeConverter - the type converter to use

getTypeConverter

public TypeConverter getTypeConverter(Class toType,
                                      Class fromType)

getInjector

public Injector getInjector()
Description copied from interface: TypeConverterRegistry
Gets the injector

Specified by:
getInjector in interface TypeConverterRegistry

setInjector

public void setInjector(Injector injector)
Description copied from interface: TypeConverterRegistry
Sets the injector to be used for creating new instances during type convertions.

Specified by:
setInjector in interface TypeConverterRegistry

getFromClassMappings

public Set<Class> getFromClassMappings()

getToClassMappings

public Map<Class,TypeConverter> getToClassMappings(Class fromClass)

getTypeMappings

public Map<DefaultTypeConverter.TypeMapping,TypeConverter> getTypeMappings()

getOrFindTypeConverter

protected <T> TypeConverter getOrFindTypeConverter(Class toType,
                                                   Object value)

lookup

public TypeConverter lookup(Class toType,
                            Class fromType)
Description copied from interface: TypeConverterRegistry
Performs a lookup for a given type converter.

Specified by:
lookup in interface TypeConverterRegistry
Parameters:
toType - the type to convert to
fromType - the type to convert from
Returns:
the type converter or null if not found.

checkLoaded

protected void checkLoaded()
Checks if the registry is loaded and if not lazily load it


loadFallbackTypeConverters

protected void loadFallbackTypeConverters()
                                   throws IOException,
                                          ClassNotFoundException
Throws:
IOException
ClassNotFoundException


Copyright © 2009 Apache Software Foundation. All Rights Reserved.