FELIX-1048 : Recognize fragment bundles and display them properly in the bundles list.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@769151 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 8fc50ad..d620ae3 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
@@ -343,7 +343,7 @@
 
     private String getStatusLine(final Bundle[] bundles)
     {
-        int active = 0, installed = 0, resolved = 0;
+        int active = 0, installed = 0, resolved = 0, fragments = 0;
         for ( int i = 0; i < bundles.length; i++ )
         {
             switch ( bundles[i].getState() )
@@ -355,14 +355,21 @@
                     installed++;
                     break;
                 case Bundle.RESOLVED:
-                    resolved++;
+                    if ( bundles[i].getHeaders().get(Constants.FRAGMENT_HOST) != null )
+                    {
+                        fragments++;
+                    }
+                    else
+                    {
+                        resolved++;
+                    }
                     break;
             }
         }
         final StringBuffer buffer = new StringBuffer();
         buffer.append("Bundle information: ");
         appendBundleInfoCount(buffer, "in total", bundles.length);
-        if ( active == bundles.length )
+        if ( active == bundles.length || active + fragments == bundles.length )
         {
             buffer.append(" - all ");
             appendBundleInfoCount(buffer, "active.", bundles.length);
@@ -374,6 +381,11 @@
                 buffer.append(", ");
                 appendBundleInfoCount(buffer, "active", active);
             }
+            if ( fragments != 0 )
+            {
+                buffer.append(", ");
+                appendBundleInfoCount(buffer, "active fragments", fragments);
+            }
             if ( resolved != 0 )
             {
                 buffer.append(", ");
@@ -397,7 +409,7 @@
         jw.key( "name" );
         jw.value( Util.getName( bundle ) );
         jw.key( "state" );
-        jw.value( toStateString( bundle.getState() ) );
+        jw.value( toStateString( bundle ) );
 
         jw.key( "actions" );
         jw.array();
@@ -432,13 +444,17 @@
     }
 
 
-    private String toStateString( int bundleState )
+    private String toStateString( final Bundle bundle )
     {
-        switch ( bundleState )
+        switch ( bundle.getState() )
         {
             case Bundle.INSTALLED:
                 return "Installed";
             case Bundle.RESOLVED:
+                if ( bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null )
+                {
+                    return "Fragment";
+                }
                 return "Resolved";
             case Bundle.STARTING:
                 return "Starting";
@@ -449,7 +465,7 @@
             case Bundle.UNINSTALLED:
                 return "Uninstalled";
             default:
-                return "Unknown: " + bundleState;
+                return "Unknown: " + bundle.getState();
         }
     }
 
@@ -467,12 +483,20 @@
 
     private boolean hasStart( Bundle bundle )
     {
+        if ( bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null )
+        {
+            return false;
+        }
         return bundle.getState() == Bundle.INSTALLED || bundle.getState() == Bundle.RESOLVED;
     }
 
 
     private boolean hasStop( Bundle bundle )
     {
+        if ( bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null )
+        {
+            return false;
+        }
         return bundle.getState() == Bundle.ACTIVE;
     }
 
diff --git a/webconsole/src/main/resources/res/ui/bundles.js b/webconsole/src/main/resources/res/ui/bundles.js
index b9bf12d..30d11dc 100644
--- a/webconsole/src/main/resources/res/ui/bundles.js
+++ b/webconsole/src/main/resources/res/ui/bundles.js
@@ -55,6 +55,9 @@
 }
 
 function actionButton( /* Element */ parent, /* string */ id, /* Obj */ action ) {
+	if ( !action.enabled ) {
+		return;
+	}
 	var enabled = action.enabled;
 	var op = action.link;
 	var opLabel = action.name;