camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r739202 - in /camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel: impl/DefaultComponentResolver.java util/FactoryFinder.java util/ObjectHelper.java
Date Fri, 30 Jan 2009 08:07:25 GMT
Author: davsclaus
Date: Fri Jan 30 08:07:25 2009
New Revision: 739202

URL: http://svn.apache.org/viewvc?rev=739202&view=rev
Log:
Merged revisions 739199 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r739199 | davsclaus | 2009-01-30 08:47:39 +0100 (Fri, 30 Jan 2009) | 1 line
  
  CAMEL-1301: Fixed NPE in factory finder and improved ObjectHelper.loadClass
........

Modified:
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java?rev=739202&r1=739201&r2=739202&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java
Fri Jan 30 08:07:25 2009
@@ -63,12 +63,12 @@
             throw new IllegalArgumentException("Invalid URI, no Component registered for
scheme : "
                     + name, e);
         }
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Found component: " + name + " via type: " + type.getName() + " via
" + COMPONENT_FACTORY.getPath() + name);
-        }
         if (type == null) {
             return null;
         }
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Found component: " + name + " via type: " + type.getName() + " via
" + COMPONENT_FACTORY.getPath() + name);
+        }
         if (Component.class.isAssignableFrom(type)) {
             return (Component<E>) context.getInjector().newInstance(type);
         } else {

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java?rev=739202&r1=739201&r2=739202&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java
Fri Jan 30 08:07:25 2009
@@ -106,7 +106,9 @@
         Class clazz = (Class)classMap.get(propertyPrefix + key);
         if (clazz == null) {
             clazz = newInstance(doFindFactoryProperties(key), propertyPrefix);
-            classMap.put(propertyPrefix + key, clazz);
+            if (clazz != null) {
+                classMap.put(propertyPrefix + key, clazz);
+            }
         }
         return clazz;
     }

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=739202&r1=739201&r2=739202&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
Fri Jan 30 08:07:25 2009
@@ -478,17 +478,44 @@
      * @return the class or null if it could not be loaded
      */
     public static Class<?> loadClass(String name, ClassLoader loader) {
-        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
-        if (contextClassLoader != null) {
-            try {
-                return contextClassLoader.loadClass(name);
-            } catch (ClassNotFoundException e) {
-                try {
-                    return loader.loadClass(name);
-                } catch (ClassNotFoundException e1) {
-                    LOG.debug("Could not find class: " + name + ". Reason: " + e);
-                }
+        // try context class loader first
+        Class clazz = doLoadClass(name, Thread.currentThread().getContextClassLoader());
+        if (clazz == null) {
+            // then the provided loader
+            clazz = doLoadClass(name, loader);
+        }
+        if (clazz == null) {
+            // and fallback to the loader the loaded the ObjectHelper class
+            clazz = doLoadClass(name, ObjectHelper.class.getClassLoader());
+        }
+
+        if (clazz == null) {
+            LOG.warn("Could not find class: " + name);
+        }
+
+        return clazz;
+    }
+
+    /**
+     * Loads the given class with the provided classloader (may be null).
+     * Will ignore any class not found and return null.
+     *
+     * @param name    the name of the class to load
+     * @param loader  a provided loader (may be null)
+     * @return the class, or null if it could not be loaded
+     */
+    private static Class<?> doLoadClass(String name, ClassLoader loader) {
+        ObjectHelper.notEmpty(name, "name");
+        if (loader == null) {
+            return null;
+        }
+        try {
+            return loader.loadClass(name);
+        } catch (ClassNotFoundException e) {
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Can not load class: " + name + " using classloader: " + loader,
e);
             }
+
         }
         return null;
     }



Mime
View raw message