Package org.osgi.framework.wiring

Examples of org.osgi.framework.wiring.BundleRevision


                    // optionally resolved revision is to blame (typically a fragment).
                    // If so, then remove the optionally resolved revision and try
                    // again; otherwise, rethrow the resolve exception.
                    if (rethrow != null)
                    {
                        BundleRevision faultyRevision =
                            getActualBundleRevision(rethrow.getRevision());
                        if (rethrow.getRequirement() instanceof HostedRequirement)
                        {
                            faultyRevision =
                                ((HostedRequirement) rethrow.getRequirement())
View Full Code Here


    private static Map<BundleRevision, List<ResolverWire>> populateWireMap(
        BundleRevision revision, Map<BundleRevision, Packages> revisionPkgMap,
        Map<BundleRevision, List<ResolverWire>> wireMap,
        Candidates allCandidates)
    {
        BundleRevision unwrappedRevision = getActualBundleRevision(revision);
        if ((unwrappedRevision.getWiring() == null)
            && !wireMap.containsKey(unwrappedRevision))
        {
            wireMap.put(unwrappedRevision, (List<ResolverWire>) Collections.EMPTY_LIST);

            List<ResolverWire> packageWires = new ArrayList<ResolverWire>();
            List<ResolverWire> bundleWires = new ArrayList<ResolverWire>();
            List<ResolverWire> capabilityWires = new ArrayList<ResolverWire>();

            for (BundleRequirement req : revision.getDeclaredRequirements(null))
            {
                SortedSet<BundleCapability> cands = allCandidates.getCandidates(req);
                if ((cands != null) && (cands.size() > 0))
                {
                    BundleCapability cand = cands.iterator().next();
                    // Ignore revisions that import themselves.
                    if (!revision.equals(cand.getRevision()))
                    {
                        if (cand.getRevision().getWiring() == null)
                        {
                            populateWireMap(cand.getRevision(),
                                revisionPkgMap, wireMap, allCandidates);
                        }
                        Packages candPkgs = revisionPkgMap.get(cand.getRevision());
                        ResolverWire wire = new ResolverWireImpl(
                            unwrappedRevision,
                            getActualRequirement(req),
                            getActualBundleRevision(cand.getRevision()),
                            getActualCapability(cand));
                        if (req.getNamespace().equals(BundleRevision.PACKAGE_NAMESPACE))
                        {
                            packageWires.add(wire);
                        }
                        else if (req.getNamespace().equals(BundleRevision.BUNDLE_NAMESPACE))
                        {
                            bundleWires.add(wire);
                        }
                        else
                        {
                            capabilityWires.add(wire);
                        }
                    }
                }
            }

            // Combine package wires with require wires last.
            packageWires.addAll(bundleWires);
            packageWires.addAll(capabilityWires);
            wireMap.put(unwrappedRevision, packageWires);

            // Add host wire for any fragments.
            if (revision instanceof HostBundleRevision)
            {
                List<BundleRevision> fragments = ((HostBundleRevision) revision).getFragments();
                for (BundleRevision fragment : fragments)
                {
                    List<ResolverWire> hostWires = wireMap.get(fragment);
                    if (hostWires == null)
                    {
                        hostWires = new ArrayList<ResolverWire>();
                        wireMap.put(fragment, hostWires);
                    }
                    hostWires.add(
                        new ResolverWireImpl(
                            getActualBundleRevision(fragment),
                            fragment.getDeclaredRequirements(
                                BundleRevision.HOST_NAMESPACE).get(0),
                            unwrappedRevision,
                            unwrappedRevision.getDeclaredCapabilities(
                                BundleRevision.HOST_NAMESPACE).get(0)));
                }
            }
        }
View Full Code Here

     * @param m the module whose wrapper is desired.
     * @return the wrapper module or the module itself if it was not wrapped.
    **/
    public BundleRevision getWrappedHost(BundleRevision m)
    {
        BundleRevision wrapped = m_allWrappedHosts.get(m);
        return (wrapped == null) ? m : wrapped;
    }
View Full Code Here

        final Map<String, BundleRevision> singletons = new HashMap<String, BundleRevision>();

        for (Iterator<BundleRevision> it = m_involvedRevisions.iterator(); it.hasNext(); )
        {
            BundleRevision br = it.next();
            if (isSingleton(br))
            {
                if (!init)
                {
                    populateDependents();
                    init = true;
                }

                // See if there is an existing singleton for the
                // revision's symbolic name.
                BundleRevision singleton = singletons.get(br.getSymbolicName());
                // If there is no existing singleton or this revision is
                // a resolved singleton or this revision has a higher version
                // and the existing singleton is not resolved, then select
                // this revision as the singleton.
                if ((singleton == null)
                    || (br.getWiring() != null)
                    || ((br.getVersion().compareTo(singleton.getVersion()) > 0)
                        && (singleton.getWiring() == null)))
                {
                    singletons.put(br.getSymbolicName(), br);
                    // Remove the singleton revision from the candidates
                    // if it wasn't selected.
                    if (singleton != null)
                    {
                        removeRevision(
                            singleton,
                            new ResolveException(
                                "Conflict with another singleton.", singleton, null));
                    }
                }
                else
                {
                    removeRevision(br,
                        new ResolveException(
                            "Conflict with another singleton.", br, null));
                }
            }
        }

        // If the root is a singleton, then prefer it over any other singleton.
// TODO: OSGi R4.3/SINGLETON - How do we prefer the root as a singleton?
/*
        if ((m_root != null) && isSingleton(m_root))
        {
            BundleRevision singleton = singletons.get(m_root.getSymbolicName());
            singletons.put(m_root.getSymbolicName(), m_root);
            if ((singleton != null) && !singleton.equals(m_root))
            {
                if (singleton.getWiring() != null)
                {
                    throw new ResolveException(
                        "Cannot resolve singleton "
                        + m_root
                        + " because "
                        + singleton
                        + " singleton is already resolved.",
                        m_root, null);
                }
                removeRevision(singleton);
            }
        }
*/

        // Make sure selected singletons do not conflict with existing
        // singletons passed into this method.
        for (int i = 0; (existingSingletons != null) && (i < existingSingletons.size()); i++)
        {
            BundleRevision existing = existingSingletons.get(i);
            BundleRevision singleton = singletons.get(existing.getSymbolicName());
            if ((singleton != null) && (singleton != existing))
            {
                singletons.remove(singleton.getSymbolicName());
                removeRevision(singleton,
                    new ResolveException(
                        "Conflict with another singleton.", singleton, null));
            }
        }
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

    // that already existed in its region. Not sure this will be the final resting place. Plus, there are issues
    // since this does not take into account the possibility of already existing bundles going away or new bundles
    // being installed out of band while this initialization is taking place. Need a bundle event hook for that.
    BundleContext context = Activator.getInstance().getBundleContext().getBundle(org.osgi.framework.Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext();
    for (Bundle bundle : context.getBundles()) {
      BundleRevision revision = bundle.adapt(BundleRevision.class);
      if (revision == null)
        // The bundle has been uninstalled. Do not process.
        continue;
      if (!resourceReferences.getSubsystems(revision).isEmpty())
        continue;
View Full Code Here

    return new ArrayList<BasicSubsystem>(idToSubsystem.values());
  }
 
  // TODO Not very pretty. A quick fix.
  public Object[] getSubsystemsByBundle(Bundle bundle) {
    BundleRevision revision = null;
    ArrayList<BasicSubsystem> result = new ArrayList<BasicSubsystem>();
    synchronized (subsystemToConstituents) {
      for (BasicSubsystem subsystem : subsystemToConstituents.keySet()) {
        for (Resource constituent : getConstituents(subsystem)) {
          if (constituent instanceof BundleConstituent &&
View Full Code Here

  }

  public void filterResolvable(Collection<BundleRevision> candidates) {
    try {
      for (Iterator<BundleRevision> iterator = candidates.iterator(); iterator.hasNext();) {
        BundleRevision revision = iterator.next();
        if (revision.getSymbolicName().startsWith(Constants.RegionContextBundleSymbolicNamePrefix))
          // Don't want to filter out the region context bundle.
          continue;
        Collection<BasicSubsystem> subsystems = this.subsystems.getSubsystemsReferencing(revision);
        for (BasicSubsystem subsystem : subsystems) {
          if (subsystem.isFeature()) {
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.
      return;
    bundleToRevision.put(bundle, bundleRevision);
View Full Code Here

  }
 
  @SuppressWarnings("unchecked")
  private void handleUninstalledEvent(BundleEvent event) {
    Bundle bundle = event.getBundle();
    BundleRevision revision = bundleToRevision.remove(bundle);
    if (ThreadLocalSubsystem.get() != null)
      return;
    Collection<BasicSubsystem> subsystems;
    if (revision == null) {
      // The bundle was installed while the bundle event hook was unregistered.
View Full Code Here

TOP

Related Classes of org.osgi.framework.wiring.BundleRevision

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.