org.apache.felix.ipojo
Class IPojoContext

java.lang.Object
  extended by org.apache.felix.ipojo.IPojoContext
All Implemented Interfaces:
ServiceContext, org.osgi.framework.BundleContext

public class IPojoContext
extends java.lang.Object
implements org.osgi.framework.BundleContext, ServiceContext

The iPOJO Context is a BundleContext implementation allowing the separation between Bundle context and Service (Bundle) Context.

Author:
Felix Project Team

Constructor Summary
IPojoContext(org.osgi.framework.BundleContext context)
          Constructor.
IPojoContext(org.osgi.framework.BundleContext bundleContext, ServiceContext serviceContext)
          Constructor.
 
Method Summary
 void addBundleListener(org.osgi.framework.BundleListener listener)
          Add a bundle listener.
 void addFrameworkListener(org.osgi.framework.FrameworkListener listener)
          Add a framework listener.
 void addServiceListener(org.osgi.framework.ServiceListener listener)
          Add a service listener.
 void addServiceListener(org.osgi.framework.ServiceListener listener, java.lang.String filter)
          Add a service listener.
 org.osgi.framework.Filter createFilter(java.lang.String filter)
          Create a Filter object.
 org.osgi.framework.ServiceReference[] getAllServiceReferences(java.lang.String clazz, java.lang.String filter)
          Get the service references matching with the given query.
 org.osgi.framework.Bundle getBundle()
          Get the current bundle.
 org.osgi.framework.Bundle getBundle(long bundleId)
          Get the bundle object with the given id.
 org.osgi.framework.Bundle[] getBundles()
          Get installed bundles.
 java.io.File getDataFile(java.lang.String filename)
          Get a data file.
 org.osgi.framework.BundleContext getGlobalContext()
          Get the global context, i.e.
 java.lang.String getProperty(java.lang.String key)
          Get a property value.
 java.lang.Object getService(org.osgi.framework.ServiceReference reference)
          Get a service object.
 ServiceContext getServiceContext()
          Get the service context, i.e.
 org.osgi.framework.ServiceReference getServiceReference(java.lang.String clazz)
          Get a service reference for the given interface.
 org.osgi.framework.ServiceReference[] getServiceReferences(java.lang.String clazz, java.lang.String filter)
          Get service reference list for the given query.
 org.osgi.framework.Bundle installBundle(java.lang.String location)
          Install a bundle.
 org.osgi.framework.Bundle installBundle(java.lang.String location, java.io.InputStream input)
          Install a bundle.
 org.osgi.framework.ServiceRegistration registerService(java.lang.String[] clazzes, java.lang.Object service, java.util.Dictionary properties)
          Register a service.
 org.osgi.framework.ServiceRegistration registerService(java.lang.String clazz, java.lang.Object service, java.util.Dictionary properties)
          Register a service.
 void removeBundleListener(org.osgi.framework.BundleListener listener)
          Remove a bundle listener.
 void removeFrameworkListener(org.osgi.framework.FrameworkListener listener)
          Remove a framework listener.
 void removeServiceListener(org.osgi.framework.ServiceListener listener)
          Remove a service listener.
 boolean ungetService(org.osgi.framework.ServiceReference reference)
          Unget the service reference.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IPojoContext

public IPojoContext(org.osgi.framework.BundleContext context)
Constructor. Used when the service context = the bundle context

Parameters:
context - : bundle context

IPojoContext

public IPojoContext(org.osgi.framework.BundleContext bundleContext,
                    ServiceContext serviceContext)
Constructor. Used when the service context and the bundle context are different

Parameters:
bundleContext - : bundle context
serviceContext - : service context
Method Detail

addBundleListener

public void addBundleListener(org.osgi.framework.BundleListener listener)
Add a bundle listener.

Specified by:
addBundleListener in interface org.osgi.framework.BundleContext
Parameters:
listener - : the listener to add
See Also:
BundleContext.addBundleListener(org.osgi.framework.BundleListener)

addFrameworkListener

public void addFrameworkListener(org.osgi.framework.FrameworkListener listener)
Add a framework listener.

Specified by:
addFrameworkListener in interface org.osgi.framework.BundleContext
Parameters:
listener - : the listener object to add
See Also:
BundleContext.addFrameworkListener(org.osgi.framework.FrameworkListener)

addServiceListener

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

Specified by:
addServiceListener in interface ServiceContext
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 - : occurs when the LDAP filter is malformed
See Also:
BundleContext.addServiceListener(org.osgi.framework.ServiceListener, java.lang.String)

addServiceListener

public void addServiceListener(org.osgi.framework.ServiceListener listener)
Add a service listener.

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

createFilter

public org.osgi.framework.Filter createFilter(java.lang.String filter)
                                       throws org.osgi.framework.InvalidSyntaxException
Create a Filter object.

Specified by:
createFilter in interface org.osgi.framework.BundleContext
Parameters:
filter - : the string form of the LDAP filter to create
Returns:
the Filter object.
Throws:
org.osgi.framework.InvalidSyntaxException - : occurs when the given filter is malformed
See Also:
BundleContext.createFilter(java.lang.String)

getAllServiceReferences

public org.osgi.framework.ServiceReference[] getAllServiceReferences(java.lang.String clazz,
                                                                     java.lang.String filter)
                                                              throws org.osgi.framework.InvalidSyntaxException
Get the service references matching with the given query.

Specified by:
getAllServiceReferences in interface ServiceContext
Specified by:
getAllServiceReferences in interface org.osgi.framework.BundleContext
Parameters:
clazz - : Required interface
filter - : LDAP filter
Returns:
the array of available service reference
Throws:
org.osgi.framework.InvalidSyntaxException - : occurs if the LDAP filter is malformed
See Also:
BundleContext.getAllServiceReferences(java.lang.String, java.lang.String)

getBundle

public org.osgi.framework.Bundle getBundle()
Get the current bundle.

Specified by:
getBundle in interface org.osgi.framework.BundleContext
Returns:
the current bundle
See Also:
BundleContext.getBundle()

getBundle

public org.osgi.framework.Bundle getBundle(long bundleId)
Get the bundle object with the given id.

Specified by:
getBundle in interface org.osgi.framework.BundleContext
Parameters:
bundleId - : bundle id
Returns:
the bundle object
See Also:
BundleContext.getBundle(long)

getBundles

public org.osgi.framework.Bundle[] getBundles()
Get installed bundles.

Specified by:
getBundles in interface org.osgi.framework.BundleContext
Returns:
the list of installed bundles
See Also:
BundleContext.getBundles()

getDataFile

public java.io.File getDataFile(java.lang.String filename)
Get a data file.

Specified by:
getDataFile in interface org.osgi.framework.BundleContext
Parameters:
filename - : File name.
Returns:
the File object
See Also:
BundleContext.getDataFile(java.lang.String)

getProperty

public java.lang.String getProperty(java.lang.String key)
Get a property value.

Specified by:
getProperty in interface org.osgi.framework.BundleContext
Parameters:
key - : key of the asked property
Returns:
the property value (object) or null if no property are associated with the given key
See Also:
BundleContext.getProperty(java.lang.String)

getService

public java.lang.Object getService(org.osgi.framework.ServiceReference reference)
Get a service object.

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

public org.osgi.framework.ServiceReference getServiceReference(java.lang.String clazz)
Get a service reference for the given interface.

Specified by:
getServiceReference in interface ServiceContext
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 provider available
See Also:
BundleContext.getServiceReference(java.lang.String)

getServiceReferences

public org.osgi.framework.ServiceReference[] getServiceReferences(java.lang.String clazz,
                                                                  java.lang.String filter)
                                                           throws org.osgi.framework.InvalidSyntaxException
Get service reference list for the given query.

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

installBundle

public org.osgi.framework.Bundle installBundle(java.lang.String location)
                                        throws org.osgi.framework.BundleException
Install a bundle.

Specified by:
installBundle in interface org.osgi.framework.BundleContext
Parameters:
location - : URL of the bundle to install
Returns:
the installed bundle
Throws:
org.osgi.framework.BundleException - : if the bundle cannot be installed correctly
See Also:
BundleContext.installBundle(java.lang.String)

installBundle

public org.osgi.framework.Bundle installBundle(java.lang.String location,
                                               java.io.InputStream input)
                                        throws org.osgi.framework.BundleException
Install a bundle.

Specified by:
installBundle in interface org.osgi.framework.BundleContext
Parameters:
location - : URL of the bundle to install
input - :
Returns:
the installed bundle
Throws:
org.osgi.framework.BundleException - : if the bundle cannot be installed correctly
See Also:
BundleContext.installBundle(java.lang.String, java.io.InputStream)

registerService

public org.osgi.framework.ServiceRegistration registerService(java.lang.String[] clazzes,
                                                              java.lang.Object service,
                                                              java.util.Dictionary properties)
Register a service.

Specified by:
registerService in interface ServiceContext
Specified by:
registerService in interface org.osgi.framework.BundleContext
Parameters:
clazzes - : interfaces provided by the service.
service - : the service object.
properties - : service properties.
Returns:
the service registration for this service publication.
See Also:
ServiceContext.registerService(java.lang.String[], java.lang.Object, java.util.Dictionary)

registerService

public org.osgi.framework.ServiceRegistration registerService(java.lang.String clazz,
                                                              java.lang.Object service,
                                                              java.util.Dictionary properties)
Register a service.

Specified by:
registerService in interface ServiceContext
Specified by:
registerService in interface org.osgi.framework.BundleContext
Parameters:
clazz - : interface provided by the service.
service - : the service object.
properties - : service properties.
Returns:
the service registration for this service publication.
See Also:
BundleContext.registerService(java.lang.String, java.lang.Object, java.util.Dictionary)

removeBundleListener

public void removeBundleListener(org.osgi.framework.BundleListener listener)
Remove a bundle listener.

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

removeFrameworkListener

public void removeFrameworkListener(org.osgi.framework.FrameworkListener listener)
Remove a framework listener.

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

removeServiceListener

public void removeServiceListener(org.osgi.framework.ServiceListener listener)
Remove a service listener.

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

ungetService

public boolean ungetService(org.osgi.framework.ServiceReference reference)
Unget the service reference.

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

getGlobalContext

public org.osgi.framework.BundleContext getGlobalContext()
Get the global context, i.e. the bundle context of the factory.

Returns:
the global bundle context.

getServiceContext

public ServiceContext getServiceContext()
Get the service context, i.e. the composite context.

Returns:
the service context.