camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r749648 [1/2] - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/impl/converter/ ...
Date Tue, 03 Mar 2009 16:39:04 GMT
Author: davsclaus
Date: Tue Mar  3 16:39:03 2009
New Revision: 749648

URL: http://svn.apache.org/viewvc?rev=749648&view=rev
Log:
CAMEL-1404, CAMEL-1411: Introduced SPI interfaces for pluggable class resolvers for both package scanning and single class loading by name.

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java   (with props)
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java   (with props)
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/WebSpherePacakageScanClassResolver.java   (with props)
    camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ClassResolver.java   (with props)
    camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PackageScanClassResolver.java   (with props)
    camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PackageScanFilter.java   (with props)
    camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiPackageScanClassResolver.java   (contents, props changed)
      - copied, changed from r749569, camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiResolverUtil.java
Removed:
    camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiResolverUtil.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ReportingTypeConverterLoader.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/loadbalancer/LoadBalancerType.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/WebSphereResolverUtil.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/converter/JaxpTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/converter/StringSourceTest.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/AnnotationModelLoader.java
    camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrConverterTest.java
    camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java
    camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java
    camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/CamelOsgiTestSupport.java
    camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoaderTest.java
    camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/OsgiResolverUtilTest.java
    camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTypeConverterTest.scala
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/RouteBuilderFinder.java
    camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ConvertersMojo.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Tue Mar  3 16:39:03 2009
@@ -24,11 +24,13 @@
 import org.apache.camel.builder.ErrorHandlerBuilder;
 import org.apache.camel.model.RouteType;
 import org.apache.camel.model.dataformat.DataFormatType;
+import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.spi.ExchangeConverter;
 import org.apache.camel.spi.Injector;
 import org.apache.camel.spi.InterceptStrategy;
 import org.apache.camel.spi.Language;
 import org.apache.camel.spi.LifecycleStrategy;
+import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.spi.TypeConverterRegistry;
 import org.apache.camel.util.FactoryFinder;
@@ -345,4 +347,25 @@
      * Returns the current status of the given route
      */
     ServiceStatus getRouteStatus(RouteType route);
+
+    /**
+     * Returns the class resolver to be used for loading/lookup of classes.
+     */
+    ClassResolver getClassResolver();
+
+    /**
+     * Returns the package scanning class resolver
+     */
+    PackageScanClassResolver getPackageScanClassResolver();
+
+    /**
+     * Sets the class resolver to be use
+     */
+    void setClassResolver(ClassResolver resolver);
+
+    /**
+     * Sets the package scanning class resolver to use
+     */
+    void setPackageScanClassResolver(PackageScanClassResolver resolver);
+
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java Tue Mar  3 16:39:03 2009
@@ -131,7 +131,7 @@
 
         if (factory == null) {
             // use default
-            factory = ObjectHelper.loadClass(DEFAULT_STRATEGYFACTORY_CLASS);
+            factory = this.getCamelContext().getClassResolver().resolveClass(DEFAULT_STRATEGYFACTORY_CLASS);
             if (factory == null) {
                 throw new TypeNotPresentException(DEFAULT_STRATEGYFACTORY_CLASS + " class not found", null);
             }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Tue Mar  3 16:39:03 2009
@@ -49,6 +49,7 @@
 import org.apache.camel.processor.interceptor.Delayer;
 import org.apache.camel.processor.interceptor.TraceFormatter;
 import org.apache.camel.processor.interceptor.Tracer;
+import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.spi.ComponentResolver;
 import org.apache.camel.spi.ExchangeConverter;
 import org.apache.camel.spi.Injector;
@@ -56,6 +57,7 @@
 import org.apache.camel.spi.Language;
 import org.apache.camel.spi.LanguageResolver;
 import org.apache.camel.spi.LifecycleStrategy;
+import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.spi.TypeConverterRegistry;
@@ -101,6 +103,8 @@
     private Map<String, DataFormatType> dataFormats = new HashMap<String, DataFormatType>();
     private Class<? extends FactoryFinder> factoryFinderClass = FactoryFinder.class;
     private Map<String, RouteService> routeServices = new HashMap<String, RouteService>();
+    private ClassResolver classResolver;
+    private PackageScanClassResolver packageScanClassResolver;
 
     public DefaultCamelContext() {
         name = NAME_PREFIX + ++nameSuffix;
@@ -128,6 +132,21 @@
                 lifecycleStrategy = new DefaultLifecycleStrategy();
             }
         }
+
+        if (classResolver == null) {
+            classResolver = new DefaultClassResolver();
+        }
+
+        if (packageScanClassResolver == null) {
+            // use WebSphere specific resolver if running on WebSphere
+            if (WebSpherePacakageScanClassResolver.isWebSphereClassLoader(this.getClass().getClassLoader())) {
+                LOG.info("Using WebSphere specific PackageScanClassResolver");
+                packageScanClassResolver = new WebSpherePacakageScanClassResolver("META-INF/services/org/apache/camel/TypeConverter");
+            } else {
+                packageScanClassResolver = new DefaultPackageScanClassResolver();
+            }
+
+        }
     }
 
     /**
@@ -764,9 +783,7 @@
         }
     }
 
-
-
-    protected synchronized  void doStop() throws Exception {
+    protected synchronized void doStop() throws Exception {
         LOG.info("Apache Camel " + getVersion() + " (CamelContext:" + getName() + ") is stopping");
         stopServices(routeServices.values());
 
@@ -779,7 +796,6 @@
         LOG.info("Apache Camel " + getVersion() + " (CamelContext:" + getName() + ") stopped");
     }
 
-
     /**
      * Lets force some lazy initialization to occur upfront before we start any
      * components and create routes
@@ -802,7 +818,7 @@
      * Lazily create a default implementation
      */
     protected TypeConverter createTypeConverter() {
-        DefaultTypeConverter answer = new DefaultTypeConverter(getInjector());
+        DefaultTypeConverter answer = new DefaultTypeConverter(packageScanClassResolver, getInjector());
         typeConverterRegistry = answer;
         return answer;
     }
@@ -910,9 +926,23 @@
         } catch (Exception e) {
             throw new RuntimeCamelException(e);
         }
+    }
+
+    public ClassResolver getClassResolver() {
+        return classResolver;
+    }
+
+    public void setClassResolver(ClassResolver classResolver) {
+        this.classResolver = classResolver;
+    }
 
+    public PackageScanClassResolver getPackageScanClassResolver() {
+        return packageScanClassResolver;
     }
 
+    public void setPackageScanClassResolver(PackageScanClassResolver packageScanClassResolver) {
+        this.packageScanClassResolver = packageScanClassResolver;
+    }
 
     protected synchronized String getEndpointKey(String uri, Endpoint endpoint) {
         if (endpoint.isSingleton()) {

Added: 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=749648&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java Tue Mar  3 16:39:03 2009
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+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.
+ */
+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());
+    }
+
+    @SuppressWarnings("unchecked")
+    public <T> Class<T> resolveClass(String name, Class<T> type) {
+        Class answer = loadClass(name, DefaultClassResolver.class.getClassLoader());
+        return (Class<T>) answer;
+    }
+
+    public Class resolveClass(String name, ClassLoader loader) {
+        return loadClass(name, loader);
+    }
+
+    @SuppressWarnings("unchecked")
+    public <T> Class<T> resolveClass(String name, Class<T> type, ClassLoader loader) {
+        Class answer = loadClass(name, loader);
+        return (Class<T>) answer;
+    }
+
+    public Class resolveMandatoryClass(String name) throws ClassNotFoundException {
+        Class answer = resolveClass(name);
+        if (answer == null) {
+            throw new ClassNotFoundException(name);
+        }
+        return answer;
+    }
+
+    public <T> Class<T> resolveMandatoryClass(String name, Class<T> type) throws ClassNotFoundException {
+        Class<T> answer = resolveClass(name, type);
+        if (answer == null) {
+            throw new ClassNotFoundException(name);
+        }
+        return answer;
+    }
+
+    public Class resolveMandatoryClass(String name, ClassLoader loader) throws ClassNotFoundException {
+        Class answer = resolveClass(name, loader);
+        if (answer == null) {
+            throw new ClassNotFoundException(name);
+        }
+        return answer;
+    }
+
+    public <T> Class<T> resolveMandatoryClass(String name, Class<T> type, ClassLoader loader) throws ClassNotFoundException {
+        Class<T> answer = resolveClass(name, type, loader);
+        if (answer == null) {
+            throw new ClassNotFoundException(name);
+        }
+        return answer;
+    }
+
+    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;
+    }
+
+
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultClassResolver.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java?rev=749648&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java Tue Mar  3 16:39:03 2009
@@ -0,0 +1,460 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+
+import org.apache.camel.spi.PackageScanClassResolver;
+import org.apache.camel.spi.PackageScanFilter;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Default implement of {@link org.apache.camel.spi.PackageScanClassResolver}
+ */
+public class DefaultPackageScanClassResolver implements PackageScanClassResolver {
+
+    public static class IsA implements PackageScanFilter {
+        private Class parent;
+
+        public IsA(Class parentType) {
+            this.parent = parentType;
+        }
+
+        public boolean matches(Class type) {
+            return type != null && parent.isAssignableFrom(type);
+        }
+
+        @Override
+        public String toString() {
+            return "is assignable to " + parent.getSimpleName();
+        }
+    }
+
+    public static class AnnotatedWith implements PackageScanFilter {
+        private Class<? extends Annotation> annotation;
+        private boolean checkMetaAnnotations;
+
+        public AnnotatedWith(Class<? extends Annotation> annotation) {
+            this(annotation, false);
+        }
+
+        public AnnotatedWith(Class<? extends Annotation> annotation, boolean checkMetaAnnotations) {
+            this.annotation = annotation;
+            this.checkMetaAnnotations = checkMetaAnnotations;
+        }
+
+        public boolean matches(Class type) {
+            return type != null && ObjectHelper.hasAnnotation(type, annotation, checkMetaAnnotations);
+        }
+
+        @Override
+        public String toString() {
+            return "annotated with @" + annotation.getSimpleName();
+        }
+    }
+
+    /**
+     * A Test that checks to see if each class is annotated with a specific
+     * annotation. If it is, then the test returns true, otherwise false.
+     */
+    public static class AnnotatedWithAny implements PackageScanFilter {
+        private Set<Class<? extends Annotation>> annotations;
+        private boolean checkMetaAnnotations;
+
+        public AnnotatedWithAny(Set<Class<? extends Annotation>> annotations) {
+            this(annotations, false);
+        }
+
+        public AnnotatedWithAny(Set<Class<? extends Annotation>> annotations, boolean checkMetaAnnotations) {
+            this.annotations = annotations;
+            this.checkMetaAnnotations = checkMetaAnnotations;
+        }
+
+        public boolean matches(Class type) {
+            if (type == null) {
+                return false;
+            }
+            for (Class<? extends Annotation> annotation : annotations) {
+                if (ObjectHelper.hasAnnotation(type, annotation, checkMetaAnnotations)) {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        @Override
+        public String toString() {
+            return "annotated with any @[" + annotations + "]";
+        }
+    }
+
+    protected static final transient Log LOG = LogFactory.getLog(DefaultPackageScanClassResolver.class);
+    private Set<ClassLoader> classLoaders;
+
+    public void addClassLoader(ClassLoader classLoader) {
+        getClassLoaders().add(classLoader);
+    }
+
+    public Set<ClassLoader> getClassLoaders() {
+        if (classLoaders == null) {
+            classLoaders = new HashSet<ClassLoader>();
+            ClassLoader ccl = Thread.currentThread().getContextClassLoader();
+            if (ccl != null) {
+                classLoaders.add(ccl);
+            }
+            classLoaders.add(DefaultPackageScanClassResolver.class.getClassLoader());
+        }
+        return classLoaders;
+    }
+
+    public void setClassLoaders(Set<ClassLoader> classLoaders) {
+        this.classLoaders = classLoaders;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Set<Class> findAnnotated(Class<? extends Annotation> annotation, String... packageNames) {
+        if (packageNames == null) {
+            return Collections.EMPTY_SET;
+        }
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Searching for annotations of " + annotation.getName() + " in packages: " + Arrays.asList(packageNames));
+        }
+
+        PackageScanFilter test = new AnnotatedWith(annotation, true);
+        Set<Class> classes = new LinkedHashSet<Class>();
+        for (String pkg : packageNames) {
+            find(test, pkg, classes);
+        }
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Found: " + classes);
+        }
+
+        return classes;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Set<Class> findAnnotated(Set<Class<? extends Annotation>> annotations, String... packageNames) {
+        if (packageNames == null) {
+            return Collections.EMPTY_SET;
+        }
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Searching for annotations of " + annotations + " in packages: " + Arrays.asList(packageNames));
+        }
+
+        PackageScanFilter test = new AnnotatedWithAny(annotations, true);
+        Set<Class> classes = new LinkedHashSet<Class>();
+        for (String pkg : packageNames) {
+            find(test, pkg, classes);
+        }
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Found: " + classes);
+        }
+
+        return classes;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Set<Class> findImplementations(Class parent, String... packageNames) {
+        if (packageNames == null) {
+            return Collections.EMPTY_SET;
+        }
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Searching for implementations of " + parent.getName() + " in packages: " + Arrays.asList(packageNames));
+        }
+
+        PackageScanFilter test = new IsA(parent);
+        Set<Class> classes = new LinkedHashSet<Class>();
+        for (String pkg : packageNames) {
+            find(test, pkg, classes);
+        }
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Found: " + classes);
+        }
+
+        return classes;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Set<Class> findByFilter(PackageScanFilter filter, String... packageNames) {
+        if (packageNames == null) {
+            return Collections.EMPTY_SET;
+        }
+
+        Set<Class> classes = new LinkedHashSet<Class>();
+        for (String pkg : packageNames) {
+            find(filter, pkg, classes);
+        }
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Found: " + classes);
+        }
+
+        return classes;
+    }
+
+
+    protected void find(PackageScanFilter test, String packageName, Set<Class> classes) {
+        packageName = packageName.replace('.', '/');
+
+        Set<ClassLoader> set = getClassLoaders();
+
+        for (ClassLoader classLoader : set) {            
+            find(test, packageName, classLoader, classes);
+        }
+    }
+
+    protected void find(PackageScanFilter test, String packageName, ClassLoader loader, Set<Class> classes) {
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Searching for: " + test + " in package: " + packageName + " using classloader: "
+                    + loader.getClass().getName());
+        }
+
+        Enumeration<URL> urls;
+        try {
+            urls = getResources(loader, packageName);
+            if (!urls.hasMoreElements()) {
+                LOG.trace("No URLs returned by classloader");
+            }
+        } catch (IOException ioe) {
+            LOG.warn("Could not read package: " + packageName, ioe);
+            return;
+        }
+
+        while (urls.hasMoreElements()) {
+            URL url = null;
+            try {
+                url = urls.nextElement();
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("URL from classloader: " + url);
+                }
+
+                String urlPath = url.getFile();
+                urlPath = URLDecoder.decode(urlPath, "UTF-8");
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Decoded urlPath: " + urlPath);
+                }
+
+                // If it's a file in a directory, trim the stupid file: spec
+                if (urlPath.startsWith("file:")) {
+                    urlPath = urlPath.substring(5);
+                }
+
+                // osgi bundles should be skipped
+                if (url.toString().startsWith("bundle:") || urlPath.startsWith("bundle:")) {
+                    LOG.trace("It's a virtual osgi bundle, skipping");
+                    continue;
+                }
+
+                // Else it's in a JAR, grab the path to the jar
+                if (urlPath.indexOf('!') > 0) {
+                    urlPath = urlPath.substring(0, urlPath.indexOf('!'));
+                }
+
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Scanning for classes in [" + urlPath + "] matching criteria: " + test);
+                }
+
+                File file = new File(urlPath);
+                if (file.isDirectory()) {
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Loading from directory: " + file);
+                    }
+                    loadImplementationsInDirectory(test, packageName, file, classes);
+                } else {
+                    InputStream stream;
+                    if (urlPath.startsWith("http:")) {
+                        // load resources using http such as java webstart
+                        LOG.debug("The current jar is accessed via http");
+                        URL urlStream = new URL(urlPath);
+                        URLConnection con = urlStream.openConnection();
+                        // disable cache mainly to avoid jar file locking on Windows
+                        con.setUseCaches(false);
+                        stream = con.getInputStream();
+                    } else {
+                        stream = new FileInputStream(file);
+                    }
+
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Loading from jar: " + file);
+                    }
+                    loadImplementationsInJar(test, packageName, stream, urlPath, classes);
+                }
+            } catch (IOException ioe) {
+                LOG.warn("Could not read entries in url: " + url, ioe);
+            }
+        }
+    }
+
+    /**
+     * Strategy to get the resources by the given classloader.
+     * <p/>
+     * Notice that in WebSphere platforms there is a {@link org.apache.camel.util.WebSphereResolverUtil}
+     * to take care of WebSphere's odditiy of resource loading.
+     *
+     * @param loader  the classloader
+     * @param packageName   the packagename for the package to load
+     * @return  URL's for the given package
+     * @throws IOException is thrown by the classloader
+     */
+    protected Enumeration<URL> getResources(ClassLoader loader, String packageName) throws IOException {
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Getting resource URL for package: " + packageName + " with classloader: " + loader);
+        }
+        return loader.getResources(packageName);
+    }
+
+
+
+
+    /**
+     * Finds matches in a physical directory on a filesystem. Examines all files
+     * within a directory - if the File object is not a directory, and ends with
+     * <i>.class</i> the file is loaded and tested to see if it is acceptable
+     * according to the Test. Operates recursively to find classes within a
+     * folder structure matching the package structure.
+     *
+     * @param test     a Test used to filter the classes that are discovered
+     * @param parent   the package name up to this directory in the package
+     *                 hierarchy. E.g. if /classes is in the classpath and we wish to
+     *                 examine files in /classes/org/apache then the values of
+     *                 <i>parent</i> would be <i>org/apache</i>
+     * @param location a File object representing a directory
+     */
+    private void loadImplementationsInDirectory(PackageScanFilter test, String parent, File location, Set<Class> classes) {
+        File[] files = location.listFiles();
+        StringBuilder builder = null;
+
+        for (File file : files) {
+            builder = new StringBuilder(100);
+            String name = file.getName();
+            if (name != null) {
+                name = name.trim();
+                builder.append(parent).append("/").append(name);
+                String packageOrClass = parent == null ? name : builder.toString();
+
+                if (file.isDirectory()) {
+                    loadImplementationsInDirectory(test, packageOrClass, file, classes);
+                } else if (name.endsWith(".class")) {
+                    addIfMatching(test, packageOrClass, classes);
+                }
+            }
+        }
+    }
+
+    /**
+     * Finds matching classes within a jar files that contains a folder
+     * structure matching the package structure. If the File is not a JarFile or
+     * does not exist a warning will be logged, but no error will be raised.
+     *
+     * @param test    a Test used to filter the classes that are discovered
+     * @param parent  the parent package under which classes must be in order to
+     *                be considered
+     * @param stream  the inputstream of the jar file to be examined for classes
+     * @param urlPath the url of the jar file to be examined for classes
+     */
+    private void loadImplementationsInJar(PackageScanFilter test, String parent, InputStream stream, String urlPath, Set<Class> classes) {
+        JarInputStream jarStream = null;
+        try {
+            jarStream = new JarInputStream(stream);
+
+            JarEntry entry;
+            while ((entry = jarStream.getNextJarEntry()) != null) {
+                String name = entry.getName();
+                if (name != null) {
+                    name = name.trim();
+                    if (!entry.isDirectory() && name.startsWith(parent) && name.endsWith(".class")) {
+                        addIfMatching(test, name, classes);
+                    }
+                }
+            }
+        } catch (IOException ioe) {
+            LOG.error("Could not search jar file '" + urlPath + "' for classes matching criteria: " + test
+                + " due to an IOException: " + ioe.getMessage(), ioe);
+        } finally {
+            ObjectHelper.close(jarStream, urlPath, LOG);
+        }
+    }
+
+    /**
+     * Add the class designated by the fully qualified class name provided to
+     * the set of resolved classes if and only if it is approved by the Test
+     * supplied.
+     *
+     * @param test the test used to determine if the class matches
+     * @param fqn  the fully qualified name of a class
+     */
+    @SuppressWarnings("unchecked")
+    protected void addIfMatching(PackageScanFilter test, String fqn, Set<Class> classes) {
+        try {
+            String externalName = fqn.substring(0, fqn.indexOf('.')).replace('/', '.');
+            Set<ClassLoader> set = getClassLoaders();
+            boolean found = false;
+            for (ClassLoader classLoader : set) {
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Testing for class " + externalName + " matches criteria [" + test + "]");
+                }
+                try {
+                    Class type = classLoader.loadClass(externalName);
+                    if (test.matches(type)) {
+                        if (LOG.isTraceEnabled()) {
+                            LOG.trace("Found class: " + type + " in classloader: " + classLoader);
+                        }
+                        classes.add(type);
+                    }
+                    found = true;
+                    break;
+                } catch (ClassNotFoundException e) {
+                    LOG.debug("Could not find class '" + fqn + "' in classloader: " + classLoader
+                        + ". Reason: " + e, e);
+                } catch (NoClassDefFoundError e) {
+                    LOG.debug("Could not find the class defintion '" + fqn + "' in classloader: " + classLoader
+                              + ". Reason: " + e, e);
+                }
+            }
+            if (!found) {
+                LOG.warn("Could not find class '" + fqn + "' in any classloaders: " + set);
+            }
+        } catch (Throwable t) {
+            LOG.warn("Could not examine class '" + fqn + "' due to a " + t.getClass().getName()
+                + " with message: " + t.getMessage(), t);
+        }
+    }
+
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ReportingTypeConverterLoader.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ReportingTypeConverterLoader.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ReportingTypeConverterLoader.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ReportingTypeConverterLoader.java Tue Mar  3 16:39:03 2009
@@ -24,6 +24,7 @@
 
 import org.apache.camel.TypeConverter;
 import org.apache.camel.impl.converter.AnnotationTypeConverterLoader;
+import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.TypeConverterRegistry;
 import org.apache.camel.util.ObjectHelper;
 
@@ -46,6 +47,10 @@
     };
     private List<TypeMapping> typeMappings = new ArrayList<TypeMapping>();
 
+    public ReportingTypeConverterLoader(PackageScanClassResolver resolver) {
+        super(resolver);
+    }
+
     public TypeMapping[] getTypeConversions() {
         Collections.sort(typeMappings, COMPARE_LAST_LOADED_FIRST);
         return typeMappings.toArray(new TypeMapping[typeMappings.size()]);

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/WebSpherePacakageScanClassResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/WebSpherePacakageScanClassResolver.java?rev=749648&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/WebSpherePacakageScanClassResolver.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/WebSpherePacakageScanClassResolver.java Tue Mar  3 16:39:03 2009
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+
+/**
+ * WebSphere specific resolver to handle loading annotated resources in JAR files.
+ */
+public class WebSpherePacakageScanClassResolver extends DefaultPackageScanClassResolver {
+
+    private String resourcePath;
+
+    /**
+     * Constructor.
+     *
+     * @param resourcePath  the fixed resource path to use for fetching camel jars in WebSphere.
+     */
+    public WebSpherePacakageScanClassResolver(String resourcePath) {
+        this.resourcePath = resourcePath;
+    }
+
+    /**
+     * Is the classloader from IBM and thus the WebSphere platform?
+     *
+     * @param loader  the classloader
+     * @return  <tt>true</tt> if IBM classloader, <tt>false</tt> otherwise.
+     */
+    public static boolean isWebSphereClassLoader(ClassLoader loader) {
+        return loader.getClass().getName().startsWith("com.ibm");
+    }
+
+    /**
+     * Overloaded to handle specific problem with getting resources on the IBM WebSphere platform.
+     * <p/>
+     * WebSphere can <b>not</b> load resources if the resource to load is a folder name, such as a
+     * packagename, you have to explicit name a resource that is a file.
+     *
+     * @param loader  the classloader
+     * @param packageName   the packagename for the package to load
+     * @return  URL's for the given package
+     * @throws java.io.IOException is thrown by the classloader
+     */
+    @Override
+    @SuppressWarnings("unchecked")
+    protected Enumeration<URL> getResources(ClassLoader loader, String packageName) throws IOException {
+        // try super first, just in vase
+        Enumeration<URL> enumeration = super.getResources(loader, packageName);
+        if (!enumeration.hasMoreElements()) {
+            LOG.trace("Using WebSphere workaround to load the camel jars with the annotated converters.");
+            // Special WebSphere trick to load a file that exists in the JAR and then let it go from there.
+            // The trick is that we just need the URL's for the .jars that contains the type
+            // converters that is annotated. So by searching for this resource WebSphere is able to find
+            // it and return the URL to the .jar file with the resource. Then the default ResolverUtil
+            // can take it from there and find the classes that are annotated.
+            enumeration = loader.getResources(resourcePath);
+        }
+
+        return enumeration;
+    }
+
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/WebSpherePacakageScanClassResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/WebSpherePacakageScanClassResolver.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java Tue Mar  3 16:39:03 2009
@@ -34,10 +34,9 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.FallbackConverter;
 import org.apache.camel.TypeConverter;
+import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.TypeConverterRegistry;
 import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.ResolverUtil;
-import org.apache.camel.util.WebSphereResolverUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -50,28 +49,17 @@
 public class AnnotationTypeConverterLoader implements TypeConverterLoader {
     public static final String META_INF_SERVICES = "META-INF/services/org/apache/camel/TypeConverter";
     private static final transient Log LOG = LogFactory.getLog(AnnotationTypeConverterLoader.class);
-    protected ResolverUtil resolver;
+    protected PackageScanClassResolver resolver;
     private Set<Class> visitedClasses = new HashSet<Class>();
 
-    public AnnotationTypeConverterLoader() {
-        // use WebSphere specific resolver if running on WebSphere
-        if (WebSphereResolverUtil.isWebSphereClassLoader(this.getClass().getClassLoader())) {
-            LOG.info("Using WebSphere specific ResolverUtil");
-            resolver = new WebSphereResolverUtil(META_INF_SERVICES);
-        } else {
-            resolver = new ResolverUtil();
-        }
-    }
-
-    public AnnotationTypeConverterLoader(ResolverUtil resolverUtil) {
-        this.resolver = resolverUtil;
+    public AnnotationTypeConverterLoader(PackageScanClassResolver resolver) {
+        this.resolver = resolver;
     }
 
     @SuppressWarnings("unchecked")
     public void load(TypeConverterRegistry registry) throws Exception {
         String[] packageNames = findPackageNames();
-        resolver.findAnnotated(Converter.class, packageNames);
-        Set<Class> classes = resolver.getClasses();
+        Set<Class> classes = resolver.findAnnotated(Converter.class, packageNames);
         for (Class type : classes) {
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Loading converter class: " + ObjectHelper.name(type));

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java Tue Mar  3 16:39:03 2009
@@ -30,6 +30,7 @@
 import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.spi.Injector;
+import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.TypeConverterAware;
 import org.apache.camel.spi.TypeConverterRegistry;
 import org.apache.camel.util.FactoryFinder;
@@ -54,9 +55,11 @@
     private List<TypeConverter> fallbackConverters = new ArrayList<TypeConverter>();
     private boolean loaded;
 
-    public DefaultTypeConverter(Injector injector) {
-        typeConverterLoaders.add(new AnnotationTypeConverterLoader());
+    public DefaultTypeConverter(PackageScanClassResolver resolver, Injector injector) {
         this.injector = injector;
+
+        typeConverterLoaders.add(new AnnotationTypeConverterLoader(resolver));
+
         // add to string first as it will then be last in the last as to string can nearly
         // always convert something to a string so we want it only as the last resort
         addFallbackTypeConverter(new ToStringTypeConverter());

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java Tue Mar  3 16:39:03 2009
@@ -26,7 +26,6 @@
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.util.IntrospectionSupport;
 import org.apache.camel.util.ObjectHelper;
-import static org.apache.camel.util.ObjectHelper.notNull;
 
 /**
  * Represents the base XML type for DataFormat.
@@ -61,7 +60,7 @@
      */
     public static DataFormat getDataFormat(RouteContext routeContext, DataFormatType type, String ref) {
         if (type == null) {
-            notNull(ref, "ref or dataFormatType");
+            ObjectHelper.notNull(ref, "ref or dataFormatType");
 
             DataFormat dataFormat = lookup(routeContext, ref, DataFormat.class);
             if (dataFormat == null) {
@@ -109,7 +108,7 @@
     @SuppressWarnings("unchecked")
     protected DataFormat createDataFormat(RouteContext routeContext) {
         if (dataFormatTypeName != null) {
-            Class type = ObjectHelper.loadClass(dataFormatTypeName, getClass().getClassLoader());
+            Class type = routeContext.getCamelContext().getClassResolver().resolveClass(dataFormatTypeName);
             if (type == null) {
                 throw new IllegalArgumentException("The class " + dataFormatTypeName + " is not on the classpath! Cannot use the dataFormat " + this);
             }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/loadbalancer/LoadBalancerType.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/loadbalancer/LoadBalancerType.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/loadbalancer/LoadBalancerType.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/loadbalancer/LoadBalancerType.java Tue Mar  3 16:39:03 2009
@@ -31,7 +31,6 @@
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.util.IntrospectionSupport;
 import org.apache.camel.util.ObjectHelper;
-import static org.apache.camel.util.ObjectHelper.notNull;
 
 /**
  * Represents an XML &lt;loadBalance/&gt; element
@@ -58,7 +57,7 @@
 
     public static LoadBalancer getLoadBalancer(RouteContext routeContext, LoadBalancerType type, String ref) {
         if (type == null) {
-            notNull(ref, "ref or LoadBalancerType");
+            ObjectHelper.notNull(ref, "ref or LoadBalancerType");
             LoadBalancer loadBalancer = routeContext.lookup(ref, LoadBalancer.class);
             if (loadBalancer instanceof LoadBalancerType) {
                 type = (LoadBalancerType) loadBalancer;
@@ -103,7 +102,7 @@
     @SuppressWarnings("unchecked")
     protected LoadBalancer createLoadBalancer(RouteContext routeContext) {
         if (loadBalancerTypeName != null) {
-            Class type = ObjectHelper.loadClass(loadBalancerTypeName, getClass().getClassLoader());
+            Class type = routeContext.getCamelContext().getClassResolver().resolveClass(loadBalancerTypeName);
             if (type == null) {
                 throw new IllegalArgumentException("Cannot find class: " + loadBalancerTypeName + " in the classpath");
             }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java Tue Mar  3 16:39:03 2009
@@ -173,7 +173,7 @@
                 // load the jpa event class
                 synchronized (this) {
                     if (jpaTraceEventMessageClass == null) {
-                        jpaTraceEventMessageClass = ObjectHelper.loadClass(JPA_TRACE_EVENT_MESSAGE);
+                        jpaTraceEventMessageClass = exchange.getContext().getClassResolver().resolveClass(JPA_TRACE_EVENT_MESSAGE);
                         if (jpaTraceEventMessageClass == null) {
                             throw new IllegalArgumentException("Cannot find class: " + JPA_TRACE_EVENT_MESSAGE
                                     + ". Make sure camel-jpa.jar is in the classpath.");
@@ -273,4 +273,4 @@
         }
     }
 
-}
\ No newline at end of file
+}

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ClassResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ClassResolver.java?rev=749648&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ClassResolver.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ClassResolver.java Tue Mar  3 16:39:03 2009
@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spi;
+
+/**
+ * A class resolver for loading classes in a loosly coupled manner to cater for different platforms such
+ * as standalone, web container, j2ee container and OSGi platforms.
+ */
+public interface ClassResolver {
+
+    /**
+     * Resolves the given class by its name
+     *
+     * @param name full qualified name of class
+     * @return the class if resolved, <tt>null</tt> if not found.
+     */
+    Class resolveClass(String name);
+
+    /**
+     * Resolves the given class by its name
+     *
+     * @param name full qualified name of class
+     * @param type the expected type of the class
+     * @return the class if resolved, <tt>null</tt> if not found.
+     */
+    <T> Class<T> resolveClass(String name, Class<T> type);
+
+    /**
+     * Resolves the given class by its name
+     *
+     * @param name full qualified name of class
+     * @param loader use the provided class loader
+     * @return the class if resolved, <tt>null</tt> if not found.
+     */
+    Class resolveClass(String name, ClassLoader loader);
+
+    /**
+     * Resolves the given class by its name
+     *
+     * @param name full qualified name of class
+     * @param type the expected type of the class
+     * @param loader use the provided class loader
+     * @return the class if resolved, <tt>null</tt> if not found.
+     */
+    <T> Class<T> resolveClass(String name, Class<T> type, ClassLoader loader);
+
+    /**
+     * Resolves the given class by its name
+     *
+     * @param name full qualified name of class
+     * @return the class if resolved, <tt>null</tt> if not found.
+     * @throws ClassNotFoundException is thrown if class not found
+     */
+    Class resolveMandatoryClass(String name) throws ClassNotFoundException;
+
+    /**
+     * Resolves the given class by its name
+     *
+     * @param name full qualified name of class
+     * @param type the expected type of the class
+     * @return the class if resolved, <tt>null</tt> if not found.
+     * @throws ClassNotFoundException is thrown if class not found
+     */
+    <T> Class<T> resolveMandatoryClass(String name, Class<T> type) throws ClassNotFoundException;
+
+    /**
+     * Resolves the given class by its name
+     *
+     * @param name full qualified name of class
+     * @return the class if resolved, <tt>null</tt> if not found.
+     * @param loader use the provided class loader
+     * @throws ClassNotFoundException is thrown if class not found
+     */
+    Class resolveMandatoryClass(String name, ClassLoader loader) throws ClassNotFoundException;
+
+    /**
+     * Resolves the given class by its name
+     *
+     * @param name full qualified name of class
+     * @param type the expected type of the class
+     * @param loader use the provided class loader
+     * @return the class if resolved, <tt>null</tt> if not found.
+     * @throws ClassNotFoundException is thrown if class not found
+     */
+    <T> Class<T> resolveMandatoryClass(String name, Class<T> type, ClassLoader loader) throws ClassNotFoundException;
+
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ClassResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ClassResolver.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PackageScanClassResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PackageScanClassResolver.java?rev=749648&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PackageScanClassResolver.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PackageScanClassResolver.java Tue Mar  3 16:39:03 2009
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spi;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+/**
+ * A resolver that can find resources based on package scanning.
+ */
+public interface PackageScanClassResolver {
+
+    /**
+     * Sets the ClassLoader instances that should be used when scanning for
+     * classes. If none is set then the context classloader will be used.
+     *
+     * @param classLoaders loaders to use when scanning for classes
+     */
+    void setClassLoaders(Set<ClassLoader> classLoaders);
+
+    /**
+     * Gets the ClassLoader instances that should be used when scanning for classes.
+     *
+     * @return the class loaders to use
+     */
+    Set<ClassLoader> getClassLoaders();
+
+    /**
+     * Adds the class loader to the existing loaders
+     *
+     * @param classLoader the loader to add
+     */
+    void addClassLoader(ClassLoader classLoader);
+
+    /**
+     * Attempts to discover classes that are annotated with to the annotation.
+     *
+     * @param annotation   the annotation that should be present on matching classes
+     * @param packageNames one or more package names to scan (including subpackages) for classes
+     * @return the classes found, returns an empty set if none found
+     */
+    Set<Class> findAnnotated(Class<? extends Annotation> annotation, String... packageNames);
+
+    /**
+     * Attempts to discover classes that are annotated with to the annotation.
+     *
+     * @param annotations   the annotations that should be present (any of them) on matching classes
+     * @param packageNames one or more package names to scan (including subpackages) for classes
+     * @return the classes found, returns an empty set if none found
+     */
+    Set<Class> findAnnotated(Set<Class<? extends Annotation>> annotations, String... packageNames);
+
+    /**
+     * Attempts to discover classes that are assignable to the type provided. In
+     * the case that an interface is provided this method will collect
+     * implementations. In the case of a non-interface class, subclasses will be
+     * collected.
+     *
+     * @param parent       the class of interface to find subclasses or implementations of
+     * @param packageNames one or more package names to scan (including subpackages) for classes
+     * @return the classes found, returns an empty set if none found
+     */
+    Set<Class> findImplementations(Class parent, String... packageNames);
+
+    /**
+     * Attemsp to discover classes filter by the provided filter
+     *
+     * @param fiter  filter to filter desired classes.
+     * @param packageNames one or more package names to scan (including subpackages) for classes
+     * @return the classes found, returns an empty set if none found
+     */
+    Set<Class> findByFilter(PackageScanFilter fiter, String... packageNames);
+
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PackageScanClassResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PackageScanClassResolver.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PackageScanFilter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PackageScanFilter.java?rev=749648&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PackageScanFilter.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PackageScanFilter.java Tue Mar  3 16:39:03 2009
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spi;
+
+/**
+ * Filter that can be used with the {@link org.apache.camel.spi.PackageScanClassResolver} resolver.
+ */
+public interface PackageScanFilter {
+
+    /**
+     * Does the given class match
+     *
+     * @param type the class
+     * @return true to include this class, false to skip it.
+     */
+    boolean matches(Class type);
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PackageScanFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PackageScanFilter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java Tue Mar  3 16:39:03 2009
@@ -32,6 +32,8 @@
  * Finder to find factories from the resource classpath, usually <b>META-INF/services/org/apache/camel/</b>.
  */
 public class FactoryFinder {
+    // TODO: Extract interface to SPI
+
     protected final ConcurrentHashMap<String, Class> classMap = new ConcurrentHashMap<String, Class>();
     private final String path;    
 

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=749648&r1=749647&r2=749648&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 Tue Mar  3 16:39:03 2009
@@ -490,6 +490,7 @@
      *
      * @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());
@@ -503,6 +504,7 @@
      * @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
@@ -530,6 +532,7 @@
      * @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/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java Tue Mar  3 16:39:03 2009
@@ -21,7 +21,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLDecoder;
@@ -67,6 +66,7 @@
  * </pre>
  *
  * @author Tim Fennell
+ * @deprecated please use {@link org.apache.camel.spi.PackageScanClassResolver} instead.
  */
 public class ResolverUtil<T> {
     protected static final transient Log LOG = LogFactory.getLog(ResolverUtil.class);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/WebSphereResolverUtil.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/WebSphereResolverUtil.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/WebSphereResolverUtil.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/WebSphereResolverUtil.java Tue Mar  3 16:39:03 2009
@@ -22,6 +22,7 @@
 
 /**
  * WebSphere specific resolver util to handle loading annotated resources in JAR files.
+ * @deprecated
  */
 public class WebSphereResolverUtil extends ResolverUtil {
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java Tue Mar  3 16:39:03 2009
@@ -33,6 +33,7 @@
 import org.apache.camel.TypeConverter;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.impl.DefaultPackageScanClassResolver;
 import org.apache.camel.impl.converter.DefaultTypeConverter;
 import org.apache.camel.util.IntrospectionSupport;
 import org.apache.camel.util.ReflectionInjector;
@@ -45,7 +46,7 @@
 public class ConverterTest extends TestCase {
     private static final transient Log LOG = LogFactory.getLog(ConverterTest.class);
 
-    protected TypeConverter converter = new DefaultTypeConverter(new ReflectionInjector());
+    protected TypeConverter converter = new DefaultTypeConverter(new DefaultPackageScanClassResolver(), new ReflectionInjector());
 
     public static class IntegerPropertyEditor extends PropertyEditorSupport {
         public void setAsText(String text) throws IllegalArgumentException {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/converter/JaxpTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/JaxpTest.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/converter/JaxpTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/converter/JaxpTest.java Tue Mar  3 16:39:03 2009
@@ -28,6 +28,7 @@
 
 import junit.framework.TestCase;
 import org.apache.camel.TypeConverter;
+import org.apache.camel.impl.DefaultPackageScanClassResolver;
 import org.apache.camel.impl.converter.DefaultTypeConverter;
 import org.apache.camel.util.ReflectionInjector;
 import org.apache.commons.logging.Log;
@@ -39,7 +40,7 @@
  */
 public class JaxpTest extends TestCase {
     private static final transient Log LOG = LogFactory.getLog(JaxpTest.class);
-    protected TypeConverter converter = new DefaultTypeConverter(new ReflectionInjector());
+    protected TypeConverter converter = new DefaultTypeConverter(new DefaultPackageScanClassResolver(), new ReflectionInjector());
 
     public void testConvertToDocument() throws Exception {
         Document document = converter

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/converter/StringSourceTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/StringSourceTest.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/converter/StringSourceTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/converter/StringSourceTest.java Tue Mar  3 16:39:03 2009
@@ -24,6 +24,7 @@
 import junit.framework.TestCase;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.camel.impl.DefaultPackageScanClassResolver;
 import org.apache.camel.impl.converter.DefaultTypeConverter;
 import org.apache.camel.util.ReflectionInjector;
 
@@ -31,7 +32,7 @@
  * @version $Revision$
  */
 public class StringSourceTest extends TestCase {
-    protected TypeConverter converter = new DefaultTypeConverter(new ReflectionInjector());
+    protected TypeConverter converter = new DefaultTypeConverter(new DefaultPackageScanClassResolver(), new ReflectionInjector());
     protected String expectedBody = "<hello>world!</hello>";
 
     public void testSerialization() throws Exception {

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java Tue Mar  3 16:39:03 2009
@@ -25,6 +25,7 @@
 
 import org.apache.camel.dataformat.bindy.util.AnnotationModelLoader;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -34,15 +35,15 @@
  */
 public abstract class BindyAbstractFactory implements BindyFactory {
     private static final transient Log LOG = LogFactory.getLog(BindyAbstractFactory.class);
-    protected Set<Class<?>> models;
+    protected Set<Class> models;
     protected Map<String, Field> mapAnnotedLinkField = new LinkedHashMap<String, Field>();    
 
     private AnnotationModelLoader modelsLoader;
     
     private String packageName;
 
-    public BindyAbstractFactory(String packageName) throws Exception {
-        modelsLoader = new AnnotationModelLoader();
+    public BindyAbstractFactory(PackageScanClassResolver resolver, String packageName) throws Exception {
+        this.modelsLoader = new AnnotationModelLoader(resolver);
         this.packageName = packageName;
         initModel();
     }

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java Tue Mar  3 16:39:03 2009
@@ -27,6 +27,7 @@
 import org.apache.camel.dataformat.bindy.annotation.DataField;
 import org.apache.camel.dataformat.bindy.annotation.Link;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -46,9 +47,8 @@
     private String separator;
     private boolean skipFirstLine;
 
-    public BindyCsvFactory(String packageName) throws Exception {
-        
-        super(packageName);
+    public BindyCsvFactory(PackageScanClassResolver resolver, String packageName) throws Exception {
+        super(resolver, packageName);
         
         // initialize specific parameters of the csv model
         initCsvModel();

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java Tue Mar  3 16:39:03 2009
@@ -32,6 +32,7 @@
 import org.apache.camel.dataformat.bindy.annotation.Message;
 import org.apache.camel.dataformat.bindy.util.ConvertSeparator;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -52,9 +53,9 @@
     private String keyValuePairSeparator;
     private String pairSeparator;
 
-    public BindyKeyValuePairFactory(String packageName) throws Exception {
+    public BindyKeyValuePairFactory(PackageScanClassResolver resolver, String packageName) throws Exception {
         
-        super(packageName);
+        super(resolver, packageName);
         
         // Initialize what is specific to Key Value Pair model
         initKeyValuePairModel();

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java Tue Mar  3 16:39:03 2009
@@ -26,8 +26,10 @@
 import java.util.Scanner;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.CamelContext;
 import org.apache.camel.dataformat.bindy.BindyCsvFactory;
 import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -51,22 +53,24 @@
 
     @SuppressWarnings("unchecked")
     public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws Exception {
+        BindyCsvFactory factory = getFactory(exchange.getContext().getPackageScanClassResolver());
         List<Map<String, Object>> models = (ArrayList<Map<String, Object>>) body;
 
         for (Map<String, Object> model : models) {
-            String result = getFactory().unbind(model);
+            String result = factory.unbind(model);
             byte[] bytes = exchange.getContext().getTypeConverter().convertTo(byte[].class, exchange, result);
             outputStream.write(bytes);
         }
     }
 
     public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
+        BindyCsvFactory factory = getFactory(exchange.getContext().getPackageScanClassResolver());
 
         // List of Pojos
         List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
 
         // Create POJO where CSV data will be stored
-        Map<String, Object> model = getFactory().factory();
+        Map<String, Object> model = factory.factory();
 
         InputStreamReader in = new InputStreamReader(inputStream);
 
@@ -74,14 +78,14 @@
         Scanner scanner = new Scanner(in);
 
         // Retrieve the separator defined to split the record
-        String separator = getFactory().getSeparator();
+        String separator = factory.getSeparator();
         ObjectHelper.notEmpty(separator, "The separator has not been defined in the annotation @Record or not instantiated during initModel.");
 
         int count = 0;
         try {
 
             // If the first line of the CSV file contains columns name, then we skip this line
-            if (getFactory().getSkipFirstLine()) {
+            if (factory.getSkipFirstLine()) {
                 scanner.nextLine();
             }
 
@@ -104,10 +108,10 @@
                 List<String> result = Arrays.asList(line.split(separator));
                 
                 // Bind data from CSV record with model classes
-                getFactory().bind(result, model);
+                factory.bind(result, model);
 
                 // Link objects together
-                getFactory().link(model);
+                factory.link(model);
 
                 // Add objects graph to the list
                 models.add(model);
@@ -130,9 +134,9 @@
     /**
      * Method used to create the singleton of the BindyCsvFactory
      */
-    public BindyCsvFactory getFactory() throws Exception {
+    public BindyCsvFactory getFactory(PackageScanClassResolver resolver) throws Exception {
         if (modelFactory == null) {
-            modelFactory = new BindyCsvFactory(this.packageName);
+            modelFactory = new BindyCsvFactory(resolver, packageName);
         }
         return modelFactory;
     }

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java Tue Mar  3 16:39:03 2009
@@ -29,6 +29,7 @@
 import org.apache.camel.dataformat.bindy.BindyCsvFactory;
 import org.apache.camel.dataformat.bindy.BindyKeyValuePairFactory;
 import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -53,23 +54,24 @@
 
     @SuppressWarnings("unchecked")
     public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws Exception {
+        BindyKeyValuePairFactory factory = getFactory(exchange.getContext().getPackageScanClassResolver());
         List<Map<String, Object>> models = (ArrayList<Map<String, Object>>) body;
         
         for (Map<String, Object> model : models) {
-
-            String result = getFactory().unbind(model);
+            String result = factory.unbind(model);
             byte[] bytes = exchange.getContext().getTypeConverter().convertTo(byte[].class, exchange, result);
             outputStream.write(bytes);
         }
     }
 
     public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
+        BindyKeyValuePairFactory factory = getFactory(exchange.getContext().getPackageScanClassResolver());
 
         // List of Pojos
         List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
 
         // Create POJO where messages data will be saved
-        Map<String, Object> model = getFactory().factory();
+        Map<String, Object> model = factory.factory();
 
         InputStreamReader in = new InputStreamReader(inputStream);
 
@@ -77,8 +79,8 @@
         Scanner scanner = new Scanner(in);
 
         // Retrieve the pair separator defined to split the record
-        ObjectHelper.notEmpty(getFactory().getPairSeparator(), "The separator has not been defined in the annotation @Message.");
-        String separator = getFactory().getPairSeparator();
+        ObjectHelper.notEmpty(factory.getPairSeparator(), "The separator has not been defined in the annotation @Message.");
+        String separator = factory.getPairSeparator();
 
         int count = 0;
         try {
@@ -102,10 +104,10 @@
                 List<String> result = Arrays.asList(line.split(separator));
                 
                 // Bind data from message with model classes
-                getFactory().bind(result, model);
+                factory.bind(result, model);
 
                 // Link objects together
-                getFactory().link(model);
+                factory.link(model);
 
                 // Add objects graph to the list
                 models.add(model);
@@ -128,9 +130,9 @@
     /**
      * Method used to create the singleton of the BindyKeyValuePairFactory
      */
-    public BindyKeyValuePairFactory getFactory() throws Exception {
+    public BindyKeyValuePairFactory getFactory(PackageScanClassResolver resolver) throws Exception {
         if (modelFactory == null) {
-            modelFactory = new BindyKeyValuePairFactory(this.packageName);
+            modelFactory = new BindyKeyValuePairFactory(resolver, this.packageName);
         }
         return modelFactory;
     }

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/AnnotationModelLoader.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/AnnotationModelLoader.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/AnnotationModelLoader.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/AnnotationModelLoader.java Tue Mar  3 16:39:03 2009
@@ -23,18 +23,18 @@
 import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
 import org.apache.camel.dataformat.bindy.annotation.Link;
 import org.apache.camel.dataformat.bindy.annotation.Message;
-import org.apache.camel.util.ResolverUtil;
+import org.apache.camel.spi.PackageScanClassResolver;
 
 /**
  * Annotation based loader for model classes with Bindy annotations.
  */
 public class AnnotationModelLoader {
 
-    private ResolverUtil<Object> resolver;
+    private PackageScanClassResolver resolver;
     private Set<Class<? extends Annotation>> annotations;
 
-    public AnnotationModelLoader() {
-        resolver = new ResolverUtil<Object>();
+    public AnnotationModelLoader(PackageScanClassResolver resolver) {
+        this.resolver = resolver;
 
         annotations = new LinkedHashSet<Class<? extends Annotation>>();
         annotations.add(CsvRecord.class);
@@ -42,9 +42,8 @@
         annotations.add(Message.class);
     }
 
-    public Set<Class<?>> loadModels(String packageName) throws Exception {
-        resolver.findAnnotated(annotations, packageName);
-        return resolver.getClasses();
+    public Set<Class> loadModels(String packageName) throws Exception {
+        return resolver.findAnnotated(annotations, packageName);
     }
 
 }

Modified: camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrConverterTest.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrConverterTest.java (original)
+++ camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrConverterTest.java Tue Mar  3 16:39:03 2009
@@ -18,12 +18,11 @@
 
 import java.io.ByteArrayInputStream;
 import java.util.Calendar;
-
 import javax.jcr.Value;
 
 import junit.framework.TestCase;
-
 import org.apache.camel.TypeConverter;
+import org.apache.camel.impl.DefaultPackageScanClassResolver;
 import org.apache.camel.impl.converter.DefaultTypeConverter;
 import org.apache.camel.util.ReflectionInjector;
 import org.apache.jackrabbit.value.BinaryValue;
@@ -36,7 +35,7 @@
  */
 public class JcrConverterTest extends TestCase {
 
-    protected TypeConverter converter = new DefaultTypeConverter(new ReflectionInjector());
+    protected TypeConverter converter = new DefaultTypeConverter(new DefaultPackageScanClassResolver(), new ReflectionInjector());
 
     public void testBooleanValueConverter() throws Exception {
         assertJcrConverterAvailable(BooleanValue.class, Boolean.TRUE);

Modified: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java (original)
+++ camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java Tue Mar  3 16:39:03 2009
@@ -17,7 +17,6 @@
 package org.apache.camel.osgi;
 
 import java.util.List;
-
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlRootElement;
@@ -26,10 +25,7 @@
 import org.apache.camel.impl.converter.AnnotationTypeConverterLoader;
 import org.apache.camel.impl.converter.DefaultTypeConverter;
 import org.apache.camel.impl.converter.TypeConverterLoader;
-import org.apache.camel.spring.RouteBuilderFinder;
 import org.apache.camel.spring.SpringCamelContext;
-import org.apache.camel.util.FactoryFinder;
-import org.apache.camel.util.ResolverUtil;
 import org.osgi.framework.BundleContext;
 import org.springframework.osgi.context.BundleContextAware;
 
@@ -51,28 +47,17 @@
     protected SpringCamelContext createContext() {
         SpringCamelContext context = super.createContext();
         if (bundleContext != null) {
+            context.setPackageScanClassResolver(new OsgiPackageScanClassResolver(bundleContext));
             context.setComponentResolver(new OsgiComponentResolver());
             context.setLanguageResolver(new OsgiLanguageResolver());
-            addOsgiAnnotationTypeConverterLoader(context, bundleContext);
             context.setFactoryFinderClass(OsgiFactoryFinder.class);
+            addOsgiAnnotationTypeConverterLoader(context);
         }
         
         return context;
     }    
     
-    /**
-     * The factory method for create the ResolverUtil
-     * @return a new instance of ResolverUtil
-     */
-    protected ResolverUtil createResolverUtil() {
-        if (bundleContext != null) {
-            return new OsgiResolverUtil(bundleContext);
-        } else {
-            return new ResolverUtil();
-        }
-    }
-    
-    protected void addOsgiAnnotationTypeConverterLoader(SpringCamelContext context, BundleContext bundleContext) {
+    protected void addOsgiAnnotationTypeConverterLoader(SpringCamelContext context) {
         DefaultTypeConverter typeConverter = (DefaultTypeConverter) context.getTypeConverter();
         List<TypeConverterLoader> typeConverterLoaders = typeConverter.getTypeConverterLoaders();
         // Remove the AnnotationTypeConverterLoader
@@ -86,7 +71,9 @@
         if (atLoader != null) {
             typeConverterLoaders.remove(atLoader);
         }
-        typeConverterLoaders.add(new OsgiAnnotationTypeConverterLoader(bundleContext));
+
+        // add our osgi annotation loader
+        typeConverterLoaders.add(new OsgiAnnotationTypeConverterLoader(context.getPackageScanClassResolver()));
     }    
     
 }



Mime
View raw message