org.springframework.osgi.mock
Class MockBundle

java.lang.Object
  extended by org.springframework.osgi.mock.MockBundle
All Implemented Interfaces:
Bundle
Direct Known Subclasses:
EntryLookupControllingMockBundle

public class MockBundle
extends Object
implements Bundle

Bundle mock. Except resource/class loading operations (which are executed on its internal class loader), the rest of the methods are dummies.

Author:
Costin Leau

Field Summary
 
Fields inherited from interface org.osgi.framework.Bundle
ACTIVE, INSTALLED, RESOLVED, START_ACTIVATION_POLICY, START_TRANSIENT, STARTING, STOP_TRANSIENT, STOPPING, UNINSTALLED
 
Constructor Summary
MockBundle()
          Constructs a new MockBundle instance using default values.
MockBundle(BundleContext context)
          Constructs a new MockBundle instance associated with the given bundle context.
MockBundle(Dictionary headers)
          Constructs a new MockBundle instance with the given bundle headers.
MockBundle(String symName)
          Constructs a new MockBundle instance with the given symbolic name.
MockBundle(String symName, Dictionary headers, BundleContext context)
          Constructs a new MockBundle instance using the given bundle symbolic name, properties and associated bundle context.
 
Method Summary
 Enumeration findEntries(String path, String filePattern, boolean recurse)
          Delegates to the classloader.
 BundleContext getBundleContext()
           
 long getBundleId()
           
 BundleContext getContext()
           
 URL getEntry(String name)
           
 Enumeration getEntryPaths(String path)
           
 Dictionary getHeaders()
           
 Dictionary getHeaders(String locale)
           
 long getLastModified()
           
 String getLocation()
           
 ServiceReference[] getRegisteredServices()
           
 URL getResource(String name)
           
 Enumeration getResources(String name)
           
 ServiceReference[] getServicesInUse()
           
 int getState()
           
 String getSymbolicName()
           
 boolean hasPermission(Object permission)
           
 Class loadClass(String name)
           
 void setBundleId(long bundleId)
           
 void setClassLoader(ClassLoader loader)
          Sets the class loader internally used by the bundle to mock the loading operations.
 void setLocation(String location)
          Sets the location for this mock bundle.
 void start()
           
 void start(int options)
           
 void stop()
           
 void stop(int options)
           
 String toString()
           
 void uninstall()
           
 void update()
           
 void update(InputStream in)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MockBundle

public MockBundle()
Constructs a new MockBundle instance using default values.


MockBundle

public MockBundle(Dictionary headers)
Constructs a new MockBundle instance with the given bundle headers.

Parameters:
headers - bundle headers

MockBundle

public MockBundle(BundleContext context)
Constructs a new MockBundle instance associated with the given bundle context.

Parameters:
context - associated bundle context

MockBundle

public MockBundle(String symName)
Constructs a new MockBundle instance with the given symbolic name.

Parameters:
symName - bundle symbolic name

MockBundle

public MockBundle(String symName,
                  Dictionary headers,
                  BundleContext context)
Constructs a new MockBundle instance using the given bundle symbolic name, properties and associated bundle context.

Parameters:
symName - bundle symbolic name
headers - bundle headers
context - associated bundle context
Method Detail

findEntries

public Enumeration findEntries(String path,
                               String filePattern,
                               boolean recurse)
Delegates to the classloader. Identical to classLoader.getResources(path + filePattern);

Specified by:
findEntries in interface Bundle
See Also:
Bundle.findEntries(java.lang.String, java.lang.String, boolean)

getBundleId

public long getBundleId()
Specified by:
getBundleId in interface Bundle

setBundleId

public void setBundleId(long bundleId)

getEntry

public URL getEntry(String name)
Specified by:
getEntry in interface Bundle

getEntryPaths

public Enumeration getEntryPaths(String path)
Specified by:
getEntryPaths in interface Bundle

getHeaders

public Dictionary getHeaders()
Specified by:
getHeaders in interface Bundle

getHeaders

public Dictionary getHeaders(String locale)
Specified by:
getHeaders in interface Bundle

getLastModified

public long getLastModified()
Specified by:
getLastModified in interface Bundle

getLocation

public String getLocation()
Specified by:
getLocation in interface Bundle

getRegisteredServices

public ServiceReference[] getRegisteredServices()
Specified by:
getRegisteredServices in interface Bundle

getResource

public URL getResource(String name)
Specified by:
getResource in interface Bundle

getResources

public Enumeration getResources(String name)
                         throws IOException
Specified by:
getResources in interface Bundle
Throws:
IOException

getServicesInUse

public ServiceReference[] getServicesInUse()
Specified by:
getServicesInUse in interface Bundle

getState

public int getState()
Specified by:
getState in interface Bundle

getSymbolicName

public String getSymbolicName()
Specified by:
getSymbolicName in interface Bundle

hasPermission

public boolean hasPermission(Object permission)
Specified by:
hasPermission in interface Bundle

loadClass

public Class loadClass(String name)
                throws ClassNotFoundException
Specified by:
loadClass in interface Bundle
Throws:
ClassNotFoundException

start

public void start()
           throws BundleException
Specified by:
start in interface Bundle
Throws:
BundleException

start

public void start(int options)
           throws BundleException
Specified by:
start in interface Bundle
Throws:
BundleException

stop

public void stop()
          throws BundleException
Specified by:
stop in interface Bundle
Throws:
BundleException

stop

public void stop(int options)
          throws BundleException
Specified by:
stop in interface Bundle
Throws:
BundleException

uninstall

public void uninstall()
               throws BundleException
Specified by:
uninstall in interface Bundle
Throws:
BundleException

update

public void update()
            throws BundleException
Specified by:
update in interface Bundle
Throws:
BundleException

update

public void update(InputStream in)
            throws BundleException
Specified by:
update in interface Bundle
Throws:
BundleException

getContext

public BundleContext getContext()

getBundleContext

public BundleContext getBundleContext()
Specified by:
getBundleContext in interface Bundle

toString

public String toString()
Overrides:
toString in class Object

setLocation

public void setLocation(String location)
Sets the location for this mock bundle.

Parameters:
location - bundle location

setClassLoader

public void setClassLoader(ClassLoader loader)
Sets the class loader internally used by the bundle to mock the loading operations. By default, the MockBundle uses its own class loader.

Parameters:
loader - mock bundle class loader


Copyright © 2006-2009 Spring Framework. All Rights Reserved.