You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2013/07/09 16:24:37 UTC

svn commit: r1501288 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: ServiceRegistrationImpl.java util/Util.java

Author: rickhall
Date: Tue Jul  9 14:24:36 2013
New Revision: 1501288

URL: http://svn.apache.org/r1501288
Log:
Modify ServiceReference.isAssignableTo() to try to be more precise. (FELIX-1131)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java?rev=1501288&r1=1501287&r2=1501288&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java Tue Jul  9 14:24:36 2013
@@ -29,6 +29,7 @@ import org.apache.felix.framework.util.U
 import org.apache.felix.framework.wiring.BundleCapabilityImpl;
 import org.osgi.framework.*;
 import org.osgi.framework.BundleReference;
+import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.framework.wiring.BundleWire;
 
@@ -165,6 +166,18 @@ class ServiceRegistrationImpl implements
             && !((BundleReference) m_factory.getClass()
                 .getClassLoader()).getBundle().equals(m_bundle))
         {
+            try
+            {
+                Class providedClazz = m_bundle.loadClass(clazz.getName());
+                if (providedClazz != null)
+                {
+                    return providedClazz == clazz;
+                }
+            }
+            catch (ClassNotFoundException ex)
+            {
+                // Ignore and try interface class loaders.
+            }
             return true;
         }
 
@@ -485,12 +498,14 @@ class ServiceRegistrationImpl implements
             // Get the package.
             String pkgName =
                 Util.getClassPackage(className);
-            BundleRevision requesterRevision = requester.adapt(BundleRevision.class);
             // Get package wiring from service requester.
+            BundleRevision requesterRevision = requester.adapt(BundleRevision.class);
             BundleWire requesterWire = Util.getWire(requesterRevision, pkgName);
+            BundleCapability requesterCap = Util.getPackageCapability(requesterRevision, pkgName);
             // Get package wiring from service provider.
             BundleRevision providerRevision = m_bundle.adapt(BundleRevision.class);
             BundleWire providerWire = Util.getWire(providerRevision, pkgName);
+            BundleCapability providerCap = Util.getPackageCapability(providerRevision, pkgName);
 
             // There are four situations that may occur here:
             //   1. Neither the requester, nor provider have wires for the package.
@@ -533,10 +548,11 @@ class ServiceRegistrationImpl implements
             // Case 2: Requester has no wire, but provider does.
             else if ((requesterWire == null) && (providerWire != null))
             {
-                // Allow if the requester is the exporter of the provider's wire.
-                if (providerWire.getProviderWiring().getRevision().equals(requesterRevision))
+                // If the requester exports the package, then the provider must
+                // be wired to it.
+                if (requesterCap != null)
                 {
-                    allow = true;
+                    allow = providerWire.getProviderWiring().getRevision().equals(requesterRevision);
                 }
                 // Otherwise, check if the requester has access to the class and,
                 // if so, if it is the same class as the provider.
@@ -571,13 +587,11 @@ class ServiceRegistrationImpl implements
             // Case 3: Requester has a wire, but provider does not.
             else if ((requesterWire != null) && (providerWire == null))
             {
-                // If the provider is the exporter of the requester's package, then check
-                // if the requester is wired to the latest version of the provider, if so
-                // then allow else don't (the provider has been updated but not refreshed).
-                if (((BundleImpl) m_bundle).hasRevision(
-                    requesterWire.getProviderWiring().getRevision()))
+                // If the provider exports the package, then the requester must
+                // be wired to it.
+                if (providerCap != null)
                 {
-                    allow = providerRevision.equals(requesterWire.getProviderWiring().getRevision());
+                    allow = requesterWire.getProviderWiring().getRevision().equals(providerRevision);
                 }
                 // If the provider is not the exporter of the requester's package,
                 // then try to use the service registration to see if the requester's

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java?rev=1501288&r1=1501287&r2=1501288&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/Util.java Tue Jul  9 14:24:36 2013
@@ -341,8 +341,8 @@ public class Util
                 {
                     if (w.getCapability().getNamespace()
                             .equals(BundleRevision.PACKAGE_NAMESPACE) &&
-                        w.getCapability().getAttributes()
-                            .get(BundleRevision.PACKAGE_NAMESPACE).equals(name))
+                            w.getCapability().getAttributes()
+                                    .get(BundleRevision.PACKAGE_NAMESPACE).equals(name))
                     {
                         return w;
                     }
@@ -352,6 +352,26 @@ public class Util
         return null;
     }
 
+    public static BundleCapability getPackageCapability(BundleRevision br, String name)
+    {
+        if (br.getWiring() != null)
+        {
+            List<BundleCapability> capabilities = br.getWiring().getCapabilities(null);
+            if (capabilities != null)
+            {
+                for (BundleCapability c : capabilities)
+                {
+                    if (c.getNamespace().equals(BundleRevision.PACKAGE_NAMESPACE)
+                        && c.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE).equals(name))
+                    {
+                        return c;
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
     private static final byte encTab[] = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
         0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52,
         0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64,