Interface ComponentContext<ExpectedServiceType>

Context of a ComponentInstance.

interface ComponentContext<
    ExpectedServiceType extends ServiceInstance = ServiceInstance,
> {
    disableComponent(name: string): void;
    enableComponent(name: string): void;
    getBundleContext(): BundleContext;
    getComponentInstance<ServiceType extends ServiceInstance>(): ComponentInstance<
        ServiceType,
    >;
    getProperties(): ComponentProperties;
    getResourceURL(path: string, otherBundleName?: string): string;
    getServiceReference(): undefined | ServiceReference;
    getUsingBundle(): undefined | Bundle;
    locateService<ServiceType extends ServiceInstance>(
        name: string,
        reference: ServiceReference,
    ): undefined | ServiceType;
    locateServiceReferences(name: string): readonly ServiceReference[];
    locateServices<ServiceType extends ServiceInstance>(
        name: string,
    ): readonly ServiceType[];
}

Type Parameters

Methods

  • Disables the component specified by name. The component name must be in the same bundle as this component.

    Parameters

    • name: string

      The name of a component.

    Returns void

  • Enables the component specified by name. The component name must be in the same bundle as this component.

    Parameters

    • name: string

      The name of a component or null to indicate all components in the bundle.

    Returns void

  • Returns the BundleContext of the bundle which contains this component.

    Returns BundleContext

  • Returns the component properties for this context.

    Returns ComponentProperties

    The properties for this context. The Dictionary is readonly and cannot be modified.

  • Creates a URL to a given path, located in this or another bundle.

    Parameters

    • path: string

      resource path

    • OptionalotherBundleName: string

      name of other bundle (optional).

    Returns string

    resolved URL to given path.

    use BundleContext.getResourceURL

  • If the component instance is registered as a service using the service element, this method returns the service reference of the service provided by this component instance.

    This method will return undefined if the component instance is not registered as a service.

    Returns undefined | ServiceReference

    The ServiceReference object for the component instance or undefined if the component instance is not registered as a service.

  • If the component instance is registered as a service using the serviceFactory="true" attribute, then this method returns the bundle using the service provided by the component instance.

    This method will return undefined if:

    • The component instance is not a service, so no bundle can be use it as a service.
    • The component instance is a service but did not specify the serviceFactory="true" attribute, so all bundles using the service provided by the component instance will share the same component instance.
    • The service provided by the component instance is not currently used by any bundle.

    Returns undefined | Bundle

    The bundle using the component instance as a service or undefined.

  • Returns the service object for the specified reference name and ServiceReference.

    Type Parameters

    Parameters

    • name: string

      The name of a reference as specified in a reference element in this component's description.

    • reference: ServiceReference

      The ServiceReference to a service. This must be a reference provided by locateService(s) matching the reference name.

    Returns undefined | ServiceType

    A service object for the referenced service or undefined

  • Returns the service reference objects for the specified reference name.

    Parameters

    • name: string

      The name of a reference as specified in a reference element in this component's description.

    Returns readonly ServiceReference[]

    An array of service reference objects for the referenced service.

  • Returns the service objects for the specified reference name.

    Type Parameters

    Parameters

    • name: string

      The name of a reference as specified in a reference element in this component's description.

    Returns readonly ServiceType[]

    An array of service objects for the referenced service.