Package org.osgi.framework.resource

Examples of org.osgi.framework.resource.Resource


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


                // Populate mandatory revisions; since these are mandatory
                // revisions, failure throws a resolve exception.
                for (Iterator<? extends Resource> it = mandatoryRevisions.iterator();
                    it.hasNext(); )
                {
                    Resource br = it.next();
                    if (Util.isFragment(br) || !env.getWirings().containsKey(br))
                    {
                        allCandidates.populate(env, br, Candidates.MANDATORY);
                    }
                    else
                    {
                        it.remove();
                    }
                }

                // Populate optional revisions; since these are optional
                // revisions, failure does not throw a resolve exception.
                if (optionalRevisions != null) {
                    for (Resource br : optionalRevisions)
                    {
                        boolean isFragment = Util.isFragment(br);
                        if (isFragment || !env.getWirings().containsKey(br))
                        {
                            allCandidates.populate(env, br, Candidates.OPTIONAL);
                        }
                    }
                }

                // Populate ondemand fragments; since these are optional
                // revisions, failure does not throw a resolve exception.
                for (Resource br : ondemandFragments)
                {
                    boolean isFragment = Util.isFragment(br);
                    if (isFragment)
                    {
                        allCandidates.populate(env, br, Candidates.ON_DEMAND);
                    }
                }

                // Merge any fragments into hosts.
                allCandidates.prepare();

                // Create a combined list of populated revisions; for
                // optional revisions. We do not need to consider ondemand
                // fragments, since they will only be pulled in if their
                // host is already present.
                Set<Resource> allRevisions =
                    new HashSet<Resource>(mandatoryRevisions);
                for (Resource br : optionalRevisions)
                {
                    if (allCandidates.isPopulated(br))
                    {
                        allRevisions.add(br);
                    }
                }

                // Record the initial candidate permutation.
                m_usesPermutations.add(allCandidates);

                ResolutionException rethrow = null;

                // If a populated revision is a fragment, then its host
                // must ultimately be verified, so store its host requirement
                // to use for package space calculation.
                Map<Resource, List<Requirement>> hostReqs =
                    new HashMap<Resource, List<Requirement>>();
                for (Resource br : allRevisions)
                {
                    if (Util.isFragment(br))
                    {
                        hostReqs.put(
                            br,
                            br.getRequirements(ResourceConstants.WIRING_HOST_NAMESPACE));
                    }
                }

                do
                {
                    rethrow = null;

                    revisionPkgMap.clear();
                    m_packageSourcesCache.clear();

                    allCandidates = (m_usesPermutations.size() > 0)
                        ? m_usesPermutations.remove(0)
                        : m_importPermutations.remove(0);
//allCandidates.dump();

                    for (Resource br : allRevisions)
                    {
                        Resource target = br;

                        // If we are resolving a fragment, then get its
                        // host candidate and verify it instead.
                        List<Requirement> hostReq = hostReqs.get(br);
                        if (hostReq != null)
                        {
                            target = allCandidates.getCandidates(hostReq.get(0))
                                .iterator().next().getResource();
                        }

                        calculatePackageSpaces(
                            env, allCandidates.getWrappedHost(target), allCandidates,
                            revisionPkgMap, new HashMap(), new HashSet());
                       
                        if (m_logger.isEnabled(Logger.LOG_TRACE))
                          dumpRevisionPkgMap(env, revisionPkgMap);

                        try
                        {
                            checkPackageSpaceConsistency(
                                env, false, allCandidates.getWrappedHost(target),
                                allCandidates, revisionPkgMap, new HashMap());
                        }
                        catch (ResolutionException ex)
                        {
                            rethrow = ex;
                        }
                    }
                }
                while ((rethrow != null)
                    && ((m_usesPermutations.size() > 0) || (m_importPermutations.size() > 0)));

                // If there is a resolve exception, then determine if an
                // optionally resolved revision is to blame (typically a fragment).
                // If so, then remove the optionally resolved resolved and try
                // again; otherwise, rethrow the resolve exception.
                if (rethrow != null)
                {
                    Collection<Requirement> exReqs = rethrow.getUnresolvedRequirements();
                    Requirement faultyReq = ((exReqs == null) || exReqs.isEmpty())
                        ? null : exReqs.iterator().next();
                    Resource faultyRevision = (faultyReq == null)
                        ? null : getActualResource(faultyReq.getResource());
                    if (faultyReq instanceof HostedRequirement)
                    {
                        faultyRevision =
                            ((HostedRequirement) faultyReq)
                                .getOriginalRequirement().getResource();
                    }
                    if (optionalRevisions.remove(faultyRevision))
                    {
                        retry = true;
                    }
                    else if (ondemandFragments.remove(faultyRevision))
                    {
                        retry = true;
                    }
                    else
                    {
                        throw rethrow;
                    }
                }
                // If there is no exception to rethrow, then this was a clean
                // resolve, so populate the wire map.
                else
                {
                    for (Resource br : allRevisions)
                    {
                        Resource target = br;

                        // If we are resolving a fragment, then we
                        // actually want to populate its host's wires.
                        List<Requirement> hostReq = hostReqs.get(br);
                        if (hostReq != null)
View Full Code Here

                    if (rethrow != null)
                    {
                        Collection<Requirement> exReqs = rethrow.getUnresolvedRequirements();
                        Requirement faultyReq = ((exReqs == null) || exReqs.isEmpty())
                            ? null : exReqs.iterator().next();
                        Resource faultyResource = null;
                        if (faultyReq instanceof HostedRequirement)
                        {
                            faultyResource =
                                ((HostedRequirement) faultyReq)
                                    .getOriginalRequirement().getResource();
View Full Code Here

        Environment env, Resource resource,
        Map<Resource, Packages> revisionPkgMap,
        Map<Resource, List<Wire>> wireMap,
        Candidates allCandidates)
    {
        Resource unwrappedResource = getActualResource(resource);
        if (!env.getWirings().containsKey(unwrappedResource)
            && !wireMap.containsKey(unwrappedResource))
        {
            wireMap.put(unwrappedResource, (List<Wire>) Collections.EMPTY_LIST);

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

            for (Requirement req : resource.getRequirements(null))
            {
                SortedSet<Capability> cands = allCandidates.getCandidates(req);
                if ((cands != null) && (cands.size() > 0))
                {
                    Capability cand = cands.iterator().next();
                    // Ignore revisions that import themselves.
                    if (!resource.equals(cand.getResource()))
                    {
                        if (!env.getWirings().containsKey(cand.getResource()))
                        {
                            populateWireMap(env, cand.getResource(),
                                revisionPkgMap, wireMap, allCandidates);
                        }
                        Packages candPkgs = revisionPkgMap.get(cand.getResource());
                        Wire wire = new WireImpl(
                            unwrappedResource,
                            getActualRequirement(req),
                            getActualResource(cand.getResource()),
                            getActualCapability(cand));
                        if (req.getNamespace().equals(ResourceConstants.WIRING_PACKAGE_NAMESPACE))
                        {
                            packageWires.add(wire);
                        }
                        else if (req.getNamespace().equals(ResourceConstants.WIRING_BUNDLE_NAMESPACE))
                        {
                            bundleWires.add(wire);
                        }
                        else
                        {
                            capabilityWires.add(wire);
                        }
                    }
                }
            }

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

            // Add host wire for any fragments.
            if (resource instanceof HostResource)
            {
                List<Resource> fragments = ((HostResource) resource).getFragments();
                for (Resource fragment : fragments)
                {
                    List<Wire> hostWires = wireMap.get(fragment);
                    if (hostWires == null)
                    {
                        hostWires = new ArrayList<Wire>();
                        wireMap.put(fragment, hostWires);
                    }
                    hostWires.add(
                        new WireImpl(
                            getActualResource(fragment),
                            fragment.getRequirements(
                                ResourceConstants.WIRING_HOST_NAMESPACE).get(0),
                            unwrappedResource,
                            unwrappedResource.getCapabilities(
                                ResourceConstants.WIRING_HOST_NAMESPACE).get(0)));
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.osgi.framework.resource.Resource

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.