Search in sources :

Example 1 with MappingFileData

use of org.dozer.classmap.MappingFileData in project camel by apache.

the class DozerTypeConverterLoader method addMapping.

/**
     * Registers Dozer <code>BeanMappingBuilder</code> in current mapper instance.
     * This method should be called instead of direct <code>mapper.addMapping()</code> invocation for Camel
     * being able to register given type conversion.
     *
     * @param beanMappingBuilder api-based mapping builder
     */
public void addMapping(BeanMappingBuilder beanMappingBuilder) {
    if (mapper == null) {
        log.warn("No mapper instance provided to " + this.getClass().getSimpleName() + ". Mapping has not been registered!");
        return;
    }
    mapper.addMapping(beanMappingBuilder);
    MappingFileData mappingFileData = beanMappingBuilder.build();
    TypeConverterRegistry registry = camelContext.getTypeConverterRegistry();
    List<ClassMap> classMaps = new ArrayList<ClassMap>();
    classMaps.addAll(mappingFileData.getClassMaps());
    registerClassMaps(registry, null, mapper, classMaps);
}
Also used : TypeConverterRegistry(org.apache.camel.spi.TypeConverterRegistry) MappingFileData(org.dozer.classmap.MappingFileData) ArrayList(java.util.ArrayList) ClassMap(org.dozer.classmap.ClassMap)

Example 2 with MappingFileData

use of org.dozer.classmap.MappingFileData in project camel by apache.

the class DozerTypeConverterLoader method loadMappings.

private List<ClassMap> loadMappings(CamelContext camelContext, String mapperId, DozerBeanMapper mapper) {
    List<ClassMap> answer = new ArrayList<ClassMap>();
    // load the class map using the class resolver so we can load from classpath in OSGi
    MappingFileReader reader = new MappingFileReader(XMLParserFactory.getInstance());
    List<String> mappingFiles = mapper.getMappingFiles();
    if (mappingFiles == null) {
        return Collections.emptyList();
    }
    for (String name : mappingFiles) {
        URL url = loadMappingFile(camelContext.getClassResolver(), name);
        if (url != null) {
            MappingFileData data = reader.read(url);
            answer.addAll(data.getClassMaps());
        }
    }
    return answer;
}
Also used : MappingFileReader(org.dozer.loader.xml.MappingFileReader) MappingFileData(org.dozer.classmap.MappingFileData) ArrayList(java.util.ArrayList) ClassMap(org.dozer.classmap.ClassMap) URL(java.net.URL)

Aggregations

ArrayList (java.util.ArrayList)2 ClassMap (org.dozer.classmap.ClassMap)2 MappingFileData (org.dozer.classmap.MappingFileData)2 URL (java.net.URL)1 TypeConverterRegistry (org.apache.camel.spi.TypeConverterRegistry)1 MappingFileReader (org.dozer.loader.xml.MappingFileReader)1