You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2010/08/03 11:47:04 UTC

svn commit: r981795 - in /felix/trunk/webconsole/src/main: java/org/apache/felix/webconsole/internal/compendium/ComponentsServlet.java resources/res/ui/components.js

Author: fmeschbe
Date: Tue Aug  3 09:47:04 2010
New Revision: 981795

URL: http://svn.apache.org/viewvc?rev=981795&view=rev
Log:
FELIX-2288 Add support for components whose component ID is not assigned. Instead of the component ID a combination of the component name and the service.pid property assigned to the component is used. If the service.pid property is not assigned to the component, just the component name is used.

Modified:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentsServlet.java
    felix/trunk/webconsole/src/main/resources/res/ui/components.js

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentsServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentsServlet.java?rev=981795&r1=981794&r2=981795&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentsServlet.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentsServlet.java Tue Aug  3 09:47:04 2010
@@ -508,60 +508,121 @@ public class ComponentsServlet extends S
         public final Component component;
         public final boolean componentRequested;
 
-        protected long getComponentId( final String componentIdPar )
-        {
-            try
-            {
-                return Long.parseLong( componentIdPar );
-            }
-            catch ( NumberFormatException nfe )
-            {
-                // TODO: log
-            }
-
-            // no bundleId or wrong format
-            return -1;
-        }
 
         protected RequestInfo( final HttpServletRequest request )
         {
             String info = request.getPathInfo();
             // remove label and starting slash
-            info = info.substring(getLabel().length() + 1);
+            info = info.substring( getLabel().length() + 1 );
 
             // get extension
-            if ( info.endsWith(".json") )
+            if ( info.endsWith( ".json" ) )
             {
                 extension = "json";
-                info = info.substring(0, info.length() - 5);
+                info = info.substring( 0, info.length() - 5 );
             }
             else
             {
                 extension = "html";
             }
 
-            long componentId = getComponentId(info.substring(info.lastIndexOf('/') + 1));
-            if ( componentId == -1 )
+            if ( info.length() > 0 && info.startsWith( "/" ) )
             {
-                componentRequested = false;
-                component = null;
+                this.componentRequested = true;
+                info = info.substring( 1 );
+                Component component = getComponentId( info );
+                if ( component == null )
+                {
+                    component = getComponentByName( info );
+                }
+                this.component = component;
             }
             else
             {
-                componentRequested = true;
-                final ScrService scrService = getScrService();
-                if ( scrService != null )
+                this.componentRequested = false;
+                this.component = null;
+            }
+
+            request.setAttribute( ComponentsServlet.this.getClass().getName(), this );
+        }
+
+
+        protected Component getComponentId( final String componentIdPar )
+        {
+            final ScrService scrService = getScrService();
+            if ( scrService != null )
+            {
+                try
                 {
-                    component = scrService.getComponent( componentId );
+                    final long componentId = Long.parseLong( componentIdPar );
+                    return scrService.getComponent( componentId );
                 }
-                else
+                catch ( NumberFormatException nfe )
                 {
-                    component = null;
+                    // don't care
                 }
             }
-            request.setAttribute(ComponentsServlet.class.getName(), this);
+
+            return null;
         }
 
+
+        protected Component getComponentByName( final String names )
+        {
+            if ( names.length() > 0 )
+            {
+                final ScrService scrService = getScrService();
+                if ( scrService != null )
+                {
+
+                    final int slash = names.lastIndexOf( '/' );
+                    final String componentName;
+                    final String pid;
+                    if ( slash > 0 )
+                    {
+                        componentName = names.substring( 0, slash );
+                        pid = names.substring( slash + 1 );
+                    }
+                    else
+                    {
+                        componentName = names;
+                        pid = null;
+                    }
+
+                    Component[] components;
+                    try
+                    {
+                        components = scrService.getComponents( componentName );
+                    }
+                    catch ( Throwable t )
+                    {
+                        // not implemented in the used API versio
+                        components = null;
+                    }
+
+                    if ( components != null )
+                    {
+                        if ( pid != null )
+                        {
+                            for ( int i = 0; i < components.length; i++ )
+                            {
+                                Component component = components[i];
+                                if ( pid.equals( component.getProperties().get( Constants.SERVICE_PID ) ) )
+                                {
+                                    return component;
+                                }
+                            }
+                        }
+                        else if ( components.length > 0 )
+                        {
+                            return components[0];
+                        }
+                    }
+                }
+            }
+
+            return null;
+        }
     }
 
     static RequestInfo getRequestInfo(final HttpServletRequest request)

Modified: felix/trunk/webconsole/src/main/resources/res/ui/components.js
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/res/ui/components.js?rev=981795&r1=981794&r2=981795&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/resources/res/ui/components.js (original)
+++ felix/trunk/webconsole/src/main/resources/res/ui/components.js Tue Aug  3 09:47:04 2010
@@ -38,24 +38,35 @@ function renderData( eventData )  {
 	}
 }
 
+function getEntryId(/* Object */ dataEntry) {
+    var id = dataEntry.id;
+    if (id < 0) {
+        id = dataEntry.name;
+        if (dataEntry.pid) {
+            id += "/" + dataEntry.pid;
+        }
+    }
+    return id;
+}
+
 function entry( /* Object */ dataEntry ) {
-	var id = dataEntry.id;
+	var idPath = getEntryId(dataEntry);
+	var id = idPath.replace(/[./-]/g, "_");
 	var name = dataEntry.name;
-
-	var _ = tableEntryTemplate.clone().appendTo(tableBody).attr('id', 'entry' + dataEntry.id);
+	var _ = tableEntryTemplate.clone().appendTo(tableBody).attr('id', 'entry' + id);
 
 	_.find('.bIcon').attr('id', 'img' + id).click(function() {
-		showDetails(id);
-	}).after(drawDetails ? name : ('<a href="' + window.location.pathname + '/' + id + '">' + name + '</a>'));
+		showDetails(idPath);
+	}).after(drawDetails ? name : ('<a href="' + pluginRoot + '/' + idPath + '">' + name + '</a>'));
 
-	_.find('td:eq(0)').text( id );
+	_.find('td:eq(0)').text( dataEntry.id );
 	_.find('td:eq(2)').text( dataEntry.state );
 
 	// setup buttons
 	if ( dataEntry.stateRaw == 1 || dataEntry.stateRaw == 1024 ) { // disabled or disabling
-		_.find('li:eq(0)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(id, 'enable') });
+		_.find('li:eq(0)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(idPath, 'enable') });
 	} else {
-		_.find('li:eq(1)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(id, 'disable') });
+		_.find('li:eq(1)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(idPath, 'disable') });
 	}
 	if ( dataEntry.configurable ) _.find('li:eq(2)').removeClass('ui-helper-hidden').click(function() { // configure
 		changeDataEntryState(dataEntry.pid, 'configure');
@@ -85,6 +96,7 @@ function loadData() {
 }
 
 function hideDetails( id ) {
+	var __test__ = $("#img" + id);
 	$("#img" + id).each(function() {
 		$("#pluginInlineDetails").remove();
 		$(this).
@@ -98,9 +110,11 @@ function hideDetails( id ) {
 
 function renderDetails( data ) {
 	data = data.data[0];
+	var id = getEntryId(data).replace(/[./-]/g, "_");
 	$("#pluginInlineDetails").remove();
-	$("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails'/>");
-	$("#img" + data.id).each(function() {
+	var __test__ = $("#entry" + id);
+	$("#entry" + id + " > td").eq(1).append("<div id='pluginInlineDetails'/>");
+	$("#img" + id).each(function() {
 		if ( drawDetails ) {
 			var ref = window.location.pathname;
 			ref = ref.substring(0, ref.lastIndexOf('/'));
@@ -116,7 +130,7 @@ function renderDetails( data ) {
 				removeClass('ui-icon-triangle-1-e').//right
 				addClass('ui-icon-triangle-1-s').//down
 				attr("title", "Hide Details").
-				unbind('click').click(function() {hideDetails(data.id)});
+				unbind('click').click(function() {hideDetails(id)});
 		}
 	});
 	$("#pluginInlineDetails").append("<table border='0'><tbody></tbody></table>");