Package org.osgi.service.packageadmin

Examples of org.osgi.service.packageadmin.PackageAdmin


   * <code>null</code> if the bundle could not be determined.
   */
  public String getBundleId(Object object) {
    if (object == null)
      return null;
    PackageAdmin packageAdmin = getBundleAdmin();
    if (packageAdmin == null)
      return null;
    Bundle source = packageAdmin.getBundle(object.getClass());
    if (source != null && source.getSymbolicName() != null)
      return source.getSymbolicName();
    return null;
  }
View Full Code Here


    // unregister the provider
    registration.unregister();
  }

  public Bundle[] getBundles(String symbolicName, String version) {
    PackageAdmin packageAdmin = getBundleAdmin();
    if (packageAdmin == null)
      return null;
    Bundle[] bundles = packageAdmin.getBundles(symbolicName, version);
    if (bundles == null)
      return null;
    // optimize for common case; length==1
    if (bundles.length == 1 && (bundles[0].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0)
      return bundles;
View Full Code Here

    }
    return (EnvironmentInfo) environmentTracker.getService();
  }

  public Bundle[] getFragments(Bundle bundle) {
    PackageAdmin packageAdmin = getBundleAdmin();
    if (packageAdmin == null)
      return null;
    return packageAdmin.getFragments(bundle);
  }
View Full Code Here

    }
    return (FrameworkLog) logTracker.getService();
  }

  public Bundle[] getHosts(Bundle bundle) {
    PackageAdmin packageAdmin = getBundleAdmin();
    if (packageAdmin == null)
      return null;
    return packageAdmin.getHosts(bundle);
  }
View Full Code Here

      DEBUG_PLUGIN_PREFERENCES = getBooleanOption(Platform.PI_RUNTIME + "/preferences/plugin", false); //$NON-NLS-1$
    }
  }

  public boolean isFragment(Bundle bundle) {
    PackageAdmin packageAdmin = getBundleAdmin();
    if (packageAdmin == null)
      return false;
    return (packageAdmin.getBundleType(bundle) & PackageAdmin.BUNDLE_TYPE_FRAGMENT) > 0;
  }
View Full Code Here

    public void testModuleRegistered() throws Exception {

        assertNotNull("BundleContext injected", bundleContext);

        ServiceReference sref = bundleContext.getServiceReference(PackageAdmin.class.getName());
        PackageAdmin pa = (PackageAdmin) bundleContext.getService(sref);
        assertNotNull("PackageAdmin not null", pa);

        Bundle[] bundles = pa.getBundles("example-module-reg", null);
        assertNotNull("Bundles not null", bundles);
        assertEquals("One bundle", 1, bundles.length);

        Bundle bundle = bundles[0];
        assertEquals("Bundle INSTALLED", Bundle.INSTALLED, bundle.getState());

        Class<?> clazz = bundle.loadClass(SimpleService.class.getName());
        assertNotNull("Loaded class", clazz);
        assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundle.getState());

        ExportedPackage[] exportedPackages = pa.getExportedPackages(bundle);
        assertNotNull("ExportedPackages not null", exportedPackages);
        assertEquals("One ExportedPackage", 1, exportedPackages.length);

        ExportedPackage exportedPackage = exportedPackages[0];
        assertEquals(SimpleService.class.getPackage().getName(), exportedPackage.getName());
View Full Code Here

            registration.unregister();
    }

    private void provideStiltsServer(BundleContext context) throws BundleException {
        ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
        PackageAdmin padmin = (PackageAdmin) context.getService(sref);
        if (padmin.getBundles("stilts-stomplet-server-bundle", null) == null) {
            installSupportBundle(context, ModuleIdentifier.create("org.jboss.netty"));
            installSupportBundle(context, ModuleIdentifier.create("org.projectodd.stilts")).start();
        }
    }
View Full Code Here

        // Deploy the bundle which contains the target service
        deployer.deploy(TARGET_BUNDLE_NAME);
        try {
            // Find the installed bundle using PackageAdmin
            ServiceReference sref = systemContext.getServiceReference(PackageAdmin.class.getName());
            PackageAdmin packageAdmin = (PackageAdmin) systemContext.getService(sref);
            Bundle[] bundles = packageAdmin.getBundles(TARGET_BUNDLE_NAME, null);
            assertNotNull("Bundles not null", bundles);
            assertEquals("One Bundle", 1, bundles.length);

            // Verify that the bundle got started automatically
            final Bundle targetBundle = bundles[0];
View Full Code Here

      Object adapted = adapterManager.getAdapter(adaptable,
          type.className);
      if (adapted instanceof IAdaptable)
        return (IAdaptable) adapted;

      PackageAdmin admin = getPackageAdmin();
      if (admin != null) {
        int lastDot = type.className.lastIndexOf('.');
        if (lastDot > 0) { // this lives in a package
          String packageName = type.className.substring(0, lastDot);
          ExportedPackage[] packages = admin
              .getExportedPackages(packageName);
          if (packages != null && packages.length == 1) {
            // if there is exactly one exporter of this
            // package
            // we can go further
View Full Code Here

     * Use {@link PackageAdmin#getBundles(String, String)} to find a deployed bundle by
     * symbolic name and version range
     */
    public static Bundle getDeployedBundle(BundleContext context, String symbolicName, String versionRange) {
        ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
        PackageAdmin packageAdmin = (PackageAdmin) context.getService(sref);
        Bundle[] bundles = packageAdmin.getBundles(symbolicName, versionRange);
        assertNotNull("Bundles found", bundles);
        assertEquals("One bundle found", 1, bundles.length);
        return bundles[0];
    }
View Full Code Here

TOP

Related Classes of org.osgi.service.packageadmin.PackageAdmin

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.