Package org.osgi.framework

Examples of org.osgi.framework.Bundle


     *
     * @param id the id number.
     * @return the bundle or null if not found.
     */
    private Bundle getBundleById(String id) {
        Bundle bundle = null;
        try {
            long idNumber = Long.parseLong(id);
            bundle = bundleContext.getBundle(idNumber);
        } catch (NumberFormatException nfe) {
            // ignore
View Full Code Here


   
    public List<Bundle> getBundlesByURL(String url) {
        List<Bundle> bundleList = new ArrayList<Bundle>();
        try {
            Long id = Long.parseLong(url);
            Bundle bundle = bundleContext.getBundle(id);
            if (bundle != null) {
                bundleList.add(bundle);
            }
        } catch (NumberFormatException e) {
            for (int i = 0; i < bundleContext.getBundles().length; i++) {
                Bundle bundle = bundleContext.getBundles()[i];
                if (isMavenSnapshotUrl(bundle.getLocation()) && wildCardMatch(bundle.getLocation(), url)) {
                    bundleList.add(bundle);
                }
            }
        }
        return bundleList;
View Full Code Here

    List<Long> ids;

    protected Object doExecute() throws Exception {
        if (ids != null && !ids.isEmpty()) {
            for (long id : ids) {
                Bundle bundle = getBundleContext().getBundle(id);
                if (bundle != null) {
                    printInfo(bundle);
                } else {
                    System.err.println("Bundle ID " + id + " is invalid.");
                }
View Full Code Here

    List<Long> ids;

    protected Object doExecute() throws Exception {
        if (ids != null && !ids.isEmpty()) {
            for (long id : ids) {
                Bundle bundle = getBundleContext().getBundle(id);
                if (bundle != null) {
                    boolean headerPrinted = false;
                    boolean needSeparator = false;
                    ServiceReference[] refs = null;

                    // Get registered or in-use services.
                    if (inUse) {
                        refs = bundle.getServicesInUse();
                    } else {
                        refs = bundle.getRegisteredServices();
                    }

                    // Print properties for each service.
                    for (int refIdx = 0;
                         (refs != null) && (refIdx < refs.length);
View Full Code Here

    protected Object doExecute() throws Exception {
        new Thread() {
            public void run() {
                try {
                    Bundle bundle = getBundleContext().getBundle(0);
                    bundle.stop();
                } catch (Exception e) {
                    log.error("Error when shutting down Apache Karaf", e);
                }
            }
        }.start();
View Full Code Here

                return null;
            }

            if (ids != null && !ids.isEmpty()) {
                for (long id : ids) {
                    Bundle bundle = getBundleContext().getBundle(id);
                    if (bundle != null) {
                        printHeaders(bundle);
                    } else {
                        System.err.println("Bundle ID " + id + " is invalid.");
                    }
View Full Code Here

        expect(serviceRef.getPropertyKeys()).andReturn(Collections.list(keyPropMap.keys()).toArray(new String[]{})).anyTimes();
        return serviceRef;
    }
   
    Bundle createBundle(long id, String name) {
        Bundle bundle = createMock(Bundle.class);
        expect(bundle.getBundleId()).andReturn(id).anyTimes();
        Dictionary<String, String> headers = new Hashtable<String, String>();
        headers.put(Constants.BUNDLE_NAME, name);
        expect(bundle.getHeaders()).andReturn(headers).anyTimes();
        return bundle;
    }
View Full Code Here

        expect(bundle.getHeaders()).andReturn(headers).anyTimes();
        return bundle;
    }
   
    private Bundle[] createBundles() {
        Bundle bundle1 = createBundle(1, "Bundle A");
        Bundle bundle2 = createBundle(2, "Bundle B");
        Bundle bundle3 = createBundle(3, "Bundle C");

        ServiceReference<?> ref1 = createServiceRef(Constants.OBJECTCLASS, new String[]{"org.example.MyService"},
            "key1", "value1");
        ServiceReference<?> ref2 = createServiceRef(Constants.OBJECTCLASS, new String[]{"org.example.OtherService"}, "key2", 1);

        addRegisteredServices(bundle1, ref1, ref2);
        addRegisteredServices(bundle2, ref2);
        expect(bundle3.getRegisteredServices()).andReturn(null).anyTimes();

        expect(bundle1.getServicesInUse()).andReturn(null).anyTimes();
        addUsedServices(bundle2, ref1);
        addUsedServices(bundle3, ref1, ref2);
       
View Full Code Here

        for (ConfigFileInfo configFile : feature.getConfigurationFiles()) {
          installConfigurationFile(configFile.getLocation(), configFile.getFinalname(), verbose);
        }
        Set<Long> bundles = new TreeSet<Long>();
        for (BundleInfo bInfo : resolve(feature)) {
            Bundle b = installBundleIfNeeded(state, bInfo, verbose);
            bundles.add(b.getBundleId());
            state.bundleInfos.put(b.getBundleId(), bInfo);
        }
        state.features.put(feature, bundles);
    }
View Full Code Here

            return bundles;
        }
        // Second pass: for each bundle, check if there is any unresolved optional package that could be resolved
        Map<Bundle, List<Clause>> imports = new HashMap<Bundle, List<Clause>>();
        for (Iterator<Bundle> it = bundles.iterator(); it.hasNext();) {
            Bundle b = it.next();
            String importsStr = (String) b.getHeaders().get(Constants.IMPORT_PACKAGE);
            List<Clause> importsList = getOptionalImports(importsStr);
            if (importsList.isEmpty()) {
                it.remove();
            } else {
                imports.put(b, importsList);
            }
        }
        if (bundles.isEmpty()) {
            return bundles;
        }
        // Third pass: compute a list of packages that are exported by our bundles and see if
        //             some exported packages can be wired to the optional imports
        List<Clause> exports = new ArrayList<Clause>();
        for (Bundle b : state.installed) {
            String exportsStr = (String) b.getHeaders().get(Constants.EXPORT_PACKAGE);
            if (exportsStr != null) {
                Clause[] exportsList = Parser.parseHeader(exportsStr);
                exports.addAll(Arrays.asList(exportsList));
            }
        }
        for (Iterator<Bundle> it = bundles.iterator(); it.hasNext();) {
            Bundle b = it.next();
            List<Clause> importsList = imports.get(b);
            for (Iterator<Clause> itpi = importsList.iterator(); itpi.hasNext();) {
                Clause pi = itpi.next();
                boolean matching = false;
                for (Clause pe : exports) {
                    if (pi.getName().equals(pe.getName())) {
                        String evStr = pe.getAttribute(Constants.VERSION_ATTRIBUTE);
                        String ivStr = pi.getAttribute(Constants.VERSION_ATTRIBUTE);
                        Version exported = evStr != null ? Version.parseVersion(evStr) : Version.emptyVersion;
                        VersionRange imported = ivStr != null ? VersionRange.parseVersionRange(ivStr) : VersionRange.ANY_VERSION;
                        if (imported.contains(exported)) {
                            matching = true;
                            break;
                        }
                    }
                }
                if (!matching) {
                    itpi.remove();
                }
            }
            if (importsList.isEmpty()) {
                it.remove();
            } else {
                LOGGER.debug("Refeshing bundle {} ({}) to solve the following optional imports", b.getSymbolicName(), b.getBundleId());
                for (Clause p : importsList) {
                    LOGGER.debug("    {}", p);
                }

            }
View Full Code Here

TOP

Related Classes of org.osgi.framework.Bundle

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.