org.apache.felix.ipojo

## Interface ServiceContext

All Superinterfaces:
  org.osgi.framework.BundleContext, org.osgi.framework.BundleReference

All Known Implementing Classes:
  IPojoContext, PolicyServiceContext

    public interface ServiceContext
    extends org.osgi.framework.BundleContext

A service context is the facade of a service registry. It gives the access to a service broker. All service interactions should use a service context to garanty the service isolation. This class is a subset of `BundleContext` methods. (methods implying interactions with the service registry). So, refer to this class for further information.

Author:
  Felix Project Team
See Also:
  `BundleContext`

### Method Summary

All Methods Instance Methods Abstract Methods
`void` `addServiceListener(org.osgi.framework.ServiceListener listener)` Adds a service listener.
`void` `addServiceListener(org.osgi.framework.ServiceListener listener, java.lang.String filter)` Adds a service listener.
`org.osgi.framework.ServiceReference[]` `getAllServiceReferences(java.lang.String clazz, java.lang.String filter)` Gets the service references matching with the given query.
`<S> S` `getService(org.osgi.framework.ServiceReference<S> reference)` Gets a service object.
`org.osgi.framework.ServiceReference` `getServiceReference(java.lang.String clazz)` Gets a service reference for the given interface.
`org.osgi.framework.ServiceReference[]` `getServiceReferences(java.lang.String clazz, java.lang.String filter)` Gets service reference list for the given query.
`org.osgi.framework.ServiceRegistration` `registerService(java.lang.String[] clazzes, java.lang.Object service, java.util.Dictionary<java.lang.String,?> properties)` Registers a service inside this service context.
`org.osgi.framework.ServiceRegistration` `registerService(java.lang.String clazz, java.lang.Object service, java.util.Dictionary<java.lang.String,?> properties)` Registers a service inside this service context.
`void` `removeServiceListener(org.osgi.framework.ServiceListener listener)` Removes a service listener.
`boolean` `ungetService(org.osgi.framework.ServiceReference<?> reference)` Ungets the service reference.

### Methods inherited from interface org.osgi.framework.BundleContext

`addBundleListener, addFrameworkListener, createFilter, getBundle, getBundle, getBundle, getBundles, getDataFile, getProperty, getServiceReference, getServiceReferences, installBundle, installBundle, registerService, removeBundleListener, removeFrameworkListener`

### Method Detail

#### addServiceListener

    void addServiceListener(org.osgi.framework.ServiceListener listener,
                            java.lang.String filter)
                     throws org.osgi.framework.InvalidSyntaxException

Adds a service listener. The listener is added to this service context. So only services from this context will be tracked.

Specified by:
  `addServiceListener` in interface `org.osgi.framework.BundleContext`
Parameters:
  `listener` - the service listener to add.
  `filter` - the LDAP filter
Throws:
  `org.osgi.framework.InvalidSyntaxException` - if the LDAP filter is malformed
See Also:
  `BundleContext.addServiceListener(org.osgi.framework.ServiceListener, java.lang.String)`

#### addServiceListener

    void addServiceListener(org.osgi.framework.ServiceListener listener)

Adds a service listener. The listener is added to this service context. So only services from this context will be tracked.

Specified by:
  `addServiceListener` in interface `org.osgi.framework.BundleContext`
Parameters:
  `listener` - the service listener to add.
See Also:
  `BundleContext.addServiceListener(org.osgi.framework.ServiceListener)`

#### getAllServiceReferences

    org.osgi.framework.ServiceReference[] getAllServiceReferences(java.lang.String clazz,
                                                                  java.lang.String filter)
                                                           throws org.osgi.framework.InvalidSyntaxException

Gets the service references matching with the given query. The query is executed inside this service context.

Specified by:
  `getAllServiceReferences` in interface `org.osgi.framework.BundleContext`
Parameters:
  `clazz` - the required interface
  `filter` - a LDAP filter
Returns:
  the array of available service references or `null` if no providers are available.
Throws:
  `org.osgi.framework.InvalidSyntaxException` - if the LDAP filter is malformed
See Also:
  `BundleContext.getAllServiceReferences(java.lang.String, java.lang.String)`

#### getService

    <S> S getService(org.osgi.framework.ServiceReference<S> reference)

Gets a service object. The given service reference must comes from this service context.

Specified by:
  `getService` in interface `org.osgi.framework.BundleContext`
Parameters:
  `reference` - the required service reference
Returns:
  the service object or null if the service reference is no more valid or if the service object is not accessible
See Also:
  `BundleContext.getService(org.osgi.framework.ServiceReference)`

#### getServiceReference

    org.osgi.framework.ServiceReference getServiceReference(java.lang.String clazz)

Gets a service reference for the given interface. The query is executed inside this service context.

Specified by:
  `getServiceReference` in interface `org.osgi.framework.BundleContext`
Parameters:
  `clazz` - the required interface name
Returns:
  a service reference on a available provider or `null` if no providers are available
See Also:
  `BundleContext.getServiceReference(java.lang.String)`

#### getServiceReferences

    org.osgi.framework.ServiceReference[] getServiceReferences(java.lang.String clazz,
                                                               java.lang.String filter)
                                                        throws org.osgi.framework.InvalidSyntaxException

Gets service reference list for the given query. The query is executed inside this service context.

Specified by:
  `getServiceReferences` in interface `org.osgi.framework.BundleContext`
Parameters:
  `clazz` - : the name of the required service interface
  `filter` - : LDAP filter to apply on service provider
Returns:
  : the array of consistent service reference or `null` if no available providers
Throws:
  `org.osgi.framework.InvalidSyntaxException` - if the LDAP filter is malformed
See Also:
  `BundleContext.getServiceReferences(java.lang.String, java.lang.String)`

#### registerService

    org.osgi.framework.ServiceRegistration registerService(java.lang.String[] clazzes,
                                                           java.lang.Object service,
                                                           java.util.Dictionary<java.lang.String,?> properties)

Registers a service inside this service context. This service is then isolated inside this context.

Specified by:
  `registerService` in interface `org.osgi.framework.BundleContext`
Parameters:
  `clazzes` - the interfaces provided by the service.
  `service` - the service object.
  `properties` - service properties to publish
Returns:
  the service registration for this service publication. This service registration is attached to the current service context, and does not have any meaning in other contexts.
See Also:
  `registerService(java.lang.String[], java.lang.Object, java.util.Dictionary)`

#### registerService

    org.osgi.framework.ServiceRegistration registerService(java.lang.String clazz,
                                                           java.lang.Object service,
                                                           java.util.Dictionary<java.lang.String,?> properties)

Registers a service inside this service context. This service is then isolated inside this context.

Specified by:
  `registerService` in interface `org.osgi.framework.BundleContext`
Parameters:
  `clazz` - the interface provided by the service.
  `service` - the service object.
  `properties` - service properties to publish.
Returns:
  the service registration for this service publication. This service registration is attached to the current service context, and does not have any meaning in other contexts.
See Also:
  `BundleContext.registerService(java.lang.String, java.lang.Object, java.util.Dictionary)`

#### removeServiceListener

    void removeServiceListener(org.osgi.framework.ServiceListener listener)

Removes a service listener. The listener must be registered inside this service context.

Specified by:
  `removeServiceListener` in interface `org.osgi.framework.BundleContext`
Parameters:
  `listener` - the listener to remove
See Also:
  `BundleContext.removeServiceListener(org.osgi.framework.ServiceListener)`

#### ungetService

    boolean ungetService(org.osgi.framework.ServiceReference<?> reference)

Ungets the service reference. The service reference must comes from this service context.

Specified by:
  `ungetService` in interface `org.osgi.framework.BundleContext`
Parameters:
  `reference` - the reference to unget
Returns:
  `true` if you are the last user of the reference.
See Also:
  `BundleContext.ungetService(org.osgi.framework.ServiceReference)`