use of org.apache.camel.spi.TypeConverterAware in project camel by apache.
the class InstanceMethodTypeConverter method convertTo.
@SuppressWarnings("unchecked")
public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
Object instance = injector.newInstance();
if (instance == null) {
throw new RuntimeCamelException("Could not instantiate an instance of: " + type.getCanonicalName());
}
// inject parent type converter
if (instance instanceof TypeConverterAware) {
if (registry instanceof TypeConverter) {
TypeConverter parentTypeConverter = (TypeConverter) registry;
((TypeConverterAware) instance).setTypeConverter(parentTypeConverter);
}
}
return useExchange ? (T) ObjectHelper.invokeMethod(method, instance, value, exchange) : (T) ObjectHelper.invokeMethod(method, instance, value);
}
use of org.apache.camel.spi.TypeConverterAware in project camel by apache.
the class BaseTypeConverterRegistry method addFallbackTypeConverter.
@Override
public void addFallbackTypeConverter(TypeConverter typeConverter, boolean canPromote) {
log.trace("Adding fallback type converter: {} which can promote: {}", typeConverter, canPromote);
// add in top of fallback as the toString() fallback will nearly always be able to convert
// the last one which is add to the FallbackTypeConverter will be called at the first place
fallbackConverters.add(0, new FallbackTypeConverter(typeConverter, canPromote));
if (typeConverter instanceof TypeConverterAware) {
TypeConverterAware typeConverterAware = (TypeConverterAware) typeConverter;
typeConverterAware.setTypeConverter(this);
}
if (typeConverter instanceof CamelContextAware) {
CamelContextAware camelContextAware = (CamelContextAware) typeConverter;
if (camelContext != null) {
camelContextAware.setCamelContext(camelContext);
}
}
}
Aggregations