camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject git commit: CAMEL-6598: camel-dozer if mapping type is one way then dont add 2nd converter.
Date Thu, 01 Aug 2013 12:07:45 GMT
Updated Branches:
  refs/heads/master b24f380c1 -> 59ff5faad


CAMEL-6598: camel-dozer if mapping type is one way then dont add 2nd converter.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/59ff5faa
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/59ff5faa
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/59ff5faa

Branch: refs/heads/master
Commit: 59ff5faade9067e6c1789e487a53f83cd58be64d
Parents: b24f380
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Aug 1 14:07:38 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Aug 1 14:07:38 2013 +0200

----------------------------------------------------------------------
 .../dozer/DozerTypeConverterLoader.java         | 32 ++++++++++++++------
 1 file changed, 22 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/59ff5faa/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java
b/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java
index e5a8385..dc42c94 100644
--- a/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java
+++ b/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerTypeConverterLoader.java
@@ -42,6 +42,8 @@ import org.dozer.util.DozerClassLoader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.dozer.classmap.MappingDirection.ONE_WAY;
+
 /**
  * <code>DozerTypeConverterLoader</code> provides the mechanism for registering
  * a Dozer {@link Mapper} as {@link TypeConverter} for a {@link CamelContext}.
@@ -122,9 +124,11 @@ public class DozerTypeConverterLoader implements CamelContextAware {
         }
 
         TypeConverterRegistry registry = camelContext.getTypeConverterRegistry();
-        for (DozerBeanMapper dozer : mappers.values()) {
-            List<ClassMap> all = loadMappings(camelContext, dozer);
-            registerClassMaps(registry, dozer, all);
+        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);
         }
     }
 
@@ -135,22 +139,30 @@ public class DozerTypeConverterLoader implements CamelContextAware {
         return new HashMap<String, DozerBeanMapper>(camelContext.getRegistry().findByTypeWithName(DozerBeanMapper.class));
     }
 
-    protected void registerClassMaps(TypeConverterRegistry registry, DozerBeanMapper dozer,
List<ClassMap> all) {
+    protected void registerClassMaps(TypeConverterRegistry registry, String dozerId, DozerBeanMapper
dozer, List<ClassMap> all) {
         DozerTypeConverter converter = new DozerTypeConverter(dozer);
         for (ClassMap map : all) {
-            addDozerTypeConverter(registry, converter, map.getMapId(), map.getSrcClassToMap(),
map.getDestClassToMap());
+            addDozerTypeConverter(registry, converter, dozerId, map.getSrcClassToMap(), map.getDestClassToMap());
+            // if not one way then add the other way around also
+            if (map.getType() != ONE_WAY) {
+                addDozerTypeConverter(registry, converter, dozerId, map.getDestClassToMap(),
map.getSrcClassToMap());
+            }
         }
     }
 
-    protected void addDozerTypeConverter(TypeConverterRegistry registry, DozerTypeConverter
converter, String mapId, Class<?> to, Class<?> from) {
+    protected void addDozerTypeConverter(TypeConverterRegistry registry, DozerTypeConverter
converter,
+                                         String dozerId, Class<?> to, Class<?>
from) {
         if (log.isInfoEnabled()) {
-            log.info("Added Dozer map id {} as Camel type converter {} <-> {}", new
Object[]{mapId, from, to});
+            if (dozerId != null) {
+                log.info("Added Dozer: {} as Camel type converter: {} -> {}", new Object[]{dozerId,
from, to});
+            } else {
+                log.info("Added Dozer as Camel type converter: {} -> {}", new Object[]{from,
to});
+            }
         }
         registry.addTypeConverter(from, to, converter);
-        registry.addTypeConverter(to, from, converter);
     }
 
-    private List<ClassMap> loadMappings(CamelContext camelContext, DozerBeanMapper
mapper) {
+    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
@@ -190,7 +202,7 @@ public class DozerTypeConverterLoader implements CamelContextAware {
         TypeConverterRegistry registry = camelContext.getTypeConverterRegistry();
         List<ClassMap> classMaps = new ArrayList<ClassMap>();
         classMaps.addAll(mappingFileData.getClassMaps());
-        registerClassMaps(registry, mapper, classMaps);
+        registerClassMaps(registry, null, mapper, classMaps);
     }
 
     public CamelContext getCamelContext() {


Mime
View raw message