camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r749939 - in /camel/trunk: camel-core/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/util/ components/camel-jms/src/main/java/org/apache/camel/component/jms/ components/camel-jpa/src/main/java/org...
Date Wed, 04 Mar 2009 08:10:32 GMT
Author: davsclaus
Date: Wed Mar  4 08:10:31 2009
New Revision: 749939

URL: http://svn.apache.org/viewvc?rev=749939&view=rev
Log:
CAMEL-1411: Use CacheResolver where possible, and let ObjectHelper be backup.

Modified:
    camel/trunk/camel-core/pom.xml
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java
    camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/util/SimpleRouteBuilder.java
    camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/ConvertersResource.java

Modified: camel/trunk/camel-core/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/pom.xml?rev=749939&r1=749938&r2=749939&view=diff
==============================================================================
--- camel/trunk/camel-core/pom.xml (original)
+++ camel/trunk/camel-core/pom.xml Wed Mar  4 08:10:31 2009
@@ -42,6 +42,7 @@
 	<camel.osgi.import>
 		!javax.xml.bind.annotation.adapters,
 		org.apache.xalan.xsltc.trax;resolution:=optional,
+        org.apache.camel.spring.util;resolution:=optional,
 		*
     </camel.osgi.import>
   </properties>

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java?rev=749939&r1=749938&r2=749939&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java Wed
Mar  4 08:10:31 2009
@@ -18,14 +18,11 @@
 
 import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.util.ObjectHelper;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 /**
- * Default class resolver that uses regular classloaders, and does NOT work in OSGi platforms.
+ * Default class resolver that uses regular class loader to load classes.
  */
 public class DefaultClassResolver implements ClassResolver {
-    private static final transient Log LOG = LogFactory.getLog(DefaultClassResolver.class);
 
     public Class resolveClass(String name) {
         return loadClass(name, DefaultClassResolver.class.getClassLoader());
@@ -80,35 +77,8 @@
     }
 
     protected Class loadClass(String name, ClassLoader loader) {
-        // 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());
-        }
-
-        return clazz;
-    }
-
-    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("Cannot load class: " + name + " using classloader: " + loader,
e);
-            }
-
-        }
-        return null;
+        return ObjectHelper.loadClass(name, loader);
     }
 
-
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=749939&r1=749938&r2=749939&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java Wed Mar 
4 08:10:31 2009
@@ -490,7 +490,6 @@
      *
      * @param name the name of the class to load
      * @return the class or null if it could not be loaded
-     * @deprecated use ClassResolver instead
      */
     public static Class<?> loadClass(String name) {
         return loadClass(name, ObjectHelper.class.getClassLoader());
@@ -504,7 +503,6 @@
      * @param loader the class loader to use after the thread context class
      *                loader
      * @return the class or null if it could not be loaded
-     * @deprecated use ClassResolver instead
      */
     public static Class<?> loadClass(String name, ClassLoader loader) {
         // try context class loader first
@@ -532,7 +530,6 @@
      * @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
-     * @deprecated use ClassResolver instead
      */
     private static Class<?> doLoadClass(String name, ClassLoader loader) {
         ObjectHelper.notEmpty(name, "name");

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java?rev=749939&r1=749938&r2=749939&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
(original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
Wed Mar  4 08:10:31 2009
@@ -49,8 +49,7 @@
  *
  * @version $Revision:520964 $
  */
-public class JmsComponent extends DefaultComponent implements ApplicationContextAware,
-    HeaderFilterStrategyAware {
+public class JmsComponent extends DefaultComponent implements ApplicationContextAware, HeaderFilterStrategyAware
{
 
     private static final transient Log LOG = LogFactory.getLog(JmsComponent.class);
     private static final String DEFAULT_QUEUE_BROWSE_STRATEGY = "org.apache.camel.component.jms.DefaultQueueBrowseStrategy";
@@ -329,7 +328,7 @@
             if (!attemptedToCreateQueueBrowserStrategy) {
                 attemptedToCreateQueueBrowserStrategy = true;
                 try {
-                    queueBrowseStrategy = tryCreateDefaultQueueBrowseStrategy();
+                    queueBrowseStrategy = tryCreateDefaultQueueBrowseStrategy(getCamelContext());
                 } catch (Throwable e) {
                     LOG.warn("Could not instantiate the QueueBrowseStrategy are you using
Spring 2.0.x"
                         + " by any chance? Error: " + e, e);
@@ -458,15 +457,16 @@
      *
      * @return the queue browse strategy or null if it cannot be supported
      */
-    protected static QueueBrowseStrategy tryCreateDefaultQueueBrowseStrategy() {
+    protected static QueueBrowseStrategy tryCreateDefaultQueueBrowseStrategy(CamelContext
context) {
         // lets try instantiate the default implementation
-        Class<?> type = ObjectHelper.loadClass(DEFAULT_QUEUE_BROWSE_STRATEGY, JmsComponent.class.getClassLoader());
+        // use the class loading this class from camel-jms to work in OSGi environments as
the camel-jms
+        // should import the spring-jms jars.
+        Class<?> type = context.getClassResolver().resolveClass(DEFAULT_QUEUE_BROWSE_STRATEGY,
JmsComponent.class.getClassLoader());
         if (type == null) {
-            LOG.warn("Could not load class: " + DEFAULT_QUEUE_BROWSE_STRATEGY
-                     + " maybe you are on Spring 2.0.x?");
+            LOG.warn("Could not load class: " + DEFAULT_QUEUE_BROWSE_STRATEGY + " maybe you
are on Spring 2.0.x?");
             return null;
         } else {
-            return (QueueBrowseStrategy)ObjectHelper.newInstance(type);
+            return ObjectHelper.newInstance(type, QueueBrowseStrategy.class);
         }
     }
 

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java?rev=749939&r1=749938&r2=749939&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java
(original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java
Wed Mar  4 08:10:31 2009
@@ -93,10 +93,10 @@
         return queueBrowseStrategy.browse(template, queue, this);
     }
 
-    protected static QueueBrowseStrategy createQueueBrowseStrategy() {
+    protected QueueBrowseStrategy createQueueBrowseStrategy() {
         QueueBrowseStrategy answer = null;
         try {
-            answer = JmsComponent.tryCreateDefaultQueueBrowseStrategy();
+            answer = JmsComponent.tryCreateDefaultQueueBrowseStrategy(getCamelContext());
         } catch (Throwable e) {
             LOG.debug("Caught exception trying to create default QueueBrowseStrategy. "
                       + "This could be due to spring 2.0.x on classpath? Cause: " + e, e);

Modified: camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java?rev=749939&r1=749938&r2=749939&view=diff
==============================================================================
--- camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
(original)
+++ camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
Wed Mar  4 08:10:31 2009
@@ -17,14 +17,12 @@
 package org.apache.camel.component.jpa;
 
 import java.util.Map;
-
 import javax.persistence.EntityManagerFactory;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Component;
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.util.ObjectHelper;
 
 /**
  * A JPA Component
@@ -57,11 +55,14 @@
 
         // lets interpret the next string as a class
         if (path != null) {
-            Class<?> type = ObjectHelper.loadClass(path);
+            // provide the class loader of this component to work in OSGi environments as
camel-jpa must be able
+            // to resolve the entity classes
+            Class<?> type = getCamelContext().getClassResolver().resolveClass(path,
JpaComponent.class.getClassLoader());
             if (type != null) {
                 endpoint.setEntityType(type);
             }
         }
+
         return endpoint;
     }
 }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java?rev=749939&r1=749938&r2=749939&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
Wed Mar  4 08:10:31 2009
@@ -25,7 +25,6 @@
 import org.apache.camel.component.ResourceBasedComponent;
 import org.apache.camel.converter.jaxp.XmlConverter;
 import org.apache.camel.impl.ProcessorEndpoint;
-import org.apache.camel.util.ObjectHelper;
 import org.springframework.core.io.Resource;
 
 /**
@@ -69,11 +68,12 @@
         String transformerFactoryClassName = getAndRemoveParameter(parameters, "transformerFactoryClass",
String.class);
         TransformerFactory factory = null;
         if (transformerFactoryClassName != null) {
-            Class factoryClass = ObjectHelper.loadClass(transformerFactoryClassName);
+            // provide the class loader of this component to work in OSGi environments
+            Class factoryClass = getCamelContext().getClassResolver().resolveClass(transformerFactoryClassName,
XsltComponent.class.getClassLoader());
             if (factoryClass != null) {
                 factory = (TransformerFactory) newInstance(factoryClass);
             } else {
-                log.warn("Cannot find the TransformerFactoryClass with the class name " +
transformerFactoryClassName);
+                log.warn("Cannot find the TransformerFactoryClass with the class name: "
+ transformerFactoryClassName);
             }
         }
         

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/util/SimpleRouteBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/util/SimpleRouteBuilder.java?rev=749939&r1=749938&r2=749939&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/util/SimpleRouteBuilder.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/util/SimpleRouteBuilder.java
Wed Mar  4 08:10:31 2009
@@ -21,7 +21,6 @@
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.model.ProcessorType;
-import org.apache.camel.util.ObjectHelper;
 
 /**
  * A simple {@link RouteBuilder} which can be configured directly with one or more from URIs,
zero or more to URIs
@@ -96,7 +95,7 @@
     public Class getBeanType() {
         if (beanType == null) {
             if (beanClass != null) {
-                beanType = ObjectHelper.loadClass(beanClass, getClass().getClassLoader());
+                beanType = getContext().getClassResolver().resolveClass(beanClass, getClass().getClassLoader());
             }
         }
         return beanType;

Modified: camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/ConvertersResource.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/ConvertersResource.java?rev=749939&r1=749938&r2=749939&view=diff
==============================================================================
--- camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/ConvertersResource.java
(original)
+++ camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/ConvertersResource.java
Wed Mar  4 08:10:31 2009
@@ -24,7 +24,6 @@
 import javax.ws.rs.PathParam;
 
 import org.apache.camel.impl.converter.DefaultTypeConverter;
-import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -63,7 +62,7 @@
 */
 
     public ConvertersFromResource getConvertersFrom(@PathParam("type") String typeName) {
-        Class type = ObjectHelper.loadClass(typeName, getClass().getClassLoader());
+        Class type = getCamelContext().getClassResolver().resolveClass(typeName, getClass().getClassLoader());
         if (type == null) {
             return null;
         }



Mime
View raw message