You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gn...@apache.org on 2011/02/21 10:22:56 UTC

svn commit: r1072901 - /felix/trunk/framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java

Author: gnodet
Date: Mon Feb 21 09:22:56 2011
New Revision: 1072901

URL: http://svn.apache.org/viewvc?rev=1072901&view=rev
Log:
[FELIX-2850] PackageAdmin return fragments / hosts even if the host isn't resolved

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java?rev=1072901&r1=1072900&r2=1072901&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java Mon Feb 21 09:22:56 2011
@@ -189,42 +189,66 @@ class PackageAdminImpl implements Packag
 
     public Bundle[] getFragments(Bundle bundle)
     {
-        Bundle[] fragments = null;
         // If the bundle is not a fragment, then return its fragments.
         if ((getBundleType(bundle) & BUNDLE_TYPE_FRAGMENT) == 0)
         {
-            // Convert fragment modules to bundles.
-            List list = new ArrayList();
+            List<Bundle> list = new ArrayList<Bundle>();
             // Iterate through modules
             List<Module> modules = ((BundleImpl) bundle).getModules();
             for (int modIdx = 0; modIdx < modules.size(); modIdx++)
             {
                 // Get attached fragments.
-                List<Module> frags = ((ModuleImpl) modules.get(modIdx)).getFragments();
-                for (int i = 0; (frags != null) && (i < frags.size()); i++)
+                ModuleImpl module = (ModuleImpl) modules.get(modIdx);
+                if (module.isResolved())
                 {
-                    Bundle b = frags.get(i).getBundle();
-                    if (b != null)
+                    List<Module> fragments = module.getFragments();
+                    for (int i = 0; (fragments != null) && (i < fragments.size()); i++)
                     {
-                        list.add(b);
+                        Bundle b = fragments.get(i).getBundle();
+                        if (b != null)
+                        {
+                            list.add(b);
+                        }
                     }
                 }
             }
             // Convert list to an array.
-            fragments = (list.size() == 0)
+            return (list.size() == 0)
                 ? null
                 : (Bundle[]) list.toArray(new Bundle[list.size()]);
         }
-        return fragments;
+        return null;
     }
 
     public Bundle[] getHosts(Bundle bundle)
     {
-        if (getBundleType(bundle) == BUNDLE_TYPE_FRAGMENT)
+        // If the bundle is a fragment, return its hosts
+        if ((getBundleType(bundle) & BUNDLE_TYPE_FRAGMENT) != 0)
         {
-            List<Bundle> hosts = m_felix.getDependentBundles((BundleImpl) bundle);
-            return ((hosts != null) && (hosts.size() > 0))
-                ? hosts.toArray(new Bundle[hosts.size()]) : null;
+            List<Bundle> list = new ArrayList<Bundle>();
+            // Iterate through modules
+            List<Module> modules = ((BundleImpl) bundle).getModules();
+            for (int modIdx = 0; modIdx < modules.size(); modIdx++)
+            {
+                // Get hosts
+                ModuleImpl module = (ModuleImpl) modules.get(modIdx);
+                if (module.isResolved())
+                {
+                    List<Module> hosts = module.getDependentHosts();
+                    for (int i = 0; (hosts != null) && (i < hosts.size()); i++)
+                    {
+                        Bundle b = hosts.get(i).getBundle();
+                        if (b != null)
+                        {
+                            list.add(b);
+                        }
+                    }
+                }
+            }
+            // Convert list to an array.
+            return (list.size() == 0)
+                ? null
+                : (Bundle[]) list.toArray(new Bundle[list.size()]);
         }
         return null;
     }