org.apache.felix.ipojo
Interface ServiceContext

All Superinterfaces:
BundleContext
All Known Implementing Classes:
CompositeServiceContext, IPojoContext, PolicyServiceContext

public interface ServiceContext
extends 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
 void addServiceListener(ServiceListener listener)
          Adds a service listener.
 void addServiceListener(ServiceListener listener, String filter)
          Adds a service listener.
 ServiceReference[] getAllServiceReferences(String clazz, String filter)
          Gets the service references matching with the given query.
 Object getService(ServiceReference reference)
          Gets a service object.
 ServiceReference getServiceReference(String clazz)
          Gets a service reference for the given interface.
 ServiceReference[] getServiceReferences(String clazz, String filter)
          Gets service reference list for the given query.
 ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties)
          Registers a service inside this service context.
 ServiceRegistration registerService(String clazz, Object service, Dictionary properties)
          Registers a service inside this service context.
 void removeServiceListener(ServiceListener listener)
          Removes a service listener.
 boolean ungetService(ServiceReference reference)
          Ungets the service reference.
 
Methods inherited from interface org.osgi.framework.BundleContext
addBundleListener, addFrameworkListener, createFilter, getBundle, getBundle, getBundles, getDataFile, getProperty, installBundle, installBundle, removeBundleListener, removeFrameworkListener
 

Method Detail

addServiceListener

void addServiceListener(ServiceListener listener,
                        String filter)
                        throws 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 BundleContext
Parameters:
listener - the service listener to add.
filter - the LDAP filter
Throws:
InvalidSyntaxException - if the LDAP filter is malformed
See Also:
BundleContext.addServiceListener(org.osgi.framework.ServiceListener, java.lang.String)

addServiceListener

void addServiceListener(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 BundleContext
Parameters:
listener - the service listener to add.
See Also:
BundleContext.addServiceListener(org.osgi.framework.ServiceListener)

getAllServiceReferences

ServiceReference[] getAllServiceReferences(String clazz,
                                           String filter)
                                           throws InvalidSyntaxException
Gets the service references matching with the given query. The query is executed inside this service context.

Specified by:
getAllServiceReferences in interface 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:
InvalidSyntaxException - if the LDAP filter is malformed
See Also:
BundleContext.getAllServiceReferences(java.lang.String, java.lang.String)

getService

Object getService(ServiceReference reference)
Gets a service object. The given service reference must comes from this service context.

Specified by:
getService in interface 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

ServiceReference getServiceReference(String clazz)
Gets a service reference for the given interface. The query is executed inside this service context.

Specified by:
getServiceReference in interface 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

ServiceReference[] getServiceReferences(String clazz,
                                        String filter)
                                        throws InvalidSyntaxException
Gets service reference list for the given query. The query is executed inside this service context.

Specified by:
getServiceReferences in interface 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:
InvalidSyntaxException - if the LDAP filter is malformed
See Also:
BundleContext.getServiceReferences(java.lang.String, java.lang.String)

registerService

ServiceRegistration registerService(String[] clazzes,
                                    Object service,
                                    Dictionary properties)
Registers a service inside this service context. This service is then isolated inside this context.

Specified by:
registerService in interface 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

ServiceRegistration registerService(String clazz,
                                    Object service,
                                    Dictionary properties)
Registers a service inside this service context. This service is then isolated inside this context.

Specified by:
registerService in interface 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(ServiceListener listener)
Removes a service listener. The listener must be registered inside this service context.

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

ungetService

boolean ungetService(ServiceReference reference)
Ungets the service reference. The service reference must comes from this service context.

Specified by:
ungetService in interface 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)


Copyright © 2011 Apache Software Foundation. All Rights Reserved.