You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2008/07/22 01:52:18 UTC

svn commit: r678600 - in /tuscany/java/sca/modules: extensibility-eclipse/src/main/java/org/apache/tuscany/sca/extensibility/equinox/ extensibility-osgi/src/main/java/org/apache/tuscany/sca/extensibility/osgi/ implementation-node-osgi-runtime/src/main/...

Author: rfeng
Date: Mon Jul 21 16:52:17 2008
New Revision: 678600

URL: http://svn.apache.org/viewvc?rev=678600&view=rev
Log:
Add more comments and some minor clean up

Modified:
    tuscany/java/sca/modules/extensibility-eclipse/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
    tuscany/java/sca/modules/extensibility-osgi/src/main/java/org/apache/tuscany/sca/extensibility/osgi/OSGiServiceDiscoverer.java
    tuscany/java/sca/modules/implementation-node-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/osgi/launcher/LauncherBundleActivator.java

Modified: tuscany/java/sca/modules/extensibility-eclipse/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/extensibility-eclipse/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java?rev=678600&r1=678599&r2=678600&view=diff
==============================================================================
--- tuscany/java/sca/modules/extensibility-eclipse/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java (original)
+++ tuscany/java/sca/modules/extensibility-eclipse/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java Mon Jul 21 16:52:17 2008
@@ -28,6 +28,8 @@
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
+import java.security.SecureClassLoader;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -48,9 +50,11 @@
 public class EquinoxServiceDiscoverer implements ServiceDiscoverer {
     private static final Logger logger = Logger.getLogger(EquinoxServiceDiscoverer.class.getName());
     private BundleContext context;
+    private ClassLoader classLoader;
 
     public EquinoxServiceDiscoverer(BundleContext context) {
         this.context = context;
+        this.classLoader = new ClassLoaderImpl();
     }
 
     public static class ServiceDeclarationImpl implements ServiceDeclaration {
@@ -112,6 +116,72 @@
 
     }
 
+    public class ClassLoaderImpl extends SecureClassLoader {
+    
+        public ClassLoaderImpl() {
+            super(EquinoxServiceDiscoverer.class.getClassLoader());
+        }
+    
+        /**
+         * Open a back-door to expose the META-INF/services resources
+         */
+        @Override
+        protected URL findResource(String name) {
+            int index = name.lastIndexOf('/');
+            if (index == -1) {
+                return null;
+            }
+            String path = name.substring(0, index);
+            if (path.startsWith("/")) {
+                path = path.substring(1);
+            }
+    
+            if (!path.startsWith("META-INF/services")) {
+                return null;
+            }
+    
+            for (Bundle bundle : context.getBundles()) {
+                URL url = bundle.getEntry(name);
+                if (url != null) {
+                    return url;
+                }
+            }
+    
+            return null;
+        }
+    
+        /**
+         * Open a back-door to expose the META-INF/services resources
+         */
+        @Override
+        protected Enumeration<URL> findResources(String name) throws IOException {
+            int index = name.lastIndexOf('/');
+            if (index == -1) {
+                return null;
+            }
+            String path = name.substring(0, index);
+            String file = name.substring(index + 1);
+            if (path.startsWith("/")) {
+                path = path.substring(1);
+            }
+    
+            if (!path.startsWith("META-INF/services")) {
+                return null;
+            }
+    
+            Set<URL> urlSet = new HashSet<URL>();
+    
+            for (Bundle bundle : context.getBundles()) {
+                Enumeration<URL> urls = bundle.findEntries(path, file, false);
+                if (urls != null) {
+                    urlSet.addAll(Collections.list(urls));
+                }
+            }
+            return Collections.enumeration(urlSet);
+        }
+    
+    }
+
     private static String toString(Bundle b) {
         StringBuffer sb = new StringBuffer();
         sb.append(b.getBundleId()).append(" ").append(b.getSymbolicName());
@@ -252,4 +322,12 @@
 
     }
 
+    /**
+     * This class loader can be set as the thread context class loader for non-OSGi code
+     * @return
+     */
+    public ClassLoader getClassLoader() {
+        return classLoader;
+    }
+
 }

Modified: tuscany/java/sca/modules/extensibility-osgi/src/main/java/org/apache/tuscany/sca/extensibility/osgi/OSGiServiceDiscoverer.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/extensibility-osgi/src/main/java/org/apache/tuscany/sca/extensibility/osgi/OSGiServiceDiscoverer.java?rev=678600&r1=678599&r2=678600&view=diff
==============================================================================
--- tuscany/java/sca/modules/extensibility-osgi/src/main/java/org/apache/tuscany/sca/extensibility/osgi/OSGiServiceDiscoverer.java (original)
+++ tuscany/java/sca/modules/extensibility-osgi/src/main/java/org/apache/tuscany/sca/extensibility/osgi/OSGiServiceDiscoverer.java Mon Jul 21 16:52:17 2008
@@ -57,6 +57,12 @@
         this.classLoader = new ClassLoaderImpl();
     }
 
+    /**
+     * This class loader provides resource access to META-INF/services/... which is used by
+     * many frameworks. OSGi Import-Package and DynmaicImport-Package headers do not support
+     * split packages. Another option is to use Require-Bundle header. We can collect the list
+     * of bundles and add them as required bundles to a special gateway bundle.
+     */
     public class ClassLoaderImpl extends SecureClassLoader {
 
         public ClassLoaderImpl() {

Modified: tuscany/java/sca/modules/implementation-node-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/osgi/launcher/LauncherBundleActivator.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-node-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/osgi/launcher/LauncherBundleActivator.java?rev=678600&r1=678599&r2=678600&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-node-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/osgi/launcher/LauncherBundleActivator.java (original)
+++ tuscany/java/sca/modules/implementation-node-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/osgi/launcher/LauncherBundleActivator.java Mon Jul 21 16:52:17 2008
@@ -96,6 +96,7 @@
             }
         }
         this.bundleContext.removeBundleListener(this);
+        tuscanyBundles.clear();
         this.bundleContext = null;
     }
 
@@ -118,9 +119,6 @@
                 }
                 try {
                     Bundle bundle = createAndInstallBundle(bundleContext, file);
-                    if (bundle != null) {
-                        tuscanyBundles.add(bundle);
-                    }
                 } catch (Exception e) {
                     logger.log(Level.SEVERE, e.getMessage(), e);
                 }
@@ -181,7 +179,7 @@
         Bundle bundle = findBundle(bundleContext, symbolicName, version);
         if (bundle != null) {
             logger.info("Bundle is already installed: " + symbolicName);
-            return null;
+            return bundle;
         }
 
         String bundleLocation = bundleFile.toURI().toString();
@@ -209,6 +207,7 @@
         try {
             bundle = bundleContext.installBundle(bundleLocation, inStream);
             logger.info("Bundle installed in " + (System.currentTimeMillis() - start) + " ms: " + bundleLocation);
+            tuscanyBundles.add(bundle);
             return bundle;
         } finally {
             inStream.close();