use of org.apache.camel.TypeConverterExistsException in project camel by apache.
the class BaseTypeConverterRegistry method addTypeConverter.
@Override
public void addTypeConverter(Class<?> toType, Class<?> fromType, TypeConverter typeConverter) {
log.trace("Adding type converter: {}", typeConverter);
TypeMapping key = new TypeMapping(toType, fromType);
TypeConverter converter = typeMappings.get(key);
if (typeConverter != converter) {
// add the converter unless we should ignore
boolean add = true;
// if converter is not null then a duplicate exists
if (converter != null) {
if (typeConverterExists == TypeConverterExists.Override) {
CamelLogger logger = new CamelLogger(log, typeConverterExistsLoggingLevel);
logger.log("Overriding type converter from: " + converter + " to: " + typeConverter);
} else if (typeConverterExists == TypeConverterExists.Ignore) {
CamelLogger logger = new CamelLogger(log, typeConverterExistsLoggingLevel);
logger.log("Ignoring duplicate type converter from: " + converter + " to: " + typeConverter);
add = false;
} else {
// we should fail
throw new TypeConverterExistsException(toType, fromType);
}
}
if (add) {
typeMappings.put(key, typeConverter);
// remove any previous misses, as we added the new type converter
misses.remove(key);
}
}
}
Aggregations