Search in sources :

Example 1 with DozerThreadContextClassLoader

use of org.apache.camel.converter.dozer.DozerThreadContextClassLoader in project camel by apache.

the class DozerComponent method createDozerBeanMapper.

public static DozerBeanMapper createDozerBeanMapper(List<String> mappingFiles) {
    GlobalSettings settings = GlobalSettings.getInstance();
    try {
        LOG.info("Configuring GlobalSettings to use Camel classloader: {}", DozerThreadContextClassLoader.class.getName());
        Field field = settings.getClass().getDeclaredField("classLoaderBeanName");
        ReflectionHelper.setField(field, settings, DozerThreadContextClassLoader.class.getName());
    } catch (Exception e) {
        throw new IllegalStateException("Cannot configure Dozer GlobalSettings to use DozerThreadContextClassLoader as classloader due " + e.getMessage(), e);
    }
    try {
        LOG.info("Configuring GlobalSettings to enable EL");
        Field field = settings.getClass().getDeclaredField("elEnabled");
        ReflectionHelper.setField(field, settings, true);
    } catch (NoSuchFieldException nsfEx) {
        throw new IllegalStateException("Failed to enable EL in global Dozer settings", nsfEx);
    }
    return new DozerBeanMapper(mappingFiles);
}
Also used : Field(java.lang.reflect.Field) GlobalSettings(org.dozer.config.GlobalSettings) DozerThreadContextClassLoader(org.apache.camel.converter.dozer.DozerThreadContextClassLoader) DozerBeanMapper(org.dozer.DozerBeanMapper)

Aggregations

Field (java.lang.reflect.Field)1 DozerThreadContextClassLoader (org.apache.camel.converter.dozer.DozerThreadContextClassLoader)1 DozerBeanMapper (org.dozer.DozerBeanMapper)1 GlobalSettings (org.dozer.config.GlobalSettings)1