Package org.json

Examples of org.json.JSONArray


        }

        keyVal(jw, "Service Type", component.isServiceFactory() ? "service factory"
            : "service");

        JSONArray buf = new JSONArray();
        for (int i = 0; i < services.length; i++)
        {
            buf.put(services[i]);
        }

        keyVal(jw, "Services", buf);
    }
View Full Code Here


        Reference[] refs = component.getReferences();
        if (refs != null)
        {
            for (int i = 0; i < refs.length; i++)
            {
                JSONArray buf = new JSONArray();
                buf.put(refs[i].isSatisfied() ? "Satisfied" : "Unsatisfied");
                buf.put("Service Name: " + refs[i].getServiceName());
                if (refs[i].getTarget() != null)
                {
                    buf.put("Target Filter: " + refs[i].getTarget());
                }
                buf.put("Multiple: " + (refs[i].isMultiple() ? "multiple" : "single"));
                buf.put("Optional: " + (refs[i].isOptional() ? "optional" : "mandatory"));
                buf.put("Policy: " + (refs[i].isStatic() ? "static" : "dynamic"));

                // list bound services
                ServiceReference[] boundRefs = refs[i].getServiceReferences();
                if (boundRefs != null && boundRefs.length > 0)
                {
                    for (int j = 0; j < boundRefs.length; j++)
                    {
                        final StringBuffer b = new StringBuffer();
                        b.append("Bound Service ID ");
                        b.append(boundRefs[j].getProperty(Constants.SERVICE_ID));

                        String name = (String) boundRefs[j].getProperty(ComponentConstants.COMPONENT_NAME);
                        if (name == null)
                        {
                            name = (String) boundRefs[j].getProperty(Constants.SERVICE_PID);
                            if (name == null)
                            {
                                name = (String) boundRefs[j].getProperty(Constants.SERVICE_DESCRIPTION);
                            }
                        }
                        if (name != null)
                        {
                            b.append(" (");
                            b.append(name);
                            b.append(")");
                        }
                        buf.put(b.toString());
                    }
                }
                else
                {
                    buf.put("No Services bound");
                }

                keyVal(jw, "Reference " + refs[i].getName(), buf.toString());
            }
        }
    }
View Full Code Here

    private void listProperties(JSONWriter jw, Component component)
    {
        Dictionary props = component.getProperties();
        if (props != null)
        {
            JSONArray buf = new JSONArray();
            TreeSet keys = new TreeSet(Util.list(props.keys()));
            for (Iterator ki = keys.iterator(); ki.hasNext();)
            {
                final String key = (String) ki.next();
                final StringBuffer b = new StringBuffer();
                b.append(key).append(" = ");

                Object prop = props.get(key);
                prop = WebConsoleUtil.toString(prop);
                b.append(prop);
                buf.put(b.toString());
            }

            keyVal(jw, "Properties", buf);
        }
View Full Code Here

    }

    private static final JSONArray doFindDuplicates(
        final Map/*<String, Set<ExportedPackage>>*/exports) throws JSONException
    {
        final JSONArray ret = new JSONArray();
        for (Iterator entryIter = exports.entrySet().iterator(); entryIter.hasNext();)
        {
            Entry/*<String, Set<ExportedPackage>>*/exportEntry = (Entry) entryIter.next();
            Set/*<ExportedPackage>*/exportSet = (Set) exportEntry.getValue();
            if (exportSet.size() > 1)
            {
                final JSONObject container = new JSONObject();
                ret.put(container);
                for (Iterator packageIter = exportSet.iterator(); packageIter.hasNext();)
                {
                    ExportedPackage exportedPackage = (ExportedPackage) packageIter.next();
                    final JSONObject json = toJSON(exportedPackage);
                    container//
View Full Code Here

   */
  public void submitMetric(String metricName, long value) {
    if(metricNames.add(metricName)) {
      JSONObject envelope = new JSONObject();
      try {
        envelope.put("metric-names", new JSONArray(new String[]{metricName}));
        SharedChannelGroup.getInstance().write(envelope);
        SharedChannelGroup.getInstance().write(packageMetricUpdate(Collections.singletonMap(metricName, value)));
      } catch (JSONException e) {
        log.error("Failed to submit metric", e);
      }     
View Full Code Here

        newNames.add(s);
      }
    }
    try {
      JSONObject envelope = new JSONObject();
      envelope.put("metric-names", new JSONArray(newNames.toArray(new String[newNames.size()])));
      SharedChannelGroup.getInstance().write(envelope);
    } catch (JSONException e) {
      log.error("Failed to submit metric names", e);
    }   
    try {
View Full Code Here

        newNames.add(s);
      }
    }
    if(!newNames.isEmpty()) {
      JSONObject envelope = new JSONObject();
      envelope.put("metric-names", new JSONArray(newNames));
      SharedChannelGroup.getInstance().write(envelope);
    }
  }
View Full Code Here

  /**
   * Returns a JSONArray of all the registered metric names
   * @return the metricNames
   */
  public JSONObject getMetricNamesJSON() {
    JSONArray arr = new JSONArray(metricNames);
    JSONObject mn = new JSONObject();
    try {
      mn.put("metric-names", arr);
    } catch (JSONException e) {
      e.printStackTrace();
View Full Code Here

  /**
   * Returns a JSON string of all the registered metric names
   * @return the metricNames
   */
  public String getMetricNames() {
    JSONArray arr = new JSONArray(metricNames);
    JSONObject mn = new JSONObject();
    try {
      mn.put("metric-names", arr);
    } catch (JSONException e) {
      e.printStackTrace();
View Full Code Here

  public static String getUploader(final String JSON_DATA) {
    final String duration = "";
    try {
      final JSONObject json = new JSONObject(JSON_DATA);
      final JSONObject dataObject = json.getJSONObject("entry");
      final JSONArray author = dataObject.getJSONArray("author");
      final JSONObject userInfo = author.getJSONObject(0);
      final JSONObject userNameObject = userInfo.getJSONObject("name");
      final String username = userNameObject.getString("$t");

      return username;
    } catch (final JSONException e) {
View Full Code Here

TOP

Related Classes of org.json.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.