geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1133243 - in /geronimo/specs/trunk/geronimo-osgi-support: geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/
Date Wed, 08 Jun 2011 04:16:49 GMT
Author: xuhaihong
Date: Wed Jun  8 04:16:49 2011
New Revision: 1133243

URL: http://svn.apache.org/viewvc?rev=1133243&view=rev
Log:
GERONIMO-5998 Use the implementation configured in system property as the preference while
searching the provider in the OSGi registy

Modified:
    geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java
    geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/Activator.java
    geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderBundleTrackerCustomizer.java
    geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderRegistryImpl.java

Modified: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java?rev=1133243&r1=1133242&r2=1133243&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java
(original)
+++ geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java
Wed Jun  8 04:16:49 2011
@@ -38,7 +38,6 @@ import java.util.Set;
 // the specified conditions are met.
 
 // COND: running in an OSGi environment and the Activator has been activated
-import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.util.tracker.ServiceTracker;
 

Modified: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/Activator.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/Activator.java?rev=1133243&r1=1133242&r2=1133243&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/Activator.java
(original)
+++ geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/Activator.java
Wed Jun  8 04:16:49 2011
@@ -62,8 +62,6 @@ public class Activator implements Bundle
         // register this as a service
         registryRegistration = context.registerService(ProviderRegistry.class.getName(),
registry, null);
 
-        org.osgi.framework.ServiceReference ref = context.getServiceReference(ProviderRegistry.class.getName());
-
 	    bt = new BundleTracker(context, Bundle.ACTIVE, new ProviderBundleTrackerCustomizer(this,
context.getBundle(), registry));
 	    bt.open();
 	}

Modified: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderBundleTrackerCustomizer.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderBundleTrackerCustomizer.java?rev=1133243&r1=1133242&r2=1133243&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderBundleTrackerCustomizer.java
(original)
+++ geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderBundleTrackerCustomizer.java
Wed Jun  8 04:16:49 2011
@@ -20,7 +20,6 @@ package org.apache.geronimo.osgi.registr
 
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleEvent;
-import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.log.LogService;
 import org.osgi.util.tracker.BundleTrackerCustomizer;
 

Modified: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderRegistryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderRegistryImpl.java?rev=1133243&r1=1133242&r2=1133243&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderRegistryImpl.java
(original)
+++ geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderRegistryImpl.java
Wed Jun  8 04:16:49 2011
@@ -204,15 +204,19 @@ public class ProviderRegistryImpl implem
      *                      the process of creating this service instance.
      */
     public Object getService(String providerId) throws Exception {
-        // see if we have a registered match for this...getting just the first instance
-        BundleProviderLoader loader = serviceProviders.getLoader(providerId);
-        if (loader != null) {
-            // try to load this and create an instance.  Any/all exceptions get
-            // thrown here
-            return loader.createInstance();
+        List<BundleProviderLoader> loaders = serviceProviders.getLoaders(providerId);
+        if (loaders == null || loaders.size() == 0) {
+            return null;
+        }
+        String preferenceProviderClassName = System.getProperty(providerId);
+        if (preferenceProviderClassName != null) {
+            for (BundleProviderLoader loader : loaders) {
+                if (loader.providerClass.equals(preferenceProviderClassName)) {
+                    return loader.createInstance();
+                }
+            }
         }
-        // no match to return
-        return null;
+        return loaders.get(0).createInstance();
     }
 
     /**
@@ -283,15 +287,19 @@ public class ProviderRegistryImpl implem
      *                      the process of loading this service provider class.
      */
     public Class<?> getServiceClass(String providerId) throws ClassNotFoundException
{
-        // see if we have a registered match for this...getting just the first instance
-        BundleProviderLoader loader = serviceProviders.getLoader(providerId);
-        if (loader != null) {
-            // try to load this and create an instance.  Any/all exceptions get
-            // thrown here
-            return loader.loadClass();
+        List<BundleProviderLoader> loaders = serviceProviders.getLoaders(providerId);
+        if (loaders == null || loaders.size() == 0) {
+            return null;
+        }
+        String preferenceProviderClassName = System.getProperty(providerId);
+        if (preferenceProviderClassName != null) {
+            for (BundleProviderLoader loader : loaders) {
+                if (loader.providerClass.equals(preferenceProviderClassName)) {
+                    return loader.loadClass();
+                }
+            }
         }
-        // no match to return
-        return null;
+        return loaders.get(0).loadClass();
     }
 
     private void log(int level, String message) {
@@ -347,7 +355,7 @@ public class ProviderRegistryImpl implem
                     registerProvider(loader);
                 }
                 // remember this list so we can unregister when the bundle is stopped
-                providers = new ArrayList(locatedProviders);
+                providers = new ArrayList<BundleProviderLoader>(locatedProviders);
             }
         }
 
@@ -437,10 +445,11 @@ public class ProviderRegistryImpl implem
 
             // look for services definitions in the bundle...we accumulate these as provider
class
             // definitions.
-            Enumeration e = bundle.findEntries(path, "*", false);
+            @SuppressWarnings("unchecked")
+            Enumeration<URL> e = bundle.findEntries(path, "*", false);
             if (e != null) {
                 while (e.hasMoreElements()) {
-                    final URL u = (URL) e.nextElement();
+                    final URL u = e.nextElement();
                     // go parse out the control file
                     parseServiceFile(u, mappings);
                 }
@@ -469,7 +478,6 @@ public class ProviderRegistryImpl implem
             final String providerId = url.substring(url.lastIndexOf("/") + 1);
             try {
                 BufferedReader br = new BufferedReader(new InputStreamReader(u.openStream(),
"UTF-8"));
-                String providerClassName = null;
                 // the file can be multiple lines long, with comments.  A single file can
define multiple providers
                 // for a single key, so we might need to create multiple entries.  If the
file does not contain any
                 // definition lines, then as a default, we use the providerId as an implementation
class also.



Mime
View raw message