camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r785987 - in /camel/trunk/components/camel-osgi/src: main/java/org/apache/camel/osgi/Activator.java main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java test/java/org/apache/camel/osgi/ActivatorTest.java
Date Thu, 18 Jun 2009 09:33:53 GMT
Author: ningjiang
Date: Thu Jun 18 09:33:52 2009
New Revision: 785987

URL: http://svn.apache.org/viewvc?rev=785987&view=rev
Log:
CAMEL-1729 fixed the converter loading issue in OSGi

Modified:
    camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.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/ActivatorTest.java

Modified: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java?rev=785987&r1=785986&r2=785987&view=diff
==============================================================================
--- camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java (original)
+++ camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java Thu
Jun 18 09:33:52 2009
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.URL;
+import java.util.Collection;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -59,7 +60,7 @@
         Class type;
     }
     
-    private class TypeConverterEntry {
+    public class TypeConverterEntry {
         Bundle bundle;
         URL resource;
         Set<String> converterPackages;
@@ -247,18 +248,9 @@
         return bundle;
     }
     
-    protected static synchronized String[] findTypeConverterPackageNames() {
-        LOG.trace("Finding TypeConverterPackageNames");
-        Set<String> packages = new HashSet<String>();
-        for (TypeConverterEntry entry : TYPE_CONVERTERS.values()) {
-            for (String packageName : entry.converterPackages) {
-                if (LOG.isTraceEnabled()) {
-                    LOG.trace("Found TypeConverterPackage: " + packageName);
-                }
-                packages.add(packageName);
-            }
-        }
-        return packages.toArray(new String[packages.size()]);
+    protected static synchronized TypeConverterEntry[] getTypeConverterEntries() {
+        Collection<TypeConverterEntry> entries = TYPE_CONVERTERS.values();
+        return entries.toArray(new TypeConverterEntry[entries.size()]);
     }
         
     public static synchronized Class getComponent(String name) throws Exception {

Modified: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java?rev=785987&r1=785986&r2=785987&view=diff
==============================================================================
--- camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java
(original)
+++ camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java
Thu Jun 18 09:33:52 2009
@@ -16,17 +16,39 @@
  */
 package org.apache.camel.osgi;
 
+import java.util.Set;
+
+import org.apache.camel.Converter;
 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;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public class OsgiAnnotationTypeConverterLoader extends AnnotationTypeConverterLoader {
+    
+    private static final transient Log LOG = LogFactory.getLog(OsgiAnnotationTypeConverterLoader.class);
 
     public OsgiAnnotationTypeConverterLoader(PackageScanClassResolver packageScanClassResolver)
{
         super(packageScanClassResolver);
     }
 
-    protected String[] findPackageNames() {
-        return Activator.findTypeConverterPackageNames();
+    @Override
+    public void load(TypeConverterRegistry registry) throws Exception {
+        for (Activator.TypeConverterEntry entry : Activator.getTypeConverterEntries()) {
+            OsgiPackageScanClassResolver resolver = new OsgiPackageScanClassResolver(entry.bundle.getBundleContext());
+            String[] packages = entry.converterPackages.toArray(new String[entry.converterPackages.size()]);
+            Set<Class> classes = resolver.findAnnotated(Converter.class, packages);
          
+            for (Class type : classes) {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Loading converter class: " + ObjectHelper.name(type));
+                }
+                loadConverterMethods(registry, type);
+             }
+         }
     }
+    
+    
 
 }

Modified: camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/ActivatorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/ActivatorTest.java?rev=785987&r1=785986&r2=785987&view=diff
==============================================================================
--- camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/ActivatorTest.java
(original)
+++ camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/ActivatorTest.java
Thu Jun 18 09:33:52 2009
@@ -41,10 +41,12 @@
         assertNotNull("The bean_test component should not be null", clazz);
     }
     
-    private boolean containsPackageName(String packageName, String[] packages) {
-        for (String name : packages) {
-            if (name.equals(packageName)) {
-                return true;
+    private boolean containsPackageName(String packageName, Activator.TypeConverterEntry[]
entries) {
+        for (Activator.TypeConverterEntry entry : entries) {
+            for (String name : entry.converterPackages) {
+                if (name.equals(packageName)) {            
+                    return true;
+                }
             }
         }
         return false;
@@ -52,9 +54,11 @@
     
     @Test
     public void testFindTypeConverterPackageNames() throws Exception {
-        String[] packages = Activator.findTypeConverterPackageNames();
-        assertTrue("We should find some converter packages here", packages.length > 0);
       
-        assertTrue("Here should contains org.apache.camel.osgi.test", containsPackageName("org.apache.camel.osgi.test",
packages));
+        Activator.TypeConverterEntry[] entries = Activator.getTypeConverterEntries();
+        assertTrue("We should find some converter packages here", entries.length > 0);
       
+        assertTrue("Here should contains org.apache.camel.osgi.test", containsPackageName("org.apache.camel.osgi.test",
entries));
+        assertTrue("Here should contains org.apache.camel.spring.converter", containsPackageName("org.apache.camel.spring.converter",
entries));
+        assertTrue("Here should contains org.apache.camel.osgi.test", containsPackageName("org.apache.camel.osgi.test",
entries));        
     }
 
 }



Mime
View raw message