org.eclipse.gemini.blueprint.mock
Class MockBundleContext

java.lang.Object
  extended by org.eclipse.gemini.blueprint.mock.MockBundleContext
All Implemented Interfaces:
org.osgi.framework.BundleContext

public class MockBundleContext
extends Object
implements org.osgi.framework.BundleContext

BundleContext mock.

Can be configured to use a predefined Bundle or/and configuration. By default, will create an internal MockBundle. Most of the operations are no-op (as anonymous classes with specific functionality can be created per use basis).

Author:
Costin Leau

Field Summary
protected  Set bundleListeners
           
static Properties DEFAULT_PROPERTIES
           
protected  Set serviceListeners
           
 
Constructor Summary
MockBundleContext()
          Constructs a new MockBundleContext instance.
MockBundleContext(org.osgi.framework.Bundle bundle)
          Constructs a new MockBundleContext instance.
MockBundleContext(org.osgi.framework.Bundle bundle, Properties props)
          Constructs a new MockBundleContext instance allowing both the bundle and the context properties to be specified.
 
Method Summary
 void addBundleListener(org.osgi.framework.BundleListener listener)
           
 void addFrameworkListener(org.osgi.framework.FrameworkListener listener)
           
 void addServiceListener(org.osgi.framework.ServiceListener listener)
           
 void addServiceListener(org.osgi.framework.ServiceListener listener, String filter)
           
 org.osgi.framework.Filter createFilter(String filter)
           
 org.osgi.framework.ServiceReference[] getAllServiceReferences(String clazz, String filter)
           
 org.osgi.framework.Bundle getBundle()
           
 org.osgi.framework.Bundle getBundle(long id)
           
 Set getBundleListeners()
          Returns a set of registered bundle listeners.
 org.osgi.framework.Bundle[] getBundles()
           
 File getDataFile(String filename)
           
 String getProperty(String key)
           
 Object getService(org.osgi.framework.ServiceReference reference)
           
 Set getServiceListeners()
          Returns a set of registered service listeners.
 org.osgi.framework.ServiceReference getServiceReference(String clazz)
           
 org.osgi.framework.ServiceReference[] getServiceReferences(String clazz, String filter)
           
 org.osgi.framework.Bundle installBundle(String location)
           
 org.osgi.framework.Bundle installBundle(String location, InputStream input)
           
 org.osgi.framework.ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties)
           
 org.osgi.framework.ServiceRegistration registerService(String clazz, Object service, Dictionary properties)
           
 void removeBundleListener(org.osgi.framework.BundleListener listener)
           
 void removeFrameworkListener(org.osgi.framework.FrameworkListener listener)
           
 void removeServiceListener(org.osgi.framework.ServiceListener listener)
           
 void setBundle(org.osgi.framework.Bundle bundle)
          Sets the bundle associated with this context.
 boolean ungetService(org.osgi.framework.ServiceReference reference)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PROPERTIES

public static final Properties DEFAULT_PROPERTIES

serviceListeners

protected Set serviceListeners

bundleListeners

protected Set bundleListeners
Constructor Detail

MockBundleContext

public MockBundleContext()
Constructs a new MockBundleContext instance. The associated bundle will be created automatically.


MockBundleContext

public MockBundleContext(org.osgi.framework.Bundle bundle)
Constructs a new MockBundleContext instance.

Parameters:
bundle - associated bundle

MockBundleContext

public MockBundleContext(org.osgi.framework.Bundle bundle,
                         Properties props)
Constructs a new MockBundleContext instance allowing both the bundle and the context properties to be specified.

Parameters:
bundle - associated bundle
props - context properties
Method Detail

addBundleListener

public void addBundleListener(org.osgi.framework.BundleListener listener)
Specified by:
addBundleListener in interface org.osgi.framework.BundleContext

addFrameworkListener

public void addFrameworkListener(org.osgi.framework.FrameworkListener listener)
Specified by:
addFrameworkListener in interface org.osgi.framework.BundleContext

addServiceListener

public void addServiceListener(org.osgi.framework.ServiceListener listener)
Specified by:
addServiceListener in interface org.osgi.framework.BundleContext

addServiceListener

public void addServiceListener(org.osgi.framework.ServiceListener listener,
                               String filter)
                        throws org.osgi.framework.InvalidSyntaxException
Specified by:
addServiceListener in interface org.osgi.framework.BundleContext
Throws:
org.osgi.framework.InvalidSyntaxException

createFilter

public org.osgi.framework.Filter createFilter(String filter)
                                       throws org.osgi.framework.InvalidSyntaxException
Specified by:
createFilter in interface org.osgi.framework.BundleContext
Throws:
org.osgi.framework.InvalidSyntaxException

getAllServiceReferences

public org.osgi.framework.ServiceReference[] getAllServiceReferences(String clazz,
                                                                     String filter)
                                                              throws org.osgi.framework.InvalidSyntaxException
Specified by:
getAllServiceReferences in interface org.osgi.framework.BundleContext
Throws:
org.osgi.framework.InvalidSyntaxException

getBundle

public org.osgi.framework.Bundle getBundle()
Specified by:
getBundle in interface org.osgi.framework.BundleContext

getBundle

public org.osgi.framework.Bundle getBundle(long id)
Specified by:
getBundle in interface org.osgi.framework.BundleContext

getBundles

public org.osgi.framework.Bundle[] getBundles()
Specified by:
getBundles in interface org.osgi.framework.BundleContext

getDataFile

public File getDataFile(String filename)
Specified by:
getDataFile in interface org.osgi.framework.BundleContext

getProperty

public String getProperty(String key)
Specified by:
getProperty in interface org.osgi.framework.BundleContext

getService

public Object getService(org.osgi.framework.ServiceReference reference)
Specified by:
getService in interface org.osgi.framework.BundleContext

getServiceReference

public org.osgi.framework.ServiceReference getServiceReference(String clazz)
Specified by:
getServiceReference in interface org.osgi.framework.BundleContext

getServiceReferences

public org.osgi.framework.ServiceReference[] getServiceReferences(String clazz,
                                                                  String filter)
                                                           throws org.osgi.framework.InvalidSyntaxException
Specified by:
getServiceReferences in interface org.osgi.framework.BundleContext
Throws:
org.osgi.framework.InvalidSyntaxException

installBundle

public org.osgi.framework.Bundle installBundle(String location)
                                        throws org.osgi.framework.BundleException
Specified by:
installBundle in interface org.osgi.framework.BundleContext
Throws:
org.osgi.framework.BundleException

installBundle

public org.osgi.framework.Bundle installBundle(String location,
                                               InputStream input)
                                        throws org.osgi.framework.BundleException
Specified by:
installBundle in interface org.osgi.framework.BundleContext
Throws:
org.osgi.framework.BundleException

registerService

public org.osgi.framework.ServiceRegistration registerService(String[] clazzes,
                                                              Object service,
                                                              Dictionary properties)
Specified by:
registerService in interface org.osgi.framework.BundleContext

registerService

public org.osgi.framework.ServiceRegistration registerService(String clazz,
                                                              Object service,
                                                              Dictionary properties)
Specified by:
registerService in interface org.osgi.framework.BundleContext

removeBundleListener

public void removeBundleListener(org.osgi.framework.BundleListener listener)
Specified by:
removeBundleListener in interface org.osgi.framework.BundleContext

removeFrameworkListener

public void removeFrameworkListener(org.osgi.framework.FrameworkListener listener)
Specified by:
removeFrameworkListener in interface org.osgi.framework.BundleContext

removeServiceListener

public void removeServiceListener(org.osgi.framework.ServiceListener listener)
Specified by:
removeServiceListener in interface org.osgi.framework.BundleContext

ungetService

public boolean ungetService(org.osgi.framework.ServiceReference reference)
Specified by:
ungetService in interface org.osgi.framework.BundleContext

setBundle

public void setBundle(org.osgi.framework.Bundle bundle)
Sets the bundle associated with this context.

Parameters:
bundle - associated bundle

getServiceListeners

public Set getServiceListeners()
Returns a set of registered service listeners. Handy method when mocking with listeners is required.

Returns:
set of registered service listeners

getBundleListeners

public Set getBundleListeners()
Returns a set of registered bundle listeners.

Returns:
set of registered bundle listeners


Copyright © 2006-2012. All Rights Reserved.