camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/4] camel git commit: CAMEL-9677: FallbackTypeConverter that are CamelContextAware should have it injected
Date Tue, 08 Mar 2016 08:39:27 GMT
Repository: camel
Updated Branches:
  refs/heads/master dcf340002 -> 72141c6d6


CAMEL-9677: FallbackTypeConverter that are CamelContextAware should have it injected


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

Branch: refs/heads/master
Commit: 0fc20bddc9e5e3db5108428f727b35370e0cc9b0
Parents: dcf3400
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Mar 8 09:17:38 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Mar 8 09:22:34 2016 +0100

----------------------------------------------------------------------
 .../apache/camel/impl/DefaultCamelContext.java   |  1 +
 .../converter/BaseTypeConverterRegistry.java     | 19 ++++++++++++++++++-
 .../converter/InstanceFallbackConverterTest.java |  4 ++--
 .../InstanceDummyFallbackConverter.java          | 18 ++++++++++++++++--
 4 files changed, 37 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0fc20bdd/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index dd397b4..26ddea9 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -3646,6 +3646,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
         } else {
             answer = new DefaultTypeConverter(packageScanClassResolver, getInjector(), getDefaultFactoryFinder());
         }
+        answer.setCamelContext(this);
         setTypeConverterRegistry(answer);
         return answer;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/0fc20bdd/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
b/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
index 95069d9..2895001 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
@@ -29,6 +29,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.atomic.AtomicLong;
 
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.CamelExecutionException;
 import org.apache.camel.Exchange;
 import org.apache.camel.LoggingLevel;
@@ -60,7 +62,7 @@ import org.slf4j.LoggerFactory;
  *
  * @version 
  */
-public abstract class BaseTypeConverterRegistry extends ServiceSupport implements TypeConverter,
TypeConverterRegistry {
+public abstract class BaseTypeConverterRegistry extends ServiceSupport implements TypeConverter,
TypeConverterRegistry, CamelContextAware {
     protected final Logger log = LoggerFactory.getLogger(getClass());
     protected final ConcurrentMap<TypeMapping, TypeConverter> typeMappings = new ConcurrentHashMap<TypeMapping,
TypeConverter>();
     // for misses use a soft reference cache map, as the classes may be un-deployed at runtime
@@ -68,6 +70,7 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport implement
     protected final List<TypeConverterLoader> typeConverterLoaders = new ArrayList<TypeConverterLoader>();
     protected final List<FallbackTypeConverter> fallbackConverters = new CopyOnWriteArrayList<FallbackTypeConverter>();
     protected final PackageScanClassResolver resolver;
+    protected CamelContext camelContext;
     protected Injector injector;
     protected final FactoryFinder factoryFinder;
     protected TypeConverterExists typeConverterExists = TypeConverterExists.Override;
@@ -99,6 +102,16 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport
implement
         addFallbackTypeConverter(new AsyncProcessorTypeConverter(), true);
     }
 
+    @Override
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
+    @Override
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
     public List<TypeConverterLoader> getTypeConverterLoaders() {
         return typeConverterLoaders;
     }
@@ -444,6 +457,10 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport
implement
             TypeConverterAware typeConverterAware = (TypeConverterAware) typeConverter;
             typeConverterAware.setTypeConverter(this);
         }
+        if (typeConverter instanceof CamelContextAware) {
+            CamelContextAware camelContextAware = (CamelContextAware) typeConverter;
+            camelContextAware.setCamelContext(getCamelContext());
+        }
     }
 
     public TypeConverter getTypeConverter(Class<?> toType, Class<?> fromType)
{

http://git-wip-us.apache.org/repos/asf/camel/blob/0fc20bdd/camel-core/src/test/java/org/apache/camel/converter/InstanceFallbackConverterTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/converter/InstanceFallbackConverterTest.java
b/camel-core/src/test/java/org/apache/camel/converter/InstanceFallbackConverterTest.java
index befabe9..1bcaddd 100644
--- a/camel-core/src/test/java/org/apache/camel/converter/InstanceFallbackConverterTest.java
+++ b/camel-core/src/test/java/org/apache/camel/converter/InstanceFallbackConverterTest.java
@@ -36,7 +36,7 @@ public class InstanceFallbackConverterTest extends ContextTestSupport {
         Currency cur = Currency.getInstance(Locale.US);
 
         String money = context.getTypeConverter().convertTo(String.class, exchange, cur);
-        assertEquals("Money talks", money);
+        assertEquals("Money talks says " + context.getName(), money);
     }
 
     public void testInstanceFallbackMandatoryConverter() throws Exception {
@@ -44,7 +44,7 @@ public class InstanceFallbackConverterTest extends ContextTestSupport {
         Currency cur = Currency.getInstance(Locale.US);
 
         String money = context.getTypeConverter().mandatoryConvertTo(String.class, exchange,
cur);
-        assertEquals("Money talks", money);
+        assertEquals("Money talks says " + context.getName(), money);
     }
 
     public void testInstanceFallbackMandatoryFailed() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/0fc20bdd/camel-core/src/test/java/org/apache/camel/converter/myconverter/InstanceDummyFallbackConverter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/converter/myconverter/InstanceDummyFallbackConverter.java
b/camel-core/src/test/java/org/apache/camel/converter/myconverter/InstanceDummyFallbackConverter.java
index 6c87b7a..f27fbbe 100644
--- a/camel-core/src/test/java/org/apache/camel/converter/myconverter/InstanceDummyFallbackConverter.java
+++ b/camel-core/src/test/java/org/apache/camel/converter/myconverter/InstanceDummyFallbackConverter.java
@@ -18,6 +18,8 @@ package org.apache.camel.converter.myconverter;
 
 import java.util.Currency;
 
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
 import org.apache.camel.FallbackConverter;
@@ -27,12 +29,24 @@ import org.apache.camel.spi.TypeConverterRegistry;
  * @version 
  */
 @Converter
-public class InstanceDummyFallbackConverter {
+public class InstanceDummyFallbackConverter implements CamelContextAware {
+
+    private CamelContext camelContext;
+
+    @Override
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
+    @Override
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
 
     @FallbackConverter
     public Object convertTo(Class<?> type, Exchange exchange, Object value, TypeConverterRegistry
registry) {
         if (Currency.class.isAssignableFrom(value.getClass())) {
-            return "Money talks";
+            return "Money talks says " + camelContext.getName();
         }
         return null;
     }


Mime
View raw message