Package org.osgi.framework

Examples of org.osgi.framework.Bundle.adapt()


    private void installAndStartBundles(ArtifactResolver resolver, BundleContext context, List<BundleInfo> bundles) {
        for (BundleInfo bundleInfo : bundles) {
            try {
                URI resolvedURI = resolver.resolve(bundleInfo.uri);
                Bundle b = context.installBundle(bundleInfo.uri.toString(), resolvedURI.toURL().openStream());
                b.adapt(BundleStartLevel.class).setStartLevel(bundleInfo.startLevel);
                if (isNotFragment(b)) {
                    b.start();
                }
            } catch (Exception  e) {
                throw new RuntimeException("Error installing bundle listed in " + STARTUP_PROPERTIES_FILE_NAME
View Full Code Here


        // Install the bundle as module if it has not already happened
        // A bundle that could not get resolved will have no associated module
        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        Module module = runtime.getModule(identity);
        BundleWiring wiring = bundle.adapt(BundleWiring.class);
        if (module == null && wiring != null) {
            try {
                ClassLoader classLoader = wiring.getClassLoader();
                module = runtime.installModule(classLoader, resource, null);
            } catch (ModuleException ex) {
View Full Code Here

        // skip first bundle
        iterator.next();
        // attempt to load the class from the remaining bundles
        while (iterator.hasNext()) {
            Bundle bundle = iterator.next();
            BundleWiring wiring = bundle.adapt(BundleWiring.class);
            if (wiring != null) {
                List<BundleCapability> capabilities = wiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE);
                if (capabilities != null && !capabilities.isEmpty()) {
                    for (BundleCapability capability : capabilities) {
                        Map<String, Object> attributes = capability.getAttributes();
View Full Code Here

    if (b == null) {
      ThreadLocalSubsystem.set(subsystem);
      b = subsystem.getRegion().installBundleAtLocation(location, createRegionContextBundle(symbolicName));
      // The start level of all managed bundles, including the region
      // context bundle, should be 1.
      b.adapt(BundleStartLevel.class).setStartLevel(1);
    }
    Utils.installResource(b.adapt(BundleRevision.class), subsystem);
    // The region context bundle must be started persistently.
    b.start();
  }
View Full Code Here

      b = subsystem.getRegion().installBundleAtLocation(location, createRegionContextBundle(symbolicName));
      // The start level of all managed bundles, including the region
      // context bundle, should be 1.
      b.adapt(BundleStartLevel.class).setStartLevel(1);
    }
    Utils.installResource(b.adapt(BundleRevision.class), subsystem);
    // The region context bundle must be started persistently.
    b.start();
  }
 
  public static void uninstallRegionContextBundle(BasicSubsystem subsystem) {
View Full Code Here

    String symbolicName = SYMBOLICNAME_PREFIX + subsystem.getSubsystemId();
    Bundle bundle = subsystem.getRegion().getBundle(symbolicName, VERSION);
    if (bundle == null)
      throw new IllegalStateException("Missing region context bundle: " + symbolicName);
    ThreadLocalSubsystem.set(subsystem);
    BundleRevision revision = bundle.adapt(BundleRevision.class);
    try {
      bundle.uninstall();
    }
    catch (BundleException e) {
      // TODO Should we really eat this? At least log it?
View Full Code Here

      throw new IllegalStateException("No subsystem found for bundle " + bundleRevision + " in region " + region);
  }
 
  private void handleInstalledEvent(BundleEvent event) {
    Bundle origin = event.getOrigin();
    BundleRevision originRevision = origin.adapt(BundleRevision.class);
    Bundle bundle = event.getBundle();
    BundleRevision bundleRevision = bundle.adapt(BundleRevision.class);
    if (bundleRevision == null)
      // The event is being processed asynchronously and the installed
      // bundle has been uninstalled. Nothing we can do.
View Full Code Here

 
  private void handleInstalledEvent(BundleEvent event) {
    Bundle origin = event.getOrigin();
    BundleRevision originRevision = origin.adapt(BundleRevision.class);
    Bundle bundle = event.getBundle();
    BundleRevision bundleRevision = bundle.adapt(BundleRevision.class);
    if (bundleRevision == null)
      // The event is being processed asynchronously and the installed
      // bundle has been uninstalled. Nothing we can do.
      return;
    bundleToRevision.put(bundle, bundleRevision);
View Full Code Here

      String type = clause.getType();
      if (IdentityNamespace.TYPE_BUNDLE.equals(type) || IdentityNamespace.TYPE_FRAGMENT.equals(type)) {
        Bundle resource = Activator.getInstance().getBundleContext().getBundle(0).getBundleContext().getBundle(resourceId);
        if (resource == null)
          return null;
        return resource.adapt(BundleRevision.class);
      }
      else
        return Activator.getInstance().getSubsystems().getSubsystemById(resourceId);
    }
    return findContent(clause.toRequirement(this));
View Full Code Here

    // subsystems implementation to 1 in case the framework's default bundle
    // start level has been changed. Otherwise, start failures will occur
    // if a subsystem is started at a lower start level than the default.
    // Setting the start level does no harm since all managed bundles are
    // started transiently anyway.
    bundle.adapt(BundleStartLevel.class).setStartLevel(1);
    return bundle.adapt(BundleRevision.class);
  }
}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.