public abstract class BaseTypeConverterRegistry extends ServiceSupport implements TypeConverter, TypeConverterRegistry, CamelContextAware
Modifier and Type | Class and Description |
---|---|
protected static class |
BaseTypeConverterRegistry.FallbackTypeConverter
Represents a fallback type converter
|
protected static class |
BaseTypeConverterRegistry.TypeMapping
Represents a mapping from one type (which can be null) to another
|
TypeConverterRegistry.Statistics
Modifier and Type | Field and Description |
---|---|
protected AtomicLong |
attemptCounter |
protected CamelContext |
camelContext |
protected FactoryFinder |
factoryFinder |
protected AtomicLong |
failedCounter |
protected List<BaseTypeConverterRegistry.FallbackTypeConverter> |
fallbackConverters |
protected AtomicLong |
hitCounter |
protected Injector |
injector |
protected org.slf4j.Logger |
log |
protected AtomicLong |
missCounter |
protected LRUSoftCache<BaseTypeConverterRegistry.TypeMapping,BaseTypeConverterRegistry.TypeMapping> |
misses |
protected AtomicLong |
noopCounter |
protected PackageScanClassResolver |
resolver |
protected TypeConverterRegistry.Statistics |
statistics |
protected TypeConverterExists |
typeConverterExists |
protected LoggingLevel |
typeConverterExistsLoggingLevel |
protected List<TypeConverterLoader> |
typeConverterLoaders |
protected ConcurrentMap<BaseTypeConverterRegistry.TypeMapping,TypeConverter> |
typeMappings |
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
Constructor and Description |
---|
BaseTypeConverterRegistry(PackageScanClassResolver resolver,
Injector injector,
FactoryFinder factoryFinder) |
Modifier and Type | Method and Description |
---|---|
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.
|
void |
addTypeConverters(TypeConverters typeConverters)
Registers all the type converters from the class, each converter must be implemented as a method and annotated with
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
|
protected TypeConversionException |
createTypeConversionException(Exchange exchange,
Class<?> type,
Object value,
Throwable cause) |
protected Object |
doConvertTo(Class<?> type,
Exchange exchange,
Object value,
boolean tryConvert) |
protected TypeConverter |
doLookup(Class<?> toType,
Class<?> fromType,
boolean isSuper) |
protected void |
doStart()
Implementations override this method to support customized start/stop.
|
protected void |
doStop()
Implementations override this method to support customized start/stop.
|
CamelContext |
getCamelContext()
Get the
CamelContext |
Set<Class<?>> |
getFromClassMappings() |
Injector |
getInjector()
Gets the injector
|
protected <T> TypeConverter |
getOrFindTypeConverter(BaseTypeConverterRegistry.TypeMapping key) |
TypeConverterRegistry.Statistics |
getStatistics()
Gets the utilization statistics of this type converter registry
|
Map<Class<?>,TypeConverter> |
getToClassMappings(Class<?> fromClass) |
TypeConverter |
getTypeConverter(Class<?> toType,
Class<?> fromType) |
TypeConverterExists |
getTypeConverterExists()
What should happen when attempting to add a duplicate type converter.
|
LoggingLevel |
getTypeConverterExistsLoggingLevel()
The logging level to use when logging that a type converter already exists when attempting to add a duplicate type converter.
|
List<TypeConverterLoader> |
getTypeConverterLoaders() |
Map<BaseTypeConverterRegistry.TypeMapping,TypeConverter> |
getTypeMappings() |
List<Class<?>[]> |
listAllTypeConvertersFromTo()
Gets a read-only list of the type converter from / to classes
|
void |
loadCoreTypeConverters()
Loads the core type converters which is mandatory to use Camel
|
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
|
boolean |
removeTypeConverter(Class<?> toType,
Class<?> fromType)
Removes the type converter
|
void |
setCamelContext(CamelContext camelContext)
Injects the
CamelContext |
void |
setInjector(Injector injector)
Sets the injector to be used for creating new instances during type conversions.
|
void |
setTypeConverterExists(TypeConverterExists typeConverterExists)
What should happen when attempting to add a duplicate type converter.
|
void |
setTypeConverterExistsLoggingLevel(LoggingLevel typeConverterExistsLoggingLevel)
The logging level to use when logging that a type converter already exists when attempting to add a duplicate type converter.
|
int |
size()
Number of type converters in the registry.
|
<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.
|
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
allowNull
protected final org.slf4j.Logger log
protected final ConcurrentMap<BaseTypeConverterRegistry.TypeMapping,TypeConverter> typeMappings
protected final LRUSoftCache<BaseTypeConverterRegistry.TypeMapping,BaseTypeConverterRegistry.TypeMapping> misses
protected final List<TypeConverterLoader> typeConverterLoaders
protected final List<BaseTypeConverterRegistry.FallbackTypeConverter> fallbackConverters
protected final PackageScanClassResolver resolver
protected CamelContext camelContext
protected final FactoryFinder factoryFinder
protected TypeConverterExists typeConverterExists
protected LoggingLevel typeConverterExistsLoggingLevel
protected final TypeConverterRegistry.Statistics statistics
protected final AtomicLong noopCounter
protected final AtomicLong attemptCounter
protected final AtomicLong missCounter
protected final AtomicLong hitCounter
protected final AtomicLong failedCounter
public BaseTypeConverterRegistry(PackageScanClassResolver resolver, Injector injector, FactoryFinder factoryFinder)
public CamelContext getCamelContext()
CamelContextAware
CamelContext
getCamelContext
in interface CamelContextAware
public void setCamelContext(CamelContext camelContext)
CamelContextAware
CamelContext
setCamelContext
in interface CamelContextAware
camelContext
- the Camel contextpublic List<TypeConverterLoader> getTypeConverterLoaders()
public <T> T convertTo(Class<T> type, Object value)
TypeConverter
convertTo
in interface TypeConverter
type
- the requested typevalue
- the value to be convertedpublic <T> T convertTo(Class<T> type, Exchange exchange, Object value)
TypeConverter
convertTo
in interface TypeConverter
type
- the requested typeexchange
- the current exchangevalue
- the value to be convertedpublic <T> T mandatoryConvertTo(Class<T> type, Object value) throws NoTypeConversionAvailableException
TypeConverter
mandatoryConvertTo
in interface TypeConverter
type
- the requested typevalue
- the value to be convertedNoTypeConversionAvailableException
- if no type converters exists to convert to the given typepublic <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) throws NoTypeConversionAvailableException
TypeConverter
mandatoryConvertTo
in interface TypeConverter
type
- the requested typeexchange
- the current exchangevalue
- the value to be convertedNoTypeConversionAvailableException
- if no type converters exists to convert to the given typepublic <T> T tryConvertTo(Class<T> type, Object value)
TypeConverter
tryConvertTo
in interface TypeConverter
type
- the requested typevalue
- the value to be convertedpublic <T> T tryConvertTo(Class<T> type, Exchange exchange, Object value)
TypeConverter
tryConvertTo
in interface TypeConverter
type
- the requested typeexchange
- the current exchangevalue
- the value to be convertedprotected Object doConvertTo(Class<?> type, Exchange exchange, Object value, boolean tryConvert)
public void addTypeConverter(Class<?> toType, Class<?> fromType, TypeConverter typeConverter)
TypeConverterRegistry
TypeConverterExistsException
if configured to fail if an existing
type converter already existsaddTypeConverter
in interface TypeConverterRegistry
toType
- the type to convert tofromType
- the type to convert fromtypeConverter
- the type converter to usepublic void addTypeConverters(TypeConverters typeConverters)
TypeConverterRegistry
Converter
.addTypeConverters
in interface TypeConverterRegistry
typeConverters
- class which implements the type converterspublic boolean removeTypeConverter(Class<?> toType, Class<?> fromType)
TypeConverterRegistry
removeTypeConverter
in interface TypeConverterRegistry
toType
- the type to convert tofromType
- the type to convert frompublic void addFallbackTypeConverter(TypeConverter typeConverter, boolean canPromote)
TypeConverterRegistry
addFallbackTypeConverter
in interface TypeConverterRegistry
typeConverter
- the type converter to usecanPromote
- whether or not the fallback type converter can be promoted to a first class type converterpublic TypeConverter getTypeConverter(Class<?> toType, Class<?> fromType)
public Injector getInjector()
TypeConverterRegistry
getInjector
in interface TypeConverterRegistry
public void setInjector(Injector injector)
TypeConverterRegistry
setInjector
in interface TypeConverterRegistry
injector
- the injectorpublic Set<Class<?>> getFromClassMappings()
public Map<Class<?>,TypeConverter> getToClassMappings(Class<?> fromClass)
public Map<BaseTypeConverterRegistry.TypeMapping,TypeConverter> getTypeMappings()
protected <T> TypeConverter getOrFindTypeConverter(BaseTypeConverterRegistry.TypeMapping key)
public TypeConverter lookup(Class<?> toType, Class<?> fromType)
TypeConverterRegistry
lookup
in interface TypeConverterRegistry
toType
- the type to convert tofromType
- the type to convert fromprotected TypeConverter doLookup(Class<?> toType, Class<?> fromType, boolean isSuper)
public List<Class<?>[]> listAllTypeConvertersFromTo()
TypeConverterRegistry
listAllTypeConvertersFromTo
in interface TypeConverterRegistry
public void loadCoreTypeConverters() throws Exception
Exception
protected void loadTypeConverters() throws Exception
Exception
protected void loadFallbackTypeConverters() throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
protected TypeConversionException createTypeConversionException(Exchange exchange, Class<?> type, Object value, Throwable cause)
public TypeConverterRegistry.Statistics getStatistics()
TypeConverterRegistry
getStatistics
in interface TypeConverterRegistry
public int size()
TypeConverterRegistry
size
in interface TypeConverterRegistry
public LoggingLevel getTypeConverterExistsLoggingLevel()
TypeConverterRegistry
getTypeConverterExistsLoggingLevel
in interface TypeConverterRegistry
public void setTypeConverterExistsLoggingLevel(LoggingLevel typeConverterExistsLoggingLevel)
TypeConverterRegistry
setTypeConverterExistsLoggingLevel
in interface TypeConverterRegistry
public TypeConverterExists getTypeConverterExists()
TypeConverterRegistry
getTypeConverterExists
in interface TypeConverterRegistry
public void setTypeConverterExists(TypeConverterExists typeConverterExists)
TypeConverterRegistry
setTypeConverterExists
in interface TypeConverterRegistry
protected void doStart() throws Exception
ServiceSupport
ServiceSupport.doStop()
for more details.doStart
in class ServiceSupport
Exception
ServiceSupport.doStop()
protected void doStop() throws Exception
ServiceSupport
ServiceSupport.doStop()
method when
the service is being stopped. This method will also be invoked
if the service is still in uninitialized state (eg has not
been started). The method is always called to allow the service
to do custom logic when the service is being stopped, such as when
CamelContext
is shutting down.doStop
in class ServiceSupport
Exception
ServiceSupport.doStart()
Apache Camel