org.apache.camel.impl.converter
Class DefaultTypeConverter

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

public class DefaultTypeConverter
extends ServiceSupport
implements TypeConverter, TypeConverterRegistry

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

Version:
$Revision: 20404 $

Nested Class Summary
protected static class DefaultTypeConverter.FallbackTypeConverter
          Represents a fallback type converter
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, boolean canPromote)
          Registers a new fallback type converter
 void addTypeConverter(Class<?> toType, Class<?> fromType, TypeConverter typeConverter)
          Registers a new type converter
<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)
           
protected  void doStart()
           
protected  void doStop()
           
 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()
           
protected  void loadTypeConverters()
          Checks if the registry is loaded and if not lazily load it
 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 org.apache.camel.impl.ServiceSupport
addChildService, doShutdown, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, removeChildService, shutdown, start, stop
 
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,
                                     boolean canPromote)
Description copied from interface: TypeConverterRegistry
Registers a new fallback type converter

Specified by:
addFallbackTypeConverter in interface TypeConverterRegistry
Parameters:
typeConverter - the type converter to use
canPromote - whether or not the fallback type converter can be promoted to a first class type converter

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
Returns:
the injector

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
Parameters:
injector - the injector

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.

loadTypeConverters

protected void loadTypeConverters()
                           throws Exception
Checks if the registry is loaded and if not lazily load it

Throws:
Exception

loadFallbackTypeConverters

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

doStart

protected void doStart()
                throws Exception
Specified by:
doStart in class ServiceSupport
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Specified by:
doStop in class ServiceSupport
Throws:
Exception


Copyright © 2007-2010 IONA Open Source Community. All Rights Reserved.