FELIX-1894 Display fragment info in bundle details view.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@884436 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
index 81075d5..b24f1a5 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
@@ -506,7 +506,7 @@
                     installed++;
                     break;
                 case Bundle.RESOLVED:
-                    if ( bundles[i].getHeaders().get(Constants.FRAGMENT_HOST) != null )
+                    if ( isFragmentBundle( bundles[i] ) )
                     {
                         fragments++;
                     }
@@ -638,7 +638,7 @@
 
     private boolean isFragmentBundle( Bundle bundle)
     {
-        return bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null;
+        return getPackageAdmin().getBundleType( bundle ) == PackageAdmin.BUNDLE_TYPE_FRAGMENT;
     }
 
     private boolean hasStart( Bundle bundle )
@@ -694,6 +694,8 @@
 
         keyVal( jw, "Bundle Classpath", headers.get( Constants.BUNDLE_CLASSPATH ) );
 
+        listFragmentInfo( jw, bundle, pluginRoot );
+
         if ( bundle.getState() == Bundle.INSTALLED )
         {
             listImportExportsUnresolved( jw, bundle, pluginRoot );
@@ -993,6 +995,40 @@
     }
 
 
+    private void listFragmentInfo( final JSONWriter jw, final Bundle bundle, final String pluginRoot )
+        throws JSONException
+    {
+
+        if ( isFragmentBundle( bundle ) )
+        {
+            Bundle[] hostBundles = getPackageAdmin().getHosts( bundle );
+            if ( hostBundles != null )
+            {
+                JSONArray val = new JSONArray();
+                for ( int i = 0; i < hostBundles.length; i++ )
+                {
+                    val.put( getBundleDescriptor( hostBundles[i], pluginRoot ) );
+                }
+                keyVal( jw, "Host Bundles", val );
+            }
+        }
+        else
+        {
+            Bundle[] fragmentBundles = getPackageAdmin().getFragments( bundle );
+            if ( fragmentBundles != null )
+            {
+                JSONArray val = new JSONArray();
+                for ( int i = 0; i < fragmentBundles.length; i++ )
+                {
+                    val.put( getBundleDescriptor( fragmentBundles[i], pluginRoot ) );
+                }
+                keyVal( jw, "Fragments Attached", val );
+            }
+        }
+
+    }
+
+
     private void appendProperty( JSONArray array, ServiceReference ref, String name, String label )
     {
         StringBuffer dest = new StringBuffer();