Package org.json

Examples of org.json.JSONArray


            resp.put("count", m_archs.size());
            resp.put("valid_count", StateUtils.getValidInstancesCount(m_archs));
            resp.put("invalid_count", StateUtils.getInvalidInstancesCount(m_archs));
            // End statline
           
            JSONArray instances = new JSONArray();
            for (Architecture arch : m_archs) {
                JSONObject instance = new JSONObject();
                instance.put("name", arch.getInstanceDescription().getName());
                instance.put("factory", arch.getInstanceDescription().getComponentDescription().getName());
                instance.put("state", StateUtils.getInstanceState(arch.getInstanceDescription().getState()));
                instances.put(instance);
            }
            resp.put("data", instances);
           
            pw.print(resp.toString());
        } catch (JSONException e) {
View Full Code Here


            resp.put("count", m_factories.size());
            resp.put("valid_count", StateUtils.getValidFactoriesCount(m_factories));
            resp.put("invalid_count", StateUtils.getInvalidFactoriesCount(m_factories));
            // End statline

            JSONArray factories = new JSONArray();
            for (Factory factory : m_factories) {
                String version = factory.getVersion();
                String name = factory.getName();
               
                String state = StateUtils.getFactoryState(factory.getState());
                String bundle = factory.getBundleContext().getBundle().getSymbolicName()
                    + " (" + factory.getBundleContext().getBundle().getBundleId() + ")";
                JSONObject fact = new JSONObject();
                fact.put("name", name);
                if (version != null) {
                    fact.put("version", version);
                }
                fact.put("bundle", bundle);
                fact.put("state", state);
                factories.put(fact);
            }
            resp.put("data", factories);
           
            pw.print(resp.toString());
        } catch (JSONException e) {
View Full Code Here

            resp.put("count", m_handlers.size());
            resp.put("valid_count", StateUtils.getValidHandlersCount(m_handlers));
            resp.put("invalid_count", StateUtils.getInvalidHandlersCount(m_handlers));
            // End statline
           
            JSONArray factories = new JSONArray();
            for (HandlerFactory factory : m_handlers) {
                String version = factory.getVersion();
                String name = factory.getHandlerName();
               
                String state = StateUtils.getFactoryState(factory.getState());
                String bundle = factory.getBundleContext().getBundle().getSymbolicName()
                    + " (" + factory.getBundleContext().getBundle().getBundleId() + ")";
                JSONObject fact = new JSONObject();
                fact.put("name", name);
                if (version != null) {
                    fact.put("version", version);
                }
                fact.put("bundle", bundle);
                fact.put("state", state);
                fact.put("type", factory.getType());
                if (! factory.getMissingHandlers().isEmpty()) {
                    fact.put("missing", factory.getMissingHandlers().toString());
                }
                factories.put(fact);
            }
            resp.put("data", factories);
           
            pw.print(resp.toString());
        } catch (JSONException e) {
View Full Code Here

            + " (" + factory.getBundleContext().getBundle().getBundleId() + ")";
            data.put("bundle", bundle);
           
            // Provided service specifications
            if (factory.getComponentDescription().getprovidedServiceSpecification().length != 0) {
                JSONArray services = new JSONArray
                    (Arrays.asList(factory.getComponentDescription().getprovidedServiceSpecification()));
                data.put("services", services);
            }
           
            // Properties
            PropertyDescription[] props = factory.getComponentDescription().getProperties();
            if (props != null  && props.length != 0) {
                JSONArray properties = new JSONArray();
                for (int i = 0; i < props.length; i++) {
                    JSONObject prop = new JSONObject();
                    prop.put("name", props[i].getName());
                    prop.put("type", props[i].getType());
                    prop.put("mandatory", props[i].isMandatory());
                    prop.put("immutable", props[i].isImmutable());
                    if (props[i].getValue() != null) {
                        prop.put("value", props[i].getValue());
                    }
                    properties.put(prop);
                }
                data.put("properties", properties);
            }
           
            if (! factory.getRequiredHandlers().isEmpty()) {
                JSONArray req = new JSONArray
                    (factory.getRequiredHandlers());
                data.put("requiredHandlers", req);
            }
           
            if (! factory.getMissingHandlers().isEmpty()) {
                JSONArray req = new JSONArray
                    (factory.getMissingHandlers());
                data.put("missingHandlers", req);
            }
           
            List<?> instances = StateUtils.getInstanceList(m_archs, name);
            if (! instances.isEmpty()) {
                JSONArray req = new JSONArray(instances);
                data.put("instances", req);
            }
           
            data.put("architecture", factory.getDescription().toString());
            resp.put("data", data);
View Full Code Here

            JSONObject data = new JSONObject();
            data.put("name", instance.getName());
            data.put("state", StateUtils.getInstanceState(instance.getState()));
            data.put("factory", instance.getComponentDescription().getName());
           
            JSONArray services = getProvidedServiceDetail(instance.getHandlerDescription("org.apache.felix.ipojo:provides"));
            if (services != null) {
                data.put("services", services);
            }
           
            JSONArray reqs = getRequiredServiceDetail(instance.getHandlerDescription("org.apache.felix.ipojo:requires"));
            if (reqs != null) {
                data.put("req", reqs);
            }
           
            data.put("architecture", instance.getDescription().toString());
View Full Code Here

    private JSONArray getProvidedServiceDetail(HandlerDescription hd) throws JSONException {
        if (hd == null) {
            return null;
        }

        JSONArray array = new JSONArray();
        ProvidedServiceHandlerDescription desc = (ProvidedServiceHandlerDescription) hd;

        for (ProvidedServiceDescription ps : desc.getProvidedServices()) {
            JSONObject svc = new JSONObject();
            String spec = Arrays.toString(ps.getServiceSpecifications());
            if (spec.startsWith("[")) {
                spec = spec.substring(1, spec.length() - 1);
            }
            svc.put("specification", spec);
            svc.put("state", StateUtils.getProvidedServiceState(ps.getState()));
           
            if (ps.getServiceReference() != null) {
                svc.put("id", (Long) ps.getServiceReference().getProperty(Constants.SERVICE_ID));
            }
           
            if (ps.getProperties() != null  &&!  ps.getProperties().isEmpty()) {
                svc.put("properties", getServiceProperties(ps.getProperties()));
            }

            array.put(svc);
        }
       
        return array;
    }
View Full Code Here

     * @param properties the properties
     * @return the JSON Array
     * @throws JSONException if the array cannot be created correctly
     */
    private JSONArray getServiceProperties(Properties properties) throws JSONException {
        JSONArray array = new JSONArray();
        Enumeration<Object> e = properties.keys();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            Object value = properties.get(key);
            JSONObject prop = new JSONObject();
            prop.put("name", key);
            if (value != null  && value.getClass().isArray()) {
                // TODO Test with primitive types
                prop.put("value", Arrays.toString((Object[]) value));
            } else if (value != null) {
                prop.put("value", value.toString());
            } else {
                prop.put("value", "no value");
            }
            array.put(prop);
        }
        return array;
    }
View Full Code Here

    private JSONArray getRequiredServiceDetail(
            HandlerDescription hd) throws JSONException {
        if (hd == null) {
            return null;
        }
        JSONArray array = new JSONArray();
        DependencyHandlerDescription desc = (DependencyHandlerDescription) hd;
        for (DependencyDescription dep : desc.getDependencies()) {
            JSONObject req = new JSONObject();
            req.put("specification",dep.getSpecification());
            req.put("id", dep.getId());
            req.put("state", StateUtils.getDependencyState(dep.getState()));
            req.put("policy", StateUtils.getDependencyBindingPolicy(dep.getPolicy()));
            req.put("optional", dep.isOptional());
            req.put("aggregate", dep.isMultiple());
            if (dep.getFilter() != null) {
                req.put("filter", dep.getFilter());
            }
            if (dep.getServiceReferences() != null  && dep.getServiceReferences().size() != 0) {
                req.put("matching",  getServiceReferenceList(dep.getServiceReferences()));
            }
           
            if (dep.getUsedServices() != null  && dep.getUsedServices().size() != 0) {
                req.put("used",  getServiceReferenceList(dep.getUsedServices()));
            }
           
            array.put(req);
        }

        return array;
    }
View Full Code Here

     * @param refs the service reference list
     * @return the JSON Array
     * @throws JSONException if the array cannot be created.
     */
    private JSONArray getServiceReferenceList(List<ServiceReference> refs) throws JSONException {
        JSONArray array = new JSONArray();
        if (refs != null) {
            for (ServiceReference ref : refs) {
                JSONObject reference = new JSONObject();
                if (ref.getProperty("instance.name") == null) {
                    reference.put("id", ref.getProperty(Constants.SERVICE_ID));
                } else {
                    reference.put("id", ref.getProperty(Constants.SERVICE_ID));
                    reference.put("instance", ref.getProperty("instance.name"));
                }
                array.put(reference);
            }
        }
        return array;
    }
View Full Code Here

      }

            input = method.getResponseBodyAsStream();

            JSONObject result = new JSONObject(new JSONTokener(new InputStreamReader(input)));
            JSONArray dataArray = (JSONArray) result.get("data");
            JSONObject firstElement = (JSONObject) dataArray.get(0);
            return " ["+firstElement.get("state")+"]";
    } catch (Exception e) {
      e.printStackTrace();
      return e.getMessage();
        } finally {
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.