You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by vv...@apache.org on 2015/08/07 15:07:15 UTC
svn commit: r1694680 - in
/felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal:
Activator.java ComponentConfigurationPrinter.java InfoProvider.java
Util.java WebConsolePlugin.java
Author: vvalchev
Date: Fri Aug 7 13:07:15 2015
New Revision: 1694680
URL: http://svn.apache.org/r1694680
Log:
Implemented FELIX-4998 : Declarative Service plugin might provide JSON format support for Inventory Printer
https://issues.apache.org/jira/browse/FELIX-4998
Modified:
felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Activator.java
felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ComponentConfigurationPrinter.java
felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/InfoProvider.java
felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Util.java
felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/WebConsolePlugin.java
Modified: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Activator.java?rev=1694680&r1=1694679&r2=1694680&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Activator.java (original)
+++ felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Activator.java Fri Aug 7 13:07:15 2015
@@ -16,8 +16,10 @@
*/
package org.apache.felix.webconsole.plugins.ds.internal;
+import java.util.Dictionary;
import java.util.Hashtable;
+import org.apache.felix.inventory.Format;
import org.apache.felix.inventory.InventoryPrinter;
import org.apache.felix.webconsole.SimpleWebConsolePlugin;
import org.osgi.framework.BundleActivator;
@@ -82,12 +84,17 @@ public class Activator implements Bundle
this.plugin = plugin = new WebConsolePlugin().register(context);
final Object service = context.getService(reference);
- final Hashtable props = new Hashtable();
+ final Dictionary<String, Object> props = new Hashtable<String, Object>();
final String name = "Declarative Services Components";
- props.put(InventoryPrinter.NAME, name.replace(' ', '_'));
+ props.put(InventoryPrinter.NAME, "scr"); //$NON-NLS-1$
props.put(InventoryPrinter.TITLE, name);
+ props.put(InventoryPrinter.FORMAT, new String[] {
+ Format.TEXT.toString(),
+ Format.JSON.toString()
+ });
printerRegistration = context.registerService(InventoryPrinter.SERVICE,
- new ComponentConfigurationPrinter(service), props);
+ new ComponentConfigurationPrinter(service, (WebConsolePlugin) plugin),
+ props);
infoRegistration = new InfoProvider(context.getBundle(), service).register(context);
}
Modified: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ComponentConfigurationPrinter.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ComponentConfigurationPrinter.java?rev=1694680&r1=1694679&r2=1694680&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ComponentConfigurationPrinter.java (original)
+++ felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ComponentConfigurationPrinter.java Fri Aug 7 13:07:15 2015
@@ -32,6 +32,8 @@ import java.util.TreeSet;
import org.apache.felix.inventory.Format;
import org.apache.felix.inventory.InventoryPrinter;
import org.apache.felix.webconsole.WebConsoleUtil;
+import org.json.JSONException;
+import org.json.JSONWriter;
import org.osgi.framework.Constants;
import org.osgi.framework.dto.ServiceReferenceDTO;
import org.osgi.service.component.ComponentConstants;
@@ -48,16 +50,17 @@ class ComponentConfigurationPrinter impl
{
private final ServiceComponentRuntime scrService;
+ private final WebConsolePlugin plugin;
- ComponentConfigurationPrinter(Object scrService)
+ ComponentConfigurationPrinter(Object scrService, WebConsolePlugin plugin)
{
this.scrService = (ServiceComponentRuntime)scrService;
+ this.plugin = plugin;
}
/**
* @see org.apache.felix.inventory.InventoryPrinter#print(java.io.PrintWriter, org.apache.felix.inventory.Format, boolean)
*/
- @Override
public void print(PrintWriter pw, Format format, boolean isZip)
{
final List<ComponentDescriptionDTO> descriptions = new ArrayList<ComponentDescriptionDTO>();
@@ -74,11 +77,43 @@ class ComponentConfigurationPrinter impl
}
Collections.sort(configurations, Util.COMPONENT_COMPARATOR);
- printComponents(pw, configurations);
+ if (Format.JSON.equals(format))
+ {
+ try
+ {
+ printComponentsJson(pw, configurations, isZip);
+ }
+ catch (JSONException t)
+ {
+ // ignore
+ }
+ }
+ else
+ {
+ printComponentsText(pw, configurations);
+ }
}
+ private final void printComponentsJson(final PrintWriter pw,
+ final List<ComponentConfigurationDTO> configurations,
+ final boolean details) throws JSONException
+ {
+ final JSONWriter jw = new JSONWriter(pw);
+ jw.object();
+ jw.key("components"); //$NON-NLS-1$
+ jw.array();
+
+ // render components
+ for (final ComponentConfigurationDTO cfg : configurations)
+ {
+ plugin.component(jw, cfg, details);
+ }
+
+ jw.endArray();
+ jw.endObject();
+ }
- private static final void printComponents(final PrintWriter pw,
+ private static final void printComponentsText(final PrintWriter pw,
final List<ComponentConfigurationDTO> configurations)
{
if (configurations.size() == 0)
Modified: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/InfoProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/InfoProvider.java?rev=1694680&r1=1694679&r2=1694680&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/InfoProvider.java (original)
+++ felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/InfoProvider.java Fri Aug 7 13:07:15 2015
@@ -53,7 +53,6 @@ class InfoProvider implements BundleInfo
/**
* @see org.apache.felix.webconsole.bundleinfo.BundleInfoProvider#getName(java.util.Locale)
*/
- @Override
public String getName(Locale locale)
{
return localization.getResourceBundle(locale).getString("info.name"); //$NON-NLS-1$;;
@@ -63,7 +62,6 @@ class InfoProvider implements BundleInfo
* @see org.apache.felix.webconsole.bundleinfo.BundleInfoProvider#getBundleInfo(org.osgi.framework.Bundle,
* java.lang.String, java.util.Locale)
*/
- @Override
public BundleInfo[] getBundleInfo(Bundle bundle, String webConsoleRoot, Locale locale)
{
final List<ComponentDescriptionDTO> descriptions = new ArrayList<ComponentDescriptionDTO>();
Modified: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Util.java?rev=1694680&r1=1694679&r2=1694680&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Util.java (original)
+++ felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Util.java Fri Aug 7 13:07:15 2015
@@ -27,7 +27,6 @@ class Util
static final Comparator<ComponentConfigurationDTO> COMPONENT_COMPARATOR = new Comparator<ComponentConfigurationDTO>()
{
- @Override
public int compare(ComponentConfigurationDTO c0, ComponentConfigurationDTO c1)
{
final int nameCmp = c0.description.name.compareTo(c1.description.name);
Modified: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/WebConsolePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/WebConsolePlugin.java?rev=1694680&r1=1694679&r2=1694680&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/WebConsolePlugin.java (original)
+++ felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/WebConsolePlugin.java Fri Aug 7 13:07:15 2015
@@ -243,7 +243,7 @@ class WebConsolePlugin extends SimpleWeb
}
}
- private void component(JSONWriter jw, ComponentConfigurationDTO component, boolean details)
+ void component(JSONWriter jw, ComponentConfigurationDTO component, boolean details)
throws JSONException
{
String id = String.valueOf(component.id);