camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/5] camel git commit: CAMEL-8234: DefaultClassLoader - Should use applicationContextClassLoader from CamelContext as fallback
Date Tue, 13 Jan 2015 07:00:27 GMT
CAMEL-8234: DefaultClassLoader - Should use applicationContextClassLoader from CamelContext
as fallback


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

Branch: refs/heads/master
Commit: 446d48fa42587229c92accd09ebf642e2267a5f1
Parents: c2ed010
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Jan 13 07:25:57 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Jan 13 07:25:57 2015 +0100

----------------------------------------------------------------------
 .../apache/camel/impl/DefaultCamelContext.java  |  3 ++
 .../apache/camel/impl/DefaultClassResolver.java | 39 ++++++++++++++------
 2 files changed, 30 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/446d48fa/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 d47452f..32dab75 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
@@ -2162,6 +2162,9 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
             }
             setApplicationContextClassLoader(cl);
         }
+        if (classResolver instanceof CamelContextAware) {
+            ((CamelContextAware) classResolver).setCamelContext(this);
+        }
 
         if (log.isDebugEnabled()) {
             log.debug("Using ClassResolver={}, PackageScanClassResolver={}, ApplicationContextClassLoader={}",

http://git-wip-us.apache.org/repos/asf/camel/blob/446d48fa/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java
index d4076de..3c8cced 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java
@@ -21,6 +21,7 @@ import java.net.URL;
 import java.util.Enumeration;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.util.CastUtils;
 import org.apache.camel.util.ObjectHelper;
@@ -28,28 +29,39 @@ import org.apache.camel.util.ObjectHelper;
 /**
  * Default class resolver that uses regular class loader to load classes.
  */
-public class DefaultClassResolver implements ClassResolver {
+public class DefaultClassResolver implements ClassResolver, CamelContextAware {
 
-    private final ClassLoader loader;
+    private CamelContext camelContext;
+
+    public DefaultClassResolver() {
+    }
 
     public DefaultClassResolver(CamelContext camelContext) {
-        this.loader = camelContext != null ? camelContext.getApplicationContextClassLoader()
: null;
+        this.camelContext = camelContext;
+    }
+
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
+    public CamelContext getCamelContext() {
+        return camelContext;
     }
 
     public Class<?> resolveClass(String name) {
         Class<?> answer = loadClass(name, DefaultClassResolver.class.getClassLoader());
-        if (answer == null && loader != null) {
+        if (answer == null && getApplicationContextClassLoader() != null) {
             // fallback and use application context class loader
-            answer = loadClass(name, loader);
+            answer = loadClass(name, getApplicationContextClassLoader());
         }
         return answer;
     }
 
     public <T> Class<T> resolveClass(String name, Class<T> type) {
         Class<T> answer = CastUtils.cast(loadClass(name, DefaultClassResolver.class.getClassLoader()));
-        if (answer == null && loader != null) {
+        if (answer == null && getApplicationContextClassLoader() != null) {
             // fallback and use application context class loader
-            answer = CastUtils.cast(loadClass(name, loader));
+            answer = CastUtils.cast(loadClass(name, getApplicationContextClassLoader()));
         }
         return answer;
     }
@@ -59,8 +71,7 @@ public class DefaultClassResolver implements ClassResolver {
     }
 
     public <T> Class<T> resolveClass(String name, Class<T> type, ClassLoader
loader) {
-        Class<T> answer = CastUtils.cast(loadClass(name, loader));
-        return answer;
+        return CastUtils.cast(loadClass(name, loader));
     }
 
     public Class<?> resolveMandatoryClass(String name) throws ClassNotFoundException
{
@@ -97,19 +108,18 @@ public class DefaultClassResolver implements ClassResolver {
 
     public InputStream loadResourceAsStream(String uri) {
         ObjectHelper.notEmpty(uri, "uri");
-        return ObjectHelper.loadResourceAsStream(uri, loader);
+        return ObjectHelper.loadResourceAsStream(uri, getApplicationContextClassLoader());
     }
 
     public URL loadResourceAsURL(String uri) {
         ObjectHelper.notEmpty(uri, "uri");
-        return ObjectHelper.loadResourceAsURL(uri, loader);
+        return ObjectHelper.loadResourceAsURL(uri, getApplicationContextClassLoader());
     }
 
     public Enumeration<URL> loadResourcesAsURL(String uri) {
         return loadAllResourcesAsURL(uri);
     }
 
-    @Override
     public Enumeration<URL> loadAllResourcesAsURL(String uri) {
         ObjectHelper.notEmpty(uri, "uri");
         return ObjectHelper.loadResourcesAsURL(uri);
@@ -119,4 +129,9 @@ public class DefaultClassResolver implements ClassResolver {
         ObjectHelper.notEmpty(name, "name");
         return ObjectHelper.loadClass(name, loader);
     }
+
+    protected ClassLoader getApplicationContextClassLoader() {
+        return camelContext != null ? camelContext.getApplicationContextClassLoader() : null;
+    }
+
 }


Mime
View raw message