Package org.osgi.framework.wiring

Examples of org.osgi.framework.wiring.BundleCapability


                        wire.getRequirerWiring().getRevision(),
                        (BundleRequirementImpl) r);
                }
                // Wrap the capability as a hosted capability if it comes
                // from a fragment, since we will need to know the host.
                BundleCapability c = wire.getCapability();
                if (!c.getRevision().equals(wire.getProviderWiring().getRevision()))
                {
                    c = new HostedCapability(
                        wire.getProviderWiring().getRevision(),
                        (BundleCapabilityImpl) c);
                }
                reqs.add(r);
                caps.add(c);
            }

            // Since the revision is resolved, it could be dynamically importing,
            // so check to see if there are candidates for any of its dynamic
            // imports.
            for (BundleRequirement req
                : Util.getDynamicRequirements(revision.getWiring().getRequirements(null)))
            {
                // Get the candidates for the current requirement.
                SortedSet<BundleCapability> candCaps =
                    allCandidates.getCandidates((BundleRequirementImpl) req);
                // Optional requirements may not have any candidates.
                if (candCaps == null)
                {
                    continue;
                }

                BundleCapability cap = candCaps.iterator().next();
                reqs.add(req);
                caps.add(cap);
                isDynamicImporting = true;
                // Can only dynamically import one at a time, so break
                // out of the loop after the first.
                break;
            }
        }
        else
        {
            for (BundleRequirement req : revision.getDeclaredRequirements(null))
            {
                String resolution = req.getDirectives().get(Constants.RESOLUTION_DIRECTIVE);
                if ((resolution == null)
                    || !resolution.equals(FelixConstants.RESOLUTION_DYNAMIC))
                {
                    // Get the candidates for the current requirement.
                    SortedSet<BundleCapability> candCaps =
                        allCandidates.getCandidates((BundleRequirementImpl) req);
                    // Optional requirements may not have any candidates.
                    if (candCaps == null)
                    {
                        continue;
                    }

                    BundleCapability cap = candCaps.iterator().next();
                    reqs.add(req);
                    caps.add(cap);
                }
            }
        }

        // First, add all exported packages to the target revision's package space.
        calculateExportedPackages(revision, allCandidates, revisionPkgMap);
        Packages revisionPkgs = revisionPkgMap.get(revision);

        // Second, add all imported packages to the target revision's package space.
        for (int i = 0; i < reqs.size(); i++)
        {
            BundleRequirement req = reqs.get(i);
            BundleCapability cap = caps.get(i);
            calculateExportedPackages(cap.getRevision(), allCandidates, revisionPkgMap);
            mergeCandidatePackages(
                revision, req, cap, revisionPkgMap, allCandidates,
                new HashMap<BundleRevision, List<BundleCapability>>());
        }

        // Third, have all candidates to calculate their package spaces.
        for (int i = 0; i < caps.size(); i++)
        {
            calculatePackageSpaces(
                caps.get(i).getRevision(), allCandidates, revisionPkgMap,
                usesCycleMap, cycle);
        }

        // Fourth, if the target revision is unresolved or is dynamically importing,
        // then add all the uses constraints implied by its imported and required
        // packages to its package space.
        // NOTE: We do not need to do this for resolved revisions because their
        // package space is consistent by definition and these uses constraints
        // are only needed to verify the consistency of a resolving revision. The
        // only exception is if a resolved revision is dynamically importing, then
        // we need to calculate its uses constraints again to make sure the new
        // import is consistent with the existing package space.
        if ((revision.getWiring() == null) || isDynamicImporting)
        {
            // Merge uses constraints from required capabilities.
            for (int i = 0; i < reqs.size(); i++)
            {
                BundleRequirement req = reqs.get(i);
                BundleCapability cap = caps.get(i);
                // Ignore bundle/package requirements, since they are
                // considered below.
                if (!req.getNamespace().equals(BundleRevision.BUNDLE_NAMESPACE)
                    && !req.getNamespace().equals(BundleRevision.PACKAGE_NAMESPACE))
                {
View Full Code Here


            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);
                        }
View Full Code Here

        wireMap.put(revision, (List<ResolverWire>) Collections.EMPTY_LIST);

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

        BundleRequirement dynReq = null;
        BundleCapability dynCand = null;
        for (BundleRequirement req
            : Util.getDynamicRequirements(revision.getWiring().getRequirements(null)))
        {
            // Get the candidates for the current dynamic requirement.
            SortedSet<BundleCapability> candCaps =
                allCandidates.getCandidates((BundleRequirementImpl) req);
            // Optional requirements may not have any candidates.
            if ((candCaps == null) || candCaps.isEmpty())
            {
                continue;
            }

            // Record the dynamic requirement.
            dynReq = req;
            dynCand = candCaps.first();

            // Can only dynamically import one at a time, so break
            // out of the loop after the first.
            break;
        }

        if (dynReq != null)
        {
            if (dynCand.getRevision().getWiring() == null)
            {
                populateWireMap(dynCand.getRevision(), revisionPkgMap, wireMap,
                    allCandidates);
            }

            Map<String, Object> attrs = new HashMap(1);
            attrs.put(BundleRevision.PACKAGE_NAMESPACE, pkgName);
            packageWires.add(
                new ResolverWireImpl(
                    revision,
                    dynReq,
                    getActualBundleRevision(dynCand.getRevision()),
                    getActualCapability(dynCand)));
        }

        wireMap.put(revision, packageWires);
View Full Code Here

                {
                    sb.append("\n    provide: ");
                }
                if ((i + 1) < blame.m_reqs.size())
                {
                    BundleCapability cap = Util.getSatisfyingCapability(
                        blame.m_reqs.get(i + 1).getRevision(),
                        (BundleRequirementImpl) blame.m_reqs.get(i));
                    if (cap.getNamespace().equals(BundleRevision.PACKAGE_NAMESPACE))
                    {
                        sb.append(BundleRevision.PACKAGE_NAMESPACE);
                        sb.append("=");
                        sb.append(cap.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE).toString());
                        BundleCapability usedCap;
                        if ((i + 2) < blame.m_reqs.size())
                        {
                            usedCap = Util.getSatisfyingCapability(
                                blame.m_reqs.get(i + 2).getRevision(),
                                (BundleRequirementImpl) blame.m_reqs.get(i + 1));
                        }
                        else
                        {
                            usedCap = Util.getSatisfyingCapability(
                                blame.m_cap.getRevision(),
                                (BundleRequirementImpl) blame.m_reqs.get(i + 1));
                        }
                        sb.append("; uses:=");
                        sb.append(usedCap.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE));
                    }
                    else
                    {
                        sb.append(cap);
                    }
                    sb.append("\n");
                }
                else
                {
                    BundleCapability export = Util.getSatisfyingCapability(
                        blame.m_cap.getRevision(),
                        (BundleRequirementImpl) blame.m_reqs.get(i));
                    sb.append(export.getNamespace());
                    sb.append("=");
                    sb.append(export.getAttributes().get(export.getNamespace()).toString());
                    if (export.getNamespace().equals(BundleRevision.PACKAGE_NAMESPACE)
                        && !export.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE)
                            .equals(blame.m_cap.getAttributes().get(
                                BundleRevision.PACKAGE_NAMESPACE)))
                    {
                        sb.append("; uses:=");
                        sb.append(blame.m_cap.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE));
View Full Code Here

                state.getCandidates((BundleRequirementImpl) req, true);
            Set<BundleCapability> fragmentCands = null;
            for (Iterator<BundleCapability> itCandCap = candidates.iterator();
                itCandCap.hasNext(); )
            {
                BundleCapability candCap = itCandCap.next();

                boolean isFragment = Util.isFragment(candCap.getRevision());

                // If the capability is from a fragment, then record it
                // because we have to insert associated host capabilities
                // if the fragment is already attached to any hosts.
                if (isFragment)
                {
                    if (fragmentCands == null)
                    {
                        fragmentCands = new HashSet<BundleCapability>();
                    }
                    fragmentCands.add(candCap);
                }

                // If the candidate revision is a fragment, then always attempt
                // to populate candidates for its dependency, since it must be
                // attached to a host to be used. Otherwise, if the candidate
                // revision is not already resolved and is not the current version
                // we are trying to populate, then populate the candidates for
                // its dependencies as well.
                // NOTE: Technically, we don't have to check to see if the
                // candidate revision is equal to the current revision, but this
                // saves us from recursing and also simplifies exceptions messages
                // since we effectively chain exception messages for each level
                // of recursion; thus, any avoided recursion results in fewer
                // exceptions to chain when an error does occur.
                if (isFragment
                    || ((candCap.getRevision().getWiring() == null)
                        && !candCap.getRevision().equals(revision)))
                {
                    try
                    {
                        populateRevision(state, candCap.getRevision());
                    }
                    catch (ResolveException ex)
                    {
                        if (rethrow == null)
                        {
View Full Code Here

        // Get candidates hosts and keep any that have been populated.
        SortedSet<BundleCapability> hosts =
            state.getCandidates((BundleRequirementImpl) hostReq, false);
        for (Iterator<BundleCapability> it = hosts.iterator(); it.hasNext(); )
        {
            BundleCapability host = it.next();
            if (!isPopulated(host.getRevision()))
            {
                it.remove();
            }
        }
        // If there aren't any populated hosts, then we can just
View Full Code Here

        // Populate the candidates for the dynamic import.
        ResolveException rethrow = null;
        for (Iterator<BundleCapability> itCandCap = candidates.iterator();
            itCandCap.hasNext(); )
        {
            BundleCapability candCap = itCandCap.next();
            if (candCap.getRevision().getWiring() == null)
            {
                try
                {
                    populateRevision(state, candCap.getRevision());
                }
                catch (ResolveException ex)
                {
                    if (rethrow == null)
                    {
View Full Code Here

        List<BundleRevision> unselectedFragments = new ArrayList<BundleRevision>();
        for (Entry<BundleCapability, Map<String, Map<Version, List<BundleRequirement>>>>
            hostEntry : m_hostFragments.entrySet())
        {
            // Step 1
            BundleCapability hostCap = hostEntry.getKey();
            Map<String, Map<Version, List<BundleRequirement>>> fragments
                = hostEntry.getValue();
            List<BundleRevision> selectedFragments = new ArrayList<BundleRevision>();
            for (Entry<String, Map<Version, List<BundleRequirement>>> fragEntry
                : fragments.entrySet())
            {
                boolean isFirst = true;
                for (Entry<Version, List<BundleRequirement>> versionEntry
                    : fragEntry.getValue().entrySet())
                {
                    for (BundleRequirement hostReq : versionEntry.getValue())
                    {
                        // Select the highest version of the fragment that
                        // is not removal pending.
                        if (isFirst
                            ) // TODO: karl - is this correct? && !((BundleRevisionImpl) hostReq.getRevision()).isRemovalPending())
                        {
                            selectedFragments.add(hostReq.getRevision());
                            isFirst = false;
                        }
                        // For any fragment that wasn't selected, remove the
                        // current host as a potential host for it and remove it
                        // as a dependent on the host. If there are no more
                        // potential hosts for the fragment, then mark it as
                        // unselected for later removal.
                        else
                        {
                            m_dependentMap.get(hostCap).remove(hostReq);
                            SortedSet<BundleCapability> hosts = m_candidateMap.get(hostReq);
                            hosts.remove(hostCap);
                            if (hosts.isEmpty())
                            {
                                unselectedFragments.add(hostReq.getRevision());
                            }
                        }
                    }
                }
            }

            // Step 2
            HostBundleRevision wrappedHost =
                new HostBundleRevision(hostCap.getRevision(), selectedFragments);
            hostRevisions.add(wrappedHost);
            m_allWrappedHosts.put(hostCap.getRevision(), wrappedHost);
        }

        // Step 3
        for (BundleRevision br : unselectedFragments)
        {
            removeRevision(br,
                new ResolveException(
                    "Fragment was not selected for attachment.", br, null));
        }

        // Step 4
        for (HostBundleRevision hostRevision : hostRevisions)
        {
            // Replaces capabilities from fragments with the capabilities
            // from the merged host.
            for (BundleCapability c : hostRevision.getDeclaredCapabilities(null))
            {
                // Don't replace the host capability, since the fragment will
                // really be attached to the original host, not the wrapper.
                if (!c.getNamespace().equals(BundleRevision.HOST_NAMESPACE))
                {
                    BundleCapability origCap =
                        ((HostedCapability) c).getOriginalCapability();
                    // Note that you might think we could remove the original cap
                    // from the dependent map, but you can't since it may come from
                    // a fragment that is attached to multiple hosts, so each host
                    // will need to make their own copy.
View Full Code Here

        List<BundleCapability> aliasCaps = new ArrayList<BundleCapability>(capabilities);

        for (int capIdx = 0; capIdx < aliasCaps.size(); capIdx++)
        {
            BundleCapability capability = aliasCaps.get(capIdx);
           
            // Get the attributes and search for bundle symbolic name.
            Map<String, Object> attributes = capability.getAttributes();
           
            for (Entry<String, Object> entry : attributes.entrySet())
            {
                // If there is a bundle symbolic name attribute, add the
                // standard alias as a value.
                if (Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE.equalsIgnoreCase(entry.getKey()))
                {
                    // Make a copy of the attribute array.
                    Map<String, Object> aliasAttrs = new HashMap<String, Object>(attributes);
                    // Add the aliased value.
                    aliasAttrs.put(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE, new String[] { (String) entry.getValue(), Constants.SYSTEM_BUNDLE_SYMBOLICNAME });
                    // Create the aliased capability to replace the old capability.
                    aliasCaps.set(capIdx, new BundleCapabilityImpl(capability.getRevision(), capability.getNamespace(), capability.getDirectives(), aliasAttrs));
                    // Continue with the next capability.
                    break;
                }
            }
        }
View Full Code Here

            }
            else
            {
                for (Iterator<BundleCapability> it = caps.iterator(); it.hasNext(); )
                {
                    BundleCapability cap = it.next();
                    Object lhs = cap.getAttributes().get(sf.getName());
                    if (lhs != null)
                    {
                        if (compare(lhs, sf.getValue(), sf.getOperation()))
                        {
                            matches.add(cap);
View Full Code Here

TOP

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

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.