Package org.osgi.resource

Examples of org.osgi.resource.Resource


        }

        assertEquals(Version.parseVersion("1.0.0.SNAPSHOT"), tf1Cap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE));
        assertEquals(IdentityNamespace.TYPE_BUNDLE, tf1Cap.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE));

        Resource res = tf1Cap.getResource();
        assertEquals(0, res.getRequirements(null).size());
        assertEquals(1, res.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).size());
        assertEquals(1, res.getCapabilities(ContentNamespace.CONTENT_NAMESPACE).size());
        assertEquals(1, res.getCapabilities(BundleNamespace.BUNDLE_NAMESPACE).size());
        assertEquals(8, res.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE).size());
        assertEquals(1, res.getCapabilities("foo").size());
        assertEquals(12, res.getCapabilities(null).size());

        Capability contentCap = res.getCapabilities(ContentNamespace.CONTENT_NAMESPACE).iterator().next();
        assertEquals("4b68ab3847feda7d6c62c1fbcbeebfa35eab7351ed5e78f4ddadea5df64b8015",
                contentCap.getAttributes().get(ContentNamespace.CONTENT_NAMESPACE));
        assertEquals(getClass().getResource("/repo_files/test_file_1.jar").toExternalForm(),
                contentCap.getAttributes().get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE));
        assertEquals(1L, contentCap.getAttributes().get(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE));
        assertEquals("application/vnd.osgi.bundle", contentCap.getAttributes().get(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE));

        Capability bundleCap = res.getCapabilities(BundleNamespace.BUNDLE_NAMESPACE).iterator().next();
        assertEquals("2", bundleCap.getAttributes().get("manifestversion"));
        assertEquals("dummy", bundleCap.getAttributes().get(BundleNamespace.BUNDLE_NAMESPACE));
        assertEquals(Version.parseVersion("1.0.0.SNAPSHOT"), bundleCap.getAttributes().get(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
        assertEquals("Unnamed - dummy", bundleCap.getAttributes().get("presentationname"));

        Capability packageCap = res.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE).get(7);
        assertEquals("org.apache.commons.logging", packageCap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
        assertEquals(Version.parseVersion("1.0.4"), packageCap.getAttributes().get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE));
        assertEquals("dummy", packageCap.getAttributes().get(PackageNamespace.CAPABILITY_BUNDLE_SYMBOLICNAME_ATTRIBUTE));
        assertEquals(Version.parseVersion("1.0.0.SNAPSHOT"), packageCap.getAttributes().get(PackageNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));

        Capability fooCap = res.getCapabilities("foo").iterator().next();
        assertEquals("someVal", fooCap.getAttributes().get("someKey"));
    }
View Full Code Here


                // Populate mandatory resources; since these are mandatory
                // resources, failure throws a resolve exception.
                for (Iterator<Resource> it = mandatoryResources.iterator();
                    it.hasNext();)
                {
                    Resource resource = it.next();
                    if (Util.isFragment(resource) || (rc.getWirings().get(resource) == null))
                    {
                        allCandidates.populate(rc, resource, Candidates.MANDATORY);
                    }
                    else
                    {
                        it.remove();
                    }
                }

                // Populate optional resources; since these are optional
                // resources, failure does not throw a resolve exception.
                for (Resource resource : optionalResources)
                {
                    boolean isFragment = Util.isFragment(resource);
                    if (isFragment || (rc.getWirings().get(resource) == null))
                    {
                        allCandidates.populate(rc, resource, Candidates.OPTIONAL);
                    }
                }

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

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

                List<Candidates> usesPermutations = session.getUsesPermutations();
                List<Candidates> importPermutations = session.getImportPermutations();

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

                ResolutionException rethrow = null;

                // If a populated resource 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 resource : allResources)
                {
                    if (Util.isFragment(resource))
                    {
                        hostReqs.put(
                            resource,
                            resource.getRequirements(HostNamespace.HOST_NAMESPACE));
                    }
                }

                Map<Resource, ResolutionException> faultyResources = null;
                do
                {
                    rethrow = null;

                    resourcePkgMap.clear();
                    session.getPackageSourcesCache().clear();
                    // Null out each time a new permutation is attempted.
                    // We only use this to store a valid permutation which is a
                    // delta of the current permutation.
                    session.setMultipleCardCandidates(null);

                    allCandidates = (usesPermutations.size() > 0)
                        ? usesPermutations.remove(0)
                        : importPermutations.remove(0);
//allCandidates.dump();

                    Map<Resource, ResolutionException> currentFaultyResources = null;
                    try
                    {
                        allCandidates.checkSubstitutes(importPermutations);
                    }
                    catch (ResolutionException e)
                    {
                        rethrow = e;
                        continue;
                    }

                    // Reuse a resultCache map for checking package consistency
                    // for all resources.
                    Map<Resource, Object> resultCache =
                        new HashMap<Resource, Object>(allResources.size());
                    // Check the package space consistency for all 'root' resources.
                    for (Resource resource : allResources)
                    {
                        Resource target = resource;

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

                        calculatePackageSpaces(
                            session, allCandidates.getWrappedHost(target), allCandidates,
                            resourcePkgMap, new HashMap(), new HashSet());
//System.out.println("+++ PACKAGE SPACES START +++");
//dumpResourcePkgMap(resourcePkgMap);
//System.out.println("+++ PACKAGE SPACES END +++");

                        try
                        {
                            checkPackageSpaceConsistency(
                                session, allCandidates.getWrappedHost(target),
                                allCandidates, resourcePkgMap, resultCache);
                        }
                        catch (ResolutionException ex)
                        {
                            rethrow = ex;
                            if (currentFaultyResources == null)
                            {
                                currentFaultyResources = new HashMap<Resource, ResolutionException>();
                            }
                            Resource faultyResource = resource;
                            // check that the faulty requirement is not from a fragment
                            for (Requirement faultyReq : ex.getUnresolvedRequirements())
                            {
                                if (faultyReq instanceof WrappedRequirement)
                                {
                                    faultyResource =
                                        ((WrappedRequirement) faultyReq)
                                        .getDeclaredRequirement().getResource();
                                    break;
                                }
                            }
                            currentFaultyResources.put(faultyResource, ex);
                        }
                    }
                    if (currentFaultyResources != null)
                    {
                        if (faultyResources == null)
                        {
                            faultyResources = currentFaultyResources;
                        }
                        else if (faultyResources.size() > currentFaultyResources.size())
                        {
                            // save the optimal faultyResources which has less
                            faultyResources = currentFaultyResources;
                        }
                    }
                }
                while ((rethrow != null)
                    && ((usesPermutations.size() > 0) || (importPermutations.size() > 0)));

                // If there is a resolve exception, then determine if an
                // optionally resolved resource 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)
                {
                    if (faultyResources != null)
                    {
                        Set<Resource> resourceKeys = faultyResources.keySet();
                        retry = (optionalResources.removeAll(resourceKeys));
                        for (Resource faultyResource : resourceKeys)
                        {
                            Boolean valid = validOnDemandResources.get(faultyResource);
                            if (valid != null && valid.booleanValue())
                            {
                                // This was an ondemand resource.
                                // Invalidate it and try again.
                                validOnDemandResources.put(faultyResource, Boolean.FALSE);
                                retry = true;
                            }
                        }
                        // log all the resolution exceptions for the uses constraint violations
                        for (Map.Entry<Resource, ResolutionException> usesError : faultyResources.entrySet())
                        {
                            m_logger.logUsesConstraintViolation(usesError.getKey(), usesError.getValue());
                        }
                    }
                    if (!retry)
                    {
                        throw rethrow;
                    }
                }
                // If there is no exception to rethrow, then this was a clean
                // resolve, so populate the wire map.
                else
                {
                    if (session.getMultipleCardCandidates() != null)
                    {
                        // Candidates for multiple cardinality requirements were
                        // removed in order to provide a consistent class space.
                        // Use the consistent permutation
                        allCandidates = session.getMultipleCardCandidates();
                    }
                    for (Resource resource : allResources)
                    {
                        Resource target = resource;

                        // If we are resolving a fragment, then we
                        // actually want to populate its host's wires.
                        List<Requirement> hostReq = hostReqs.get(resource);
                        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 = (faultyReq == null)
                            ? null : getDeclaredResource(faultyReq.getResource());
                        // If the faulty requirement is wrapped, then it may
                        // be from a fragment, so consider the fragment faulty
                        // instead of the host.
                        if (faultyReq instanceof WrappedRequirement)
View Full Code Here

    private static Map<Resource, List<Wire>> populateWireMap(
        ResolveContext rc, Resource resource, Map<Resource, Packages> resourcePkgMap,
        Map<Resource, List<Wire>> wireMap, Candidates allCandidates)
    {
        Resource unwrappedResource = getDeclaredResource(resource);
        if (!rc.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))
            {
                List<Capability> cands = allCandidates.getCandidates(req);
                if ((cands != null) && (cands.size() > 0))
                {
                    for (Capability cand : cands)
                    {
                        // Do not create wires for the osgi.wiring.* namespaces
                        // if the provider and requirer are the same resource;
                        // allow such wires for non-OSGi wiring namespaces.
                        if (!cand.getNamespace().startsWith("osgi.wiring.")
                            || !resource.equals(cand.getResource()))
                        {
                            // If we don't already have wires for the candidate,
                            // then recursively populate them.
                            if (!rc.getWirings().containsKey(cand.getResource()))
                            {
                                // Need to special case the candidate for identity
                                // capabilities since it may be from a fragment and
                                // we don't want to populate wires for the fragment,
                                // but rather the host to which it is attached.
                                Resource targetCand = cand.getResource();
                                if (IdentityNamespace.IDENTITY_NAMESPACE.equals(cand.getNamespace())
                                    && Util.isFragment(targetCand))
                                {
                                    targetCand = allCandidates.getCandidates(
                                        targetCand.getRequirements(HostNamespace.HOST_NAMESPACE).get(0))
                                        .iterator().next().getResource();
                                    targetCand = allCandidates.getWrappedHost(targetCand);
                                }

                                populateWireMap(rc, targetCand,
View Full Code Here

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

    if (importServiceHeader == null) {
      return null;
    }
    List<Capability> modifiableCaps = new ArrayList<Capability>();
    final List<Capability> fakeCapabilities = Collections.unmodifiableList(modifiableCaps);
    Resource fakeResource = new Resource() {

      @Override
      public List<Capability> getCapabilities(String namespace) {
        if (namespace == null) {
          return fakeCapabilities;
View Full Code Here

    else {
      DeployedContentHeader header = manifest.getDeployedContentHeader();
      if (header == null)
        return;
      for (DeployedContentHeader.Clause clause : header.getClauses()) {
        Resource resource = findContent(clause);
        if (resource == null)
          addMissingResource(clause);
        else
          addContentResource(resource);
      }
View Full Code Here

    SubsystemContentHeader contentHeader = manifest.getSubsystemContentHeader();
    if (contentHeader == null)
      return;
    for (SubsystemContentHeader.Clause clause : contentHeader.getClauses()) {
      Requirement requirement = clause.toRequirement(this);
      Resource resource = findContent(requirement);
      if (resource == null) {
        if (clause.isMandatory())
          throw new SubsystemException("Resource does not exist: "+ requirement);
        continue;
      }
View Full Code Here

    else {
      ProvisionResourceHeader header = manifest.getProvisionResourceHeader();
      if (header == null)
        return;
      for (ProvisionResourceHeader.Clause clause : header.getClauses()) {
        Resource resource = findDependency(clause);
        if (resource == null)
          throw new SubsystemException("Resource does not exist: " + clause);
        addDependency(resource);
      }
    } 
View Full Code Here

    if (isUnscoped()) {
      map = Activator.getInstance().getSystemRepository().findProviders(Collections.singleton(requirement));
      if (map.containsKey(requirement)) {
        Collection<Capability> capabilities = map.get(requirement);
        for (Capability capability : capabilities) {
          Resource provider = capability.getResource();
          if (provider instanceof BundleRevision) {
            if (getRegion().contains(((BundleRevision)provider).getBundle())) {
              return provider;
            }
          }
View Full Code Here

TOP

Related Classes of org.osgi.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.