camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r954355 - in /camel/trunk: components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiFactoryFinder.java tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OsgiFactoryFinderTest.java
Date Mon, 14 Jun 2010 03:34:50 GMT
Author: ningjiang
Date: Mon Jun 14 03:34:49 2010
New Revision: 954355

URL: http://svn.apache.org/viewvc?rev=954355&view=rev
Log:
CAMEL-2809 reverted the change of OsgiFactoryFinder

Added:
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OsgiFactoryFinderTest.java
  (with props)
Modified:
    camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiFactoryFinder.java

Modified: camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiFactoryFinder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiFactoryFinder.java?rev=954355&r1=954354&r2=954355&view=diff
==============================================================================
--- camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiFactoryFinder.java
(original)
+++ camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiFactoryFinder.java
Mon Jun 14 03:34:49 2010
@@ -30,14 +30,16 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 
 public class OsgiFactoryFinder extends DefaultFactoryFinder {
-
-    private final BundleContext bundleContext;
-    private final Bundle bundle;
+    private BundleContext bundleContext;
 
     public OsgiFactoryFinder(BundleContext bundleContext, ClassResolver classResolver, String
resourcePath) {
         super(classResolver, resourcePath);
         this.bundleContext = bundleContext;
-        this.bundle = bundleContext.getBundle();
+    }
+
+    private class BundleEntry {
+        URL url;
+        Bundle bundle;
     }
 
     @Override
@@ -48,8 +50,9 @@ public class OsgiFactoryFinder extends D
 
         Class clazz = classMap.get(propertyPrefix + key);
         if (clazz == null) {
-            URL url = bundle.getEntry(getResourcePath() + key);
-            if (url != null) {
+            BundleEntry entry = getResource(key);
+            if (entry != null) {
+                URL url = entry.url;
                 InputStream in = url.openStream();
                 // lets load the file
                 BufferedInputStream reader = null;
@@ -61,7 +64,7 @@ public class OsgiFactoryFinder extends D
                     if (className == null) {
                         throw new IOException("Expected property is missing: " + propertyPrefix
+ "class");
                     }
-                    clazz = bundle.loadClass(className);
+                    clazz = entry.bundle.loadClass(className);
                     classMap.put(propertyPrefix + key, clazz);
                 } finally {
                     IOHelper.close(reader, key, null);
@@ -75,5 +78,27 @@ public class OsgiFactoryFinder extends D
         return clazz;
     }
     
-       
+    // As the META-INF of the Factory could not be export,
+    // we need to go through the bundles to look for it
+    // NOTE, the first found factory will be return
+    public BundleEntry getResource(String name) {
+        BundleEntry entry = null;
+        Bundle[] bundles = null; 
+        
+        bundles = bundleContext.getBundles();
+        
+        URL url;
+        for (Bundle bundle : bundles) {
+            url = bundle.getEntry(getResourcePath() + name);
+            if (url != null) {
+                entry = new BundleEntry();
+                entry.url = url;
+                entry.bundle = bundle;
+                break;
+            }
+        }
+
+        return entry;
+    }
+
 }

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OsgiFactoryFinderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OsgiFactoryFinderTest.java?rev=954355&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OsgiFactoryFinderTest.java
(added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OsgiFactoryFinderTest.java
Mon Jun 14 03:34:49 2010
@@ -0,0 +1,48 @@
+/**
+ * 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.itest.osgi;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.FactoryFinder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+
+@RunWith(JUnit4TestRunner.class)
+public class OsgiFactoryFinderTest extends OSGiIntegrationTestSupport {
+    private static final transient Log LOG = LogFactory.getLog(OsgiFactoryFinderTest.class);
+    
+    @Test
+    public void testFileProducer() throws Exception {        
+        Class<?> factory = null;
+        FactoryFinder finder = context.getFactoryFinder("META-INF/services/org/apache/camel/component/");
+        factory = finder.findClass("file", "strategy.factory.");
+        LOG.info("*** The factory is " + factory);
+    }
+        
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:simple").to("mock:result");
+            }
+        };
+    }
+    
+    
+}

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OsgiFactoryFinderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OsgiFactoryFinderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message