Search in sources :

Example 1 with Capability

use of org.osgi.service.obr.Capability in project felix by apache.

the class OsgiBundleRepositoryRenderHelper method toJSON.

private final void toJSON(JSONWriter json, Resource resource, Bundle[] bundles, boolean details) throws IOException {
    final String symbolicName = resource.getSymbolicName();
    final Version version = resource.getVersion();
    String installed = "";
    for (int i = 0; symbolicName != null && installed.length() == 0 && bundles != null && i < bundles.length; i++) {
        final Version ver = bundles[i].getVersion();
        if (symbolicName.equals(bundles[i].getSymbolicName())) {
            installed = ver.toString();
        }
    }
    json.object();
    // $NON-NLS-1$
    json.key("id");
    json.value(resource.getId());
    // $NON-NLS-1$
    json.key("presentationname");
    json.value(resource.getPresentationName());
    // $NON-NLS-1$
    json.key("symbolicname");
    json.value(symbolicName);
    // $NON-NLS-1$
    json.key("url");
    json.value(resource.getURL());
    // $NON-NLS-1$
    json.key("version");
    json.value(version);
    // $NON-NLS-1$
    json.key("categories");
    json.value(resource.getCategories());
    // $NON-NLS-1$
    json.key("installed");
    json.value(installed);
    if (details) {
        Capability[] caps = resource.getCapabilities();
        if (caps != null) {
            // $NON-NLS-1$
            json.key("capabilities");
            json.array();
            for (int i = 0; i < caps.length; i++) {
                // $NON-NLS-1$
                json.key("name");
                json.value(caps[i].getName());
                // $NON-NLS-1$
                json.key("properties");
                toJSON(json, caps[i].getProperties());
            }
            json.endArray();
        }
        Requirement[] reqs = resource.getRequirements();
        if (caps != null) {
            // $NON-NLS-1$
            json.key("requirements");
            json.array();
            for (int i = 0; i < reqs.length; i++) {
                // $NON-NLS-1$
                json.key("name");
                json.value(reqs[i].getName());
                // $NON-NLS-1$
                json.key("filter");
                json.value(reqs[i].getFilter());
                // $NON-NLS-1$
                json.key("optional");
                json.value(reqs[i].isOptional());
            }
            json.endArray();
        }
        final RepositoryAdmin admin = (RepositoryAdmin) getRepositoryAdmin();
        Resolver resolver = admin.resolver();
        resolver.add(resource);
        // (Resolver.NO_OPTIONAL_RESOURCES);
        resolver.resolve();
        Resource[] required = resolver.getRequiredResources();
        if (required != null) {
            // $NON-NLS-1$
            json.key("required");
            json.array();
            for (int i = 0; i < required.length; i++) {
                toJSON(json, required[i], bundles, false);
            }
            json.endArray();
        }
        Resource[] optional = resolver.getOptionalResources();
        if (optional != null) {
            // $NON-NLS-1$
            json.key("optional");
            json.array();
            for (int i = 0; optional != null && i < optional.length; i++) {
                toJSON(json, optional[i], bundles, false);
            }
            json.endArray();
        }
        Requirement[] /*Reason*/
        unsatisfied = resolver.getUnsatisfiedRequirements();
        if (unsatisfied != null) {
            // $NON-NLS-1$
            json.key("unsatisfied");
            json.array();
            for (int i = 0; i < unsatisfied.length; i++) {
                // $NON-NLS-1$
                json.key("name");
                json.value(unsatisfied[i].getName());
                // $NON-NLS-1$
                json.key("filter");
                json.value(unsatisfied[i].getFilter());
                // $NON-NLS-1$
                json.key("optional");
                json.value(unsatisfied[i].isOptional());
            }
            json.endArray();
        }
    }
    json.endObject();
}
Also used : Requirement(org.osgi.service.obr.Requirement) RepositoryAdmin(org.osgi.service.obr.RepositoryAdmin) Capability(org.osgi.service.obr.Capability) Resolver(org.osgi.service.obr.Resolver) Version(org.osgi.framework.Version) Resource(org.osgi.service.obr.Resource)

Aggregations

Version (org.osgi.framework.Version)1 Capability (org.osgi.service.obr.Capability)1 RepositoryAdmin (org.osgi.service.obr.RepositoryAdmin)1 Requirement (org.osgi.service.obr.Requirement)1 Resolver (org.osgi.service.obr.Resolver)1 Resource (org.osgi.service.obr.Resource)1