Package org.osgi.framework.wiring

Examples of org.osgi.framework.wiring.BundleCapability


            }
            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


    private static Set<BundleCapability> matchMandatory(
        Set<BundleCapability> caps, SimpleFilter sf)
    {
        for (Iterator<BundleCapability> it = caps.iterator(); it.hasNext(); )
        {
            BundleCapability cap = it.next();
            if (!matchMandatory(cap, sf))
            {
                it.remove();
            }
        }
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

            FelixConstants.SYSTEM_BUNDLE_SYMBOLICNAME,
            Constants.SYSTEM_BUNDLE_SYMBOLICNAME };

        for (int capIdx = 0; capIdx < aliasCaps.size(); capIdx++)
        {
            BundleCapability cap = aliasCaps.get(capIdx);

            // Need to alias bundle and host capabilities.
            if (cap.getNamespace().equals(BundleRevision.BUNDLE_NAMESPACE)
                || cap.getNamespace().equals(BundleRevision.HOST_NAMESPACE))
            {
                // Make a copy of the attribute array.
                Map<String, Object> aliasAttrs =
                    new HashMap<String, Object>(cap.getAttributes());
                // Add the aliased value.
                aliasAttrs.put(cap.getNamespace(), aliases);
                // Create the aliased capability to replace the old capability.
                cap = new BundleCapabilityImpl(
                    cap.getRevision(),
                    cap.getNamespace(),
                    cap.getDirectives(),
                    aliasAttrs);
                aliasCaps.set(capIdx, cap);
            }

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

            dynIdx++)
        {
            for (Iterator<BundleCapability> itCand = candidates.iterator();
                (dynReq == null) && itCand.hasNext(); )
            {
                BundleCapability cap = itCand.next();
                if (CapabilitySet.matches(
                    (BundleCapabilityImpl) cap,
                    ((BundleRequirementImpl) dynamics.get(dynIdx)).getFilter()))
                {
                    dynReq = (BundleRequirementImpl) dynamics.get(dynIdx);
                }
            }
        }

        // If we found a matching dynamic requirement, then filter out
        // any candidates that do not match it.
        if (dynReq != null)
        {
            for (Iterator<BundleCapability> itCand = candidates.iterator();
                itCand.hasNext(); )
            {
                BundleCapability cap = itCand.next();
                if (!CapabilitySet.matches(
                    (BundleCapabilityImpl) cap, dynReq.getFilter()))
                {
                    itCand.remove();
                }
View Full Code Here

        // Create groups according to how the resolver hooks filtered the
        // collisions.
        List<List<BundleRevision>> groups = new ArrayList<List<BundleRevision>>();
        while (!allCollisions.isEmpty())
        {
            BundleCapability target = allCollisions.entrySet().iterator().next().getKey();
            groups.add(groupSingletons(allCollisions, target, new ArrayList<BundleRevision>()));
        }

        // Now select the singletons available for this resolve operation.
        for (List<BundleRevision> group : groups)
View Full Code Here

        }
        // Get candidates hosts and keep any that have been populated.
        List<BundleCapability> hosts = rc.findProviders(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

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.