use of org.dozer.classmap.ClassMap 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);
}
use of org.dozer.classmap.ClassMap 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;
}
use of org.dozer.classmap.ClassMap in project camel by apache.
the class DozerTypeConverterLoader method init.
/**
* Doses the actual querying and registration of {@link DozerTypeConverter}s
* with the {@link CamelContext}.
*
* @param camelContext the context to register the
* {@link DozerTypeConverter} in
* @param mapper the DozerMapperBean to be wrapped as a type converter.
*/
public void init(CamelContext camelContext, DozerBeanMapper mapper) {
this.camelContext = camelContext;
if (mapper != null) {
this.mapper = mapper;
}
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
ClassLoader appcl = camelContext.getApplicationContextClassLoader();
if (appcl != null) {
Thread.currentThread().setContextClassLoader(appcl);
}
Map<String, DozerBeanMapper> mappers = lookupDozerBeanMappers();
// only add if we do not already have it
if (mapper != null && !mappers.containsValue(mapper)) {
mappers.put("parameter", mapper);
}
// add any dozer bean mapper configurations
Map<String, DozerBeanMapperConfiguration> configurations = lookupDozerBeanMapperConfigurations();
if (configurations != null && configuration != null) {
// filter out existing configuration, as we do not want to use it twice
String key = null;
for (Map.Entry<String, DozerBeanMapperConfiguration> entry : configurations.entrySet()) {
if (entry.getValue() == configuration) {
key = entry.getKey();
break;
}
}
if (key != null) {
configurations.remove(key);
}
}
if (configurations != null) {
if (configurations.size() > 1) {
log.warn("Loaded " + configurations.size() + " Dozer configurations from Camel registry." + " Dozer is most efficient when there is a single mapper instance. Consider amalgamating instances.");
}
for (Map.Entry<String, DozerBeanMapperConfiguration> entry : configurations.entrySet()) {
String id = entry.getKey();
DozerBeanMapper beanMapper = createDozerBeanMapper(entry.getValue());
// only add if we do not already have it
if (!mappers.containsValue(beanMapper)) {
mappers.put(id, beanMapper);
}
}
}
if (mappers.size() > 1) {
log.warn("Loaded " + mappers.size() + " Dozer mappers from Camel registry." + " Dozer is most efficient when there is a single mapper instance. Consider amalgamating instances.");
} else if (mappers.size() == 0) {
log.warn("No Dozer mappers found in Camel registry. You should add Dozer mappers as beans to the registry of the type: " + DozerBeanMapper.class.getName());
}
TypeConverterRegistry registry = camelContext.getTypeConverterRegistry();
for (Map.Entry<String, DozerBeanMapper> entry : mappers.entrySet()) {
String mapperId = entry.getKey();
DozerBeanMapper dozer = entry.getValue();
List<ClassMap> all = loadMappings(camelContext, mapperId, dozer);
registerClassMaps(registry, mapperId, dozer, all);
}
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
}
Aggregations