Search in sources :

Example 1 with TypeConverterExistsException

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);
        }
    }
}
Also used : TypeConverter(org.apache.camel.TypeConverter) CamelLogger(org.apache.camel.util.CamelLogger) TypeConverterExistsException(org.apache.camel.TypeConverterExistsException)

Aggregations

TypeConverter (org.apache.camel.TypeConverter)1 TypeConverterExistsException (org.apache.camel.TypeConverterExistsException)1 CamelLogger (org.apache.camel.util.CamelLogger)1