Author: cziegeler
Date: Fri Jan 13 10:09:32 2017
New Revision: 1778522

URL: http://svn.apache.org/viewvc?rev=1778522&view=rev
Log:
FELIX-5489 : Remove dependency to org.json

Added:
    
felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/JSONWriter.java
   (with props)
Modified:
    felix/trunk/webconsole-plugins/ds/changelog.txt
    felix/trunk/webconsole-plugins/ds/pom.xml
    
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/WebConsolePlugin.java

Modified: felix/trunk/webconsole-plugins/ds/changelog.txt
URL: 
http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/ds/changelog.txt?rev=1778522&r1=1778521&r2=1778522&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/ds/changelog.txt (original)
+++ felix/trunk/webconsole-plugins/ds/changelog.txt Fri Jan 13 10:09:32 2017
@@ -1,3 +1,9 @@
+Changes from 2.0.2 to 2.0.4
+---------------------------
+** Bug
+    * [FELIX-5488] - DS Plugin should use PID from ComponentDescriptionDTO
+
+
 Changes from 2.0.0 to 2.0.2
 ---------------------------
 ** Improvement

Modified: felix/trunk/webconsole-plugins/ds/pom.xml
URL: 
http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/ds/pom.xml?rev=1778522&r1=1778521&r2=1778522&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/ds/pom.xml (original)
+++ felix/trunk/webconsole-plugins/ds/pom.xml Fri Jan 13 10:09:32 2017
@@ -59,7 +59,7 @@
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
-                <version>2.5.3</version>
+                <version>3.2.0</version>
                 <extensions>true</extensions>
                 <configuration>
                     <instructions>
@@ -114,13 +114,5 @@
                    <version>1.0.4</version>
             <scope>provided</scope>
         </dependency>
-        
-        <dependency>
-            <groupId>org.json</groupId>
-            <artifactId>json</artifactId>
-            <version>20070829</version>
-            <scope>provided</scope>
-        </dependency>
-
     </dependencies>
 </project>

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=1778522&r1=1778521&r2=1778522&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 Jan 13 10:09:32 2017
@@ -32,8 +32,6 @@ 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;
@@ -79,14 +77,7 @@ class ComponentConfigurationPrinter impl
 
         if (Format.JSON.equals(format))
         {
-            try
-            {
-                printComponentsJson(pw, disabled, configurations, isZip);
-            }
-            catch (JSONException t)
-            {
-                // ignore
-            }
+            printComponentsJson(pw, disabled, configurations, isZip);
         }
         else
         {
@@ -95,9 +86,9 @@ class ComponentConfigurationPrinter impl
     }
 
     private final void printComponentsJson(final PrintWriter pw,
-        final List<ComponentDescriptionDTO> disabled,
-        final List<ComponentConfigurationDTO> configurations,
-        final boolean details) throws JSONException
+            final List<ComponentDescriptionDTO> disabled,
+            final List<ComponentConfigurationDTO> configurations,
+            final boolean details)
     {
         final JSONWriter jw = new JSONWriter(pw);
         jw.object();
@@ -163,10 +154,10 @@ class ComponentConfigurationPrinter impl
         pw.println("]");
 
         pw.println("  Bundle" + cfg.description.bundle.symbolicName + " ("
-            + cfg.description.bundle.id + ")");
+                + cfg.description.bundle.id + ")");
         pw.println("  State=" + toStateString(cfg.state));
         pw.println("  DefaultState="
-            + (cfg.description.defaultEnabled ? "enabled" : "disabled"));
+                + (cfg.description.defaultEnabled ? "enabled" : "disabled"));
         pw.println("  Activation=" + (cfg.description.immediate ? "immediate" 
: "delayed"));
 
         listServices(pw, cfg);
@@ -182,9 +173,9 @@ class ComponentConfigurationPrinter impl
         pw.print(cfg.name);
 
         pw.println("  Bundle" + cfg.bundle.symbolicName + " ("
-            + cfg.bundle.id + ")");
+                + cfg.bundle.id + ")");
         pw.println("  DefaultState="
-            + (cfg.defaultEnabled ? "enabled" : "disabled"));
+                + (cfg.defaultEnabled ? "enabled" : "disabled"));
         pw.println("  Activation=" + (cfg.immediate ? "immediate" : 
"delayed"));
         pw.println();
     }
@@ -231,7 +222,7 @@ class ComponentConfigurationPrinter impl
             final SatisfiedReferenceDTO satisfiedRef = findReference(cfg, 
dto.name);
 
             pw.println("  Reference=" + dto.name + ", "
-                + (satisfiedRef != null ? "Satisfied" : "Unsatisfied"));
+                    + (satisfiedRef != null ? "Satisfied" : "Unsatisfied"));
 
             pw.println("    Service Name: " + dto.interfaceName);
 
@@ -303,16 +294,16 @@ class ComponentConfigurationPrinter impl
     {
         switch (state)
         {
-            case ComponentConfigurationDTO.ACTIVE:
-                return "active";
-            case ComponentConfigurationDTO.SATISFIED:
-                return "satisfied";
-            case ComponentConfigurationDTO.UNSATISFIED_CONFIGURATION:
-                return "unsatisfied (configuration)";
-            case ComponentConfigurationDTO.UNSATISFIED_REFERENCE:
-                return "unsatisfied (reference)";
-            default:
-                return String.valueOf(state);
+        case ComponentConfigurationDTO.ACTIVE:
+            return "active";
+        case ComponentConfigurationDTO.SATISFIED:
+            return "satisfied";
+        case ComponentConfigurationDTO.UNSATISFIED_CONFIGURATION:
+            return "unsatisfied (configuration)";
+        case ComponentConfigurationDTO.UNSATISFIED_REFERENCE:
+            return "unsatisfied (reference)";
+        default:
+            return String.valueOf(state);
         }
     }
 }

Added: 
felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/JSONWriter.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/JSONWriter.java?rev=1778522&view=auto
==============================================================================
--- 
felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/JSONWriter.java
 (added)
+++ 
felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/JSONWriter.java
 Fri Jan 13 10:09:32 2017
@@ -0,0 +1,198 @@
+/*
+ * 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.plugins.ds.internal;
+
+import java.io.PrintWriter;
+
+/**
+ * Simply JSON writer to be used on top of a {@link PrintWriter}.
+ */
+public class JSONWriter {
+
+    private final PrintWriter pw;
+
+    private boolean comma;
+
+    public JSONWriter(final PrintWriter pw) {
+        this.comma = false;
+        this.pw = pw;
+    }
+
+    public JSONWriter object()
+    {
+        if (this.comma)  this.pw.write(',');
+        this.pw.write("{");
+        this.comma = false;
+        return this;
+    }
+
+    public JSONWriter endObject()
+    {
+        this.pw.write('}');
+        this.comma = true;
+        return this;
+    }
+
+    public JSONWriter array()
+    {
+        if (this.comma)  this.pw.write(',');
+        this.pw.write("[");
+        this.comma = false;
+        return this;
+    }
+
+    public JSONWriter endArray()
+    {
+        this.pw.write(']');
+        this.comma = true;
+        return this;
+    }
+
+    public JSONWriter key(String key)
+    {
+        if (this.comma)  this.pw.write(',');
+        quote(key);
+        this.pw.write(':');
+        this.comma = false;
+        return this;
+    }
+
+    public JSONWriter value(final boolean b)
+    {
+        if (this.comma)  this.pw.write(',');
+        this.pw.write(b ? "true" : "false");
+        this.comma = true;
+        return this;
+    }
+
+    public JSONWriter value(final double d)
+    {
+        return this.value(new Double(d));
+    }
+
+    public JSONWriter value(final int i)
+    {
+        if (this.comma)  this.pw.write(',');
+        this.pw.write(String.valueOf(i));
+        this.comma = true;
+        return this;
+    }
+
+    public JSONWriter value(final long l)
+    {
+        if (this.comma)  this.pw.write(',');
+        this.pw.write(String.valueOf(l));
+        this.comma = true;
+        return this;
+    }
+
+    public JSONWriter value(final Object value)
+    {
+        if (this.comma)
+        {
+            this.pw.write(',');
+        }
+        if (value == null || value.equals(null))
+        {
+            this.pw.write("null");
+        }
+        else if (value instanceof Boolean )
+        {
+            this.pw.write(value.toString());
+        }
+        else if (value instanceof Number)
+        {
+            String str = value.toString();
+            if ( str.indexOf('.') == -1 || str.indexOf('e') > 0 || 
str.indexOf('E') > 0 )
+            {
+                this.pw.write(str);
+            } else {
+                while (str.endsWith("0"))
+                {
+                    str = str.substring(0, str.length() - 1);
+                }
+                if (str.endsWith("."))
+                {
+                    str = str.substring(0, str.length() - 1);
+                }
+                this.pw.write(str);
+            }
+        }
+        else
+        {
+            quote(value.toString());
+        }
+        this.comma = true;
+        return this;
+    }
+
+    /**
+     * Quote the provided value and escape some characters.
+     * @param value The value to quote
+     */
+    private void quote(final String value)
+    {
+        pw.print('"');
+        final int len = value.length();
+        for(int i=0;i<len;i++)
+        {
+            final char c = value.charAt(i);
+            switch(c){
+            case '"':
+                pw.print("\\\"");
+                break;
+            case '\\':
+                pw.print("\\\\");
+                break;
+            case '\b':
+                pw.print("\\b");
+                break;
+            case '\f':
+                pw.print("\\f");
+                break;
+            case '\n':
+                pw.print("\\n");
+                break;
+            case '\r':
+                pw.print("\\r");
+                break;
+            case '\t':
+                pw.print("\\t");
+                break;
+            case '/':
+                pw.print("\\/");
+                break;
+            default:
+                if ((c>='\u0000' && c<='\u001F') || (c>='\u007F' && 
c<='\u009F') || (c>='\u2000' && c<='\u20FF'))
+                {
+                    final String hex=Integer.toHexString(c);
+                    pw.print("\\u");
+                    for(int k=0;k<4-hex.length();k++){
+                        pw.print('0');
+                    }
+                    pw.print(hex.toUpperCase());
+                }
+                else{
+                    pw.print(c);
+                }
+            }
+        }
+        pw.print('"');
+    }
+}

Propchange: 
felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/JSONWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

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=1778522&r1=1778521&r2=1778522&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 Jan 13 10:09:32 2017
@@ -35,9 +35,6 @@ import javax.servlet.http.HttpServletRes
 import org.apache.felix.webconsole.DefaultVariableResolver;
 import org.apache.felix.webconsole.SimpleWebConsolePlugin;
 import org.apache.felix.webconsole.WebConsoleUtil;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONWriter;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
@@ -221,53 +218,45 @@ class WebConsolePlugin extends SimpleWeb
             throws IOException
     {
         final JSONWriter jw = new JSONWriter(pw);
-        try
-        {
-            jw.object();
+        jw.object();
 
-            jw.key("status"); //$NON-NLS-1$
-            final ServiceComponentRuntime scrService = getScrService();
-            if (scrService == null)
-            {
-                jw.value(-1);
-            }
-            else
+        jw.key("status"); //$NON-NLS-1$
+        final ServiceComponentRuntime scrService = getScrService();
+        if (scrService == null)
+        {
+            jw.value(-1);
+        }
+        else
+        {
+            jw.value(info.configurations.size());
+            if ( !info.configurations.isEmpty())
             {
-                jw.value(info.configurations.size());
-                if ( !info.configurations.isEmpty())
+                // render components
+                jw.key("data"); //$NON-NLS-1$
+                jw.array();
+                if (component != null)
+                {
+                    component(jw, component, true);
+                }
+                else
                 {
-                    // render components
-                    jw.key("data"); //$NON-NLS-1$
-                    jw.array();
-                    if (component != null)
+                    for( final ComponentDescriptionDTO cd : info.disabled )
                     {
-                        component(jw, component, true);
+                        disabledComponent(jw, cd);
                     }
-                    else
+                    for (final ComponentConfigurationDTO cfg : 
info.configurations)
                     {
-                        for( final ComponentDescriptionDTO cd : info.disabled )
-                        {
-                            disabledComponent(jw, cd);
-                        }
-                        for (final ComponentConfigurationDTO cfg : 
info.configurations)
-                        {
-                            component(jw, cfg, false);
-                        }
+                        component(jw, cfg, false);
                     }
-                    jw.endArray();
                 }
+                jw.endArray();
             }
-
-            jw.endObject();
-        }
-        catch (JSONException je)
-        {
-            throw new IOException(je.toString());
         }
+
+        jw.endObject();
     }
 
     void disabledComponent(final JSONWriter jw, final ComponentDescriptionDTO 
component)
-            throws JSONException
     {
         final String name = component.name;
 
@@ -302,7 +291,6 @@ class WebConsolePlugin extends SimpleWeb
     }
 
     void component(JSONWriter jw, ComponentConfigurationDTO component, boolean 
details)
-            throws JSONException
     {
         String id = String.valueOf(component.id);
         String name = component.description.name;
@@ -347,7 +335,6 @@ class WebConsolePlugin extends SimpleWeb
     }
 
     private void gatherComponentDetails(JSONWriter jw, 
ComponentConfigurationDTO component)
-            throws JSONException
     {
         final Bundle bundle = 
this.getBundleContext().getBundle(0).getBundleContext().getBundle(component.description.bundle.id);
 
@@ -396,13 +383,17 @@ class WebConsolePlugin extends SimpleWeb
 
         keyVal(jw, "Service Type", component.description.scope);
 
-        JSONArray buf = new JSONArray();
+        jw.object();
+        jw.key("key");
+        jw.value("Services");
+        jw.key("value");
+        jw.array();
         for (int i = 0; i < services.length; i++)
         {
-            buf.put(services[i]);
+            jw.value(services[i]);
         }
-
-        keyVal(jw, "Services", buf);
+        jw.endArray();
+        jw.endObject();
     }
 
     private SatisfiedReferenceDTO findReference(final 
ComponentConfigurationDTO component, final String name)
@@ -421,18 +412,22 @@ class WebConsolePlugin extends SimpleWeb
     {
         for(final ReferenceDTO dto : component.description.references)
         {
-            JSONArray buf = new JSONArray();
+            jw.object();
+            jw.key("key");
+            jw.value("Reference " + dto.name);
+            jw.key("value");
+            jw.array();
             final SatisfiedReferenceDTO satisfiedRef = 
findReference(component, dto.name);
 
-            buf.put(satisfiedRef != null ? "Satisfied" : "Unsatisfied");
-            buf.put("Service Name: " + dto.interfaceName);
+            jw.value(satisfiedRef != null ? "Satisfied" : "Unsatisfied");
+            jw.value("Service Name: " + dto.interfaceName);
             if (dto.target != null)
             {
-                buf.put("Target Filter: " + dto.target);
+                jw.value("Target Filter: " + dto.target);
             }
-            buf.put("Cardinality: " + dto.cardinality);
-            buf.put("Policy: " + dto.policy);
-            buf.put("Policy Option: " + dto.policyOption);
+            jw.value("Cardinality: " + dto.cardinality);
+            jw.value("Policy: " + dto.policy);
+            jw.value("Policy Option: " + dto.policyOption);
 
             // list bound services
             if ( satisfiedRef != null )
@@ -458,15 +453,16 @@ class WebConsolePlugin extends SimpleWeb
                         b.append(name);
                         b.append(")");
                     }
-                    buf.put(b.toString());
+                    jw.value(b.toString());
                 }
             }
             else
             {
-                buf.put("No Services bound");
+                jw.value("No Services bound");
             }
 
-            keyVal(jw, "Reference " + dto.name, buf.toString());
+            jw.endArray();
+            jw.endObject();
         }
     }
 
@@ -475,7 +471,11 @@ class WebConsolePlugin extends SimpleWeb
         Map<String, Object> props = component.properties;
         if (props != null)
         {
-            JSONArray buf = new JSONArray();
+            jw.object();
+            jw.key("key");
+            jw.value("Properties");
+            jw.key("value");
+            jw.array();
             TreeSet<String> keys = new TreeSet<String>(props.keySet());
             for (Iterator<String> ki = keys.iterator(); ki.hasNext();)
             {
@@ -486,23 +486,24 @@ class WebConsolePlugin extends SimpleWeb
                 Object prop = props.get(key);
                 prop = WebConsoleUtil.toString(prop);
                 b.append(prop);
-                buf.put(b.toString());
+                jw.value(b.toString());
             }
-
-            keyVal(jw, "Properties", buf);
+            jw.endArray();
+            jw.endObject();
         }
 
     }
 
     private void keyVal(JSONWriter jw, String key, Object value)
     {
-        try
+        if (key != null && value != null)
         {
-            WebConsoleUtil.keyVal(jw, key, value);
-        }
-        catch (JSONException je)
-        {
-            // don't care
+            jw.object();
+            jw.key("key"); //$NON-NLS-1$
+            jw.value(key);
+            jw.key("value"); //$NON-NLS-1$
+            jw.value(value);
+            jw.endObject();
         }
     }
 


Reply via email to