felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1648389 - in /felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core: BundleContextUtil.java BundlesConfigurationPrinter.java BundlesServlet.java ServicesConfigurationPrinter.java ServicesServlet.java
Date Mon, 29 Dec 2014 16:35:00 GMT
Author: cziegeler
Date: Mon Dec 29 16:35:00 2014
New Revision: 1648389

URL: http://svn.apache.org/r1648389
Log:
FELIX-4737 : Provide an option to use system bundle context to get bundles/services (Support
for subsystems)

Added:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleContextUtil.java
  (with props)
Modified:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesConfigurationPrinter.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesConfigurationPrinter.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java

Added: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleContextUtil.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleContextUtil.java?rev=1648389&view=auto
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleContextUtil.java
(added)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleContextUtil.java
Mon Dec 29 16:35:00 2014
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.webconsole.internal.core;
+
+
+import org.osgi.framework.BundleContext;
+
+
+/**
+ * The <code>BundleContextUtil</code> class.
+ */
+public class BundleContextUtil
+{
+    /**
+     * If this property is specified (regardless of it's value), the system bundle is used
+     * as a working bundle context. Otherwise the web console bundle context is used.
+     */
+    public static final String FWK_PROP_USE_SYSTEM_BUNDLE = "webconsole.use.systembundle";
+
+    /**
+     * Get the working bundle context: the bundle context to lookup bundles and
+     * services.
+     */
+    public static BundleContext getWorkingBundleContext( final BundleContext bc)
+    {
+        if ( bc.getProperty(FWK_PROP_USE_SYSTEM_BUNDLE) != null )
+        {
+            return bc.getBundle(0).getBundleContext();
+        }
+        return bc;
+    }
+}
\ No newline at end of file

Propchange: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleContextUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleContextUtil.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleContextUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesConfigurationPrinter.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesConfigurationPrinter.java?rev=1648389&r1=1648388&r2=1648389&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesConfigurationPrinter.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesConfigurationPrinter.java
Mon Dec 29 16:35:00 2014
@@ -19,10 +19,14 @@ package org.apache.felix.webconsole.inte
 
 import java.io.PrintWriter;
 import java.text.MessageFormat;
-import java.util.*;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
 
 import org.apache.felix.webconsole.internal.AbstractConfigurationPrinter;
-import org.osgi.framework.*;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.util.tracker.ServiceTracker;
 
@@ -101,7 +105,7 @@ public class BundlesConfigurationPrinter
      */
     public void printConfiguration( final PrintWriter pw )
     {
-        final Bundle[] bundles = this.getBundleContext().getBundles();
+        final Bundle[] bundles = BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getBundles();
         // create a map for sorting first
         final TreeMap bundlesMap = new TreeMap();
         int active = 0, installed = 0, resolved = 0, fragments = 0;

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java?rev=1648389&r1=1648388&r2=1648389&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
Mon Dec 29 16:35:00 2014
@@ -474,7 +474,7 @@ public class BundlesServlet extends Simp
             final long bundleId = Long.parseLong( pathInfo );
             if ( bundleId >= 0 )
             {
-                return getBundleContext().getBundle( bundleId );
+                return BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getBundle(
bundleId );
             }
         }
         catch ( NumberFormatException nfe )
@@ -492,7 +492,7 @@ public class BundlesServlet extends Simp
             }
 
             // search
-            final Bundle[] bundles = getBundleContext().getBundles();
+            final Bundle[] bundles = BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getBundles();
             for(int i=0; i<bundles.length; i++)
             {
                 final Bundle bundle = bundles[i];
@@ -751,7 +751,7 @@ public class BundlesServlet extends Simp
 
     private final Bundle[] getBundles()
     {
-        return getBundleContext().getBundles();
+        return BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getBundles();
     }
 
 
@@ -1672,7 +1672,7 @@ public class BundlesServlet extends Simp
             }
             else
             {
-                Bundle[] bundles = getBundleContext().getBundles();
+                Bundle[] bundles = BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getBundles();
                 for ( int i = 0; i < bundles.length; i++ )
                 {
                     if ( ( bundles[i].getLocation() != null && bundles[i].getLocation().equals(
location ) )

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesConfigurationPrinter.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesConfigurationPrinter.java?rev=1648389&r1=1648388&r2=1648389&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesConfigurationPrinter.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesConfigurationPrinter.java
Mon Dec 29 16:35:00 2014
@@ -30,10 +30,9 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
-import org.osgi.service.packageadmin.ExportedPackage;
 
 /**
- * ServicesConfigurationPrinter provides a configuration printer for inspecting the 
+ * ServicesConfigurationPrinter provides a configuration printer for inspecting the
  * registered services.
  */
 public class ServicesConfigurationPrinter extends AbstractConfigurationPrinter implements
Constants
@@ -131,7 +130,7 @@ public class ServicesConfigurationPrinte
         ServiceReference[] refs = null;
         try
         {
-            refs = getBundleContext().getAllServiceReferences(null, null);
+            refs = BundleContextUtil.getWorkingBundleContext(getBundleContext()).getAllServiceReferences(null,
null);
         }
         catch (InvalidSyntaxException e)
         {

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java?rev=1648389&r1=1648388&r2=1648389&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
Mon Dec 29 16:35:00 2014
@@ -152,7 +152,7 @@ public class ServicesServlet extends Sim
         String filterStr = filter.toString();
         try
         {
-            ServiceReference[] refs = getBundleContext().getAllServiceReferences( null, filterStr
);
+            ServiceReference[] refs = BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getAllServiceReferences(
null, filterStr );
             if ( refs == null || refs.length != 1 )
             {
                 return null;
@@ -176,7 +176,7 @@ public class ServicesServlet extends Sim
         }
         try
         {
-            final ServiceReference[] refs = getBundleContext().getAllServiceReferences( null,
filter );
+            final ServiceReference[] refs = BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getAllServiceReferences(
null, filter );
             if ( refs != null )
             {
                 return refs;
@@ -420,5 +420,4 @@ public class ServicesServlet extends Sim
 
         response.getWriter().print( TEMPLATE );
     }
-
 }



Mime
View raw message