felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r742957 - in /felix/trunk/webconsole/src/main: java/org/apache/felix/webconsole/internal/compendium/ComponentsServlet.java resources/res/imgs/component_configure.png resources/res/imgs/component_edit.png resources/res/ui/components.js
Date Tue, 10 Feb 2009 13:09:03 GMT
Author: cziegeler
Date: Tue Feb 10 13:08:50 2009
New Revision: 742957

URL: http://svn.apache.org/viewvc?rev=742957&view=rev
Log:
FELIX-919 : Rename edit to configure and only add configure button if either a configuration
is available or a meta type description.

Added:
    felix/trunk/webconsole/src/main/resources/res/imgs/component_configure.png   (props changed)
      - copied unchanged from r742728, felix/trunk/webconsole/src/main/resources/res/imgs/component_edit.png
Removed:
    felix/trunk/webconsole/src/main/resources/res/imgs/component_edit.png
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=742957&r1=742956&r2=742957&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 Feb 10 13:08:50 2009
@@ -30,9 +30,11 @@
 import org.apache.felix.webconsole.internal.Util;
 import org.apache.felix.webconsole.internal.servlet.OsgiManager;
 import org.json.*;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
+import org.osgi.framework.*;
+import org.osgi.service.cm.*;
 import org.osgi.service.component.ComponentConstants;
+import org.osgi.service.metatype.MetaTypeInformation;
+import org.osgi.service.metatype.MetaTypeService;
 
 
 public class ComponentsServlet extends BaseWebConsolePlugin
@@ -50,10 +52,13 @@
 
     public static final String OPERATION_DISABLE = "disable";
 
-    public static final String OPERATION_EDIT = "edit";
+    public static final String OPERATION_CONFIGURE = "configure";
 
     private static final String SCR_SERVICE = ScrService.class.getName();
 
+    private static final String META_TYPE_NAME = MetaTypeService.class.getName();
+
+    private static final String CONFIGURATION_ADMIN_NAME = ConfigurationAdmin.class.getName();
 
     public String getTitle()
     {
@@ -246,7 +251,10 @@
         }
         if ( pid != null )
         {
-            action(jw, true, OPERATION_EDIT, "Edit", "edit" );
+            if ( isConfigurable( pid ) )
+            {
+                action(jw, true, OPERATION_CONFIGURE, "Configure", "configure" );
+            }
         }
 
         jw.endArray();
@@ -441,12 +449,84 @@
         }
     }
 
+    /**
+     * Check if the component with the specified pid is
+     * configurable
+     * @param pid A non null pid
+     * @return <code>true</code> if the component is configurable.
+     */
+    private boolean isConfigurable( final String pid )
+    {
+        // we first check if the config admin has something for this pid
+        final ConfigurationAdmin ca = this.getConfigurationAdmin();
+        if ( ca != null )
+        {
+            try
+            {
+                // we use listConfigurations to not create configuration
+                // objects persistently without the user providing actual
+                // configuration
+                String filter = "(" + Constants.SERVICE_PID + "=" + pid + ")";
+                Configuration[] configs = ca.listConfigurations( filter );
+                if ( configs != null && configs.length > 0 )
+                {
+                    return true;
+                }
+            }
+            catch ( InvalidSyntaxException ise )
+            {
+                // should print message
+            }
+            catch ( IOException ioe )
+            {
+                // should print message
+            }
+        }
+        // second check is using the meta type service
+        final MetaTypeService mts = this.getMetaTypeService();
+        if ( mts != null )
+        {
+            try
+            {
+                final ServiceReference[] refs = this.getBundleContext().getServiceReferences(
ManagedService.class.getName(),
+                        '(' + "service.pid" + '=' + pid  + ')' );
+                for ( int i = 0; refs != null && i < refs.length; i++ )
+                {
+                    if ( refs[i].getBundle() != null )
+                    {
+                        final MetaTypeInformation mti = mts.getMetaTypeInformation( refs[i].getBundle()
);
+                        if ( mti != null )
+                        {
+                            return mti.getObjectClassDefinition(pid, null) != null;
+                        }
+                    }
+                }
+
+            }
+            catch ( InvalidSyntaxException ise )
+            {
+                // we just ignore this for now
+            }
+
+        }
+        return false;
+    }
+
+    protected ConfigurationAdmin getConfigurationAdmin()
+    {
+        return ( ConfigurationAdmin ) getService( CONFIGURATION_ADMIN_NAME );
+    }
 
     private ScrService getScrService()
     {
         return ( ScrService ) getService( SCR_SERVICE );
     }
 
+    protected MetaTypeService getMetaTypeService()
+    {
+        return ( MetaTypeService ) getService( META_TYPE_NAME );
+    }
+
     private final class RequestInfo
     {
         public final String extension;

Propchange: felix/trunk/webconsole/src/main/resources/res/imgs/component_configure.png
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: felix/trunk/webconsole/src/main/resources/res/imgs/component_configure.png
------------------------------------------------------------------------------
    svn:mime-type = image/png

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=742957&r1=742956&r2=742957&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/resources/res/ui/components.js (original)
+++ felix/trunk/webconsole/src/main/resources/res/ui/components.js Tue Feb 10 13:08:50 2009
@@ -61,7 +61,7 @@
 	var img = action.image;
 	
 	var arg = id;
-	if ( op == "edit" ) {
+	if ( op == "configure" ) {
 		arg = pid
 	}
 	var input = createElement( "input", null, {
@@ -118,7 +118,7 @@
 }
 
 function changeDataEntryState(/* long */ id, /* String */ action) {
-	if ( action == "edit") {
+	if ( action == "configure") {
 		window.location = appRoot + "/configMgr/" + id;
 		return;
 	}



Mime
View raw message