ResolveContext
Date: 2016-06-25

org.osgi.service.resolver

## Class ResolveContext

- java.lang.Object
- - org.osgi.service.resolver.ResolveContext

-     @ConsumerType
      public abstract class ResolveContext
      extends java.lang.Object

  A resolve context provides resources, options and constraints to the potential solution of a `resolve` operation.

  Resolve Contexts:

  - Specify the mandatory and optional resources to resolve. The mandatory and optional resources must be consistent and correct. For example, they must not violate the singleton policy of the implementer.
  - Provide `capabilities` that the Resolver can use to satisfy `requirements` via the `findProviders(Requirement)` method
  - Constrain solutions via the `getWirings()` method. A wiring consists of a map of existing `resources` to `wiring`.
  - Filter requirements that are part of a resolve operation via the `isEffective(Requirement)`.

  A resolver may call the methods on the resolve context any number of times during a resolve operation using any thread. Implementors should ensure that this class is properly thread safe.

  Except for `insertHostedCapability(List, HostedCapability)`, the resolve context methods must be idempotent. This means that resources must have constant capabilities and requirements and the resolve context must return a consistent set of capabilities, wires and effective requirements.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ResolveContext()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract java.util.List<org.osgi.resource.Capability>` | `findProviders(org.osgi.resource.Requirement requirement)` Find Capabilities that match the given Requirement.
    `java.util.Collection<org.osgi.resource.Resource>` | `getMandatoryResources()` Return the resources that must be resolved for this resolve context.
    `java.util.Collection<org.osgi.resource.Resource>` | `getOptionalResources()` Return the resources that the resolver should attempt to resolve for this resolve context.
    `abstract java.util.Map<org.osgi.resource.Resource,org.osgi.resource.Wiring>` | `getWirings()` Returns the wirings for existing resolved resources.
    `abstract int` | `insertHostedCapability(java.util.List<org.osgi.resource.Capability> capabilities, HostedCapability hostedCapability)` Add a `HostedCapability` to the list of capabilities returned from `findProviders(Requirement)`.
    `abstract boolean` | `isEffective(org.osgi.resource.Requirement requirement)` Test if a given requirement should be wired in the resolve operation.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ResolveContext

          public ResolveContext()

  - ### Method Detail

    - #### getMandatoryResources

          public java.util.Collection<org.osgi.resource.Resource> getMandatoryResources()

      Return the resources that must be resolved for this resolve context.

      The default implementation returns an empty collection.

      Returns:
        A collection of the resources that must be resolved for this resolve context. May be empty if there are no mandatory resources. The returned collection may be unmodifiable.

    - #### getOptionalResources

          public java.util.Collection<org.osgi.resource.Resource> getOptionalResources()

      Return the resources that the resolver should attempt to resolve for this resolve context. Inability to resolve one of the specified resources will not result in a resolution exception.

      The default implementation returns an empty collection.

      Returns:
        A collection of the resources that the resolver should attempt to resolve for this resolve context. May be empty if there are no optional resources. The returned collection may be unmodifiable.

    - #### findProviders

          public abstract java.util.List<org.osgi.resource.Capability> findProviders(org.osgi.resource.Requirement requirement)

      Find Capabilities that match the given Requirement.

      The returned list contains `Capability` objects where the Resource must be the declared Resource of the Capability. The Resolver can then add additional `HostedCapability` objects with the `insertHostedCapability(List, HostedCapability)` method when it, for example, attaches fragments. Those `HostedCapability` objects will then use the host's Resource which likely differs from the declared Resource of the corresponding Capability.

      The returned list is in priority order such that the Capabilities with a lower index have a preference over those with a higher index. The resolver must use the `insertHostedCapability(List, HostedCapability)` method to add additional Capabilities to maintain priority order. In general, this is necessary when the Resolver uses Capabilities declared in a Resource but that must originate from an attached host.

      Each returned Capability must match the given Requirement. This means that the filter in the Requirement must match as well as any namespace specific directives. For example, the mandatory attributes for the `osgi.wiring.package` namespace.

      Parameters:
        `requirement` - The requirement that a resolver is attempting to satisfy. Must not be `null`.
      Returns:
        A list of `Capability` objects that match the specified requirement.

    - #### insertHostedCapability

          public abstract int insertHostedCapability(java.util.List<org.osgi.resource.Capability> capabilities,
                                   HostedCapability hostedCapability)

      Add a `HostedCapability` to the list of capabilities returned from `findProviders(Requirement)`.

      This method is used by the `Resolver` to add Capabilities that are hosted by another Resource to the list of Capabilities returned from `findProviders(Requirement)`. This function is necessary to allow fragments to attach to hosts, thereby changing the origin of a Capability. This method must insert the specified HostedCapability in a place that makes the list maintain the preference order. It must return the index in the list of the inserted `HostedCapability`.

      Parameters:
        `capabilities` - The list returned from `findProviders(Requirement)`. Must not be `null`.
        `hostedCapability` - The HostedCapability to insert in the specified list. Must not be `null`.
      Returns:
        The index in the list of the inserted HostedCapability.

    - #### isEffective

          public abstract boolean isEffective(org.osgi.resource.Requirement requirement)

      Test if a given requirement should be wired in the resolve operation. If this method returns `false`, then the resolver should ignore this requirement during the resolve operation.

      The primary use case for this is to test the `effective` directive on the requirement, though implementations are free to use any effective test.

      Parameters:
        `requirement` - The Requirement to test. Must not be `null`.
      Returns:
        `true` if the requirement should be considered as part of the resolve operation.

    - #### getWirings

          public abstract java.util.Map<org.osgi.resource.Resource,org.osgi.resource.Wiring> getWirings()

      Returns the wirings for existing resolved resources.

      For example, if this resolve context is for an OSGi framework, then the result would contain all the currently resolved bundles with each bundle's current wiring.

      Multiple calls to this method for this resolve context must return the same result.

      Returns:
        The wirings for existing resolved resources. The returned map is unmodifiable.