org.apache.felix.ipojo.junit4osgi.helpers
Class IPOJOHelper

java.lang.Object
  extended by org.apache.felix.ipojo.junit4osgi.Helper
      extended by org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper

public class IPOJOHelper
extends Helper

iPOJO Helper. This helper helps getting Factory, and managing ComponentInstance.

Author:
Felix Project Team

Constructor Summary
IPOJOHelper(OSGiTestCase tc)
          Creates a IPOJOHelper.
 
Method Summary
static ComponentInstance createComponentInstance(Bundle bundle, String factoryName, Dictionary configuration)
          Creates a new component instance with the given configuration, from the factory specified in the given bundle.
static ComponentInstance createComponentInstance(Bundle bundle, String factoryName, String instanceName)
          Creates a new component instance with the given name (and empty configuration), from the factory specified in the given bundle.
static ComponentInstance createComponentInstance(Bundle bundle, String factoryName, String instanceName, Dictionary configuration)
          Creates a new component instance with the given name and configuration, from the factory specified in the given bundle.
static ComponentInstance createComponentInstance(ServiceContext serviceContext, String factoryName, Dictionary configuration)
          Creates a new component instance with the given name and configuration, from the factory specified in the given service context.
static ComponentInstance createComponentInstance(ServiceContext serviceContext, String factoryName, String instanceName)
          Creates a new component instance with the given name (and an empty configuration), from the factory specified in the given service context.
static ComponentInstance createComponentInstance(ServiceContext serviceContext, String factoryName, String instanceName, Dictionary configuration)
          Creates a new component instance with the given name and configuration, from the factory specified in the given service context.
 ComponentInstance createComponentInstance(String factoryName)
          Creates a new component instance with no configuration, from the factory specified in the local bundle.
 ComponentInstance createComponentInstance(String factoryName, Dictionary configuration)
          Creates a new component instance with the given configuration, from the factory specified in the local bundle.
 ComponentInstance createComponentInstance(String factoryName, String instanceName)
          Creates a new component instance with the given name (and empty configuration), from the factory specified in the local bundle.
 ComponentInstance createComponentInstance(String factoryName, String instanceName, Dictionary configuration)
          Creates a new component instance with the given name and configuration, from the factory specified in the given bundle.
 void dispose()
          Disposes created instances.
static Factory getFactory(Bundle bundle, String factoryName)
          Returns the component factory with the given name in the given bundle.
static Factory getFactory(ServiceContext serviceContext, String factoryName)
          Returns the component factory with the given name, registered in the given service context.
 Factory getFactory(String factoryName)
          Returns the component factory with the given name in the local bundle.
static HandlerFactory getHandlerFactory(Bundle bundle, String factoryName)
          Returns the handler factory with the given name in the given bundle.
 HandlerFactory getHandlerFactory(String factoryName)
          Returns the handler factory with the given name in the local bundle.
 ComponentInstance getInstanceByName(String name)
          Gets a created instance from the instance name.
static Element getMetadata(Bundle bundle, String component)
          Returns the metadata description of the component with the given name, defined in the given bundle.
 Element getMetadata(String component)
          Returns the metadata description of the component defined in this bundle.
static Object getServiceObject(ServiceContext serviceContext, String itf, String filter)
          Returns the service object of a service registered in the specified service context, offering the specified interface and matching the given filter.
static Object[] getServiceObjects(ServiceContext serviceContext, String itf, String filter)
          Returns the service objects of the services registered in the specified service context, offering the specified interface and matching the given filter.
static ServiceReference getServiceReference(ServiceContext serviceContext, String itf, String filter)
          Returns the service reference of a service registered in the specified service context, offering the specified interface and matching the given filter.
static ServiceReference getServiceReferenceByName(Bundle bundle, String itf, String name)
          Returns the service reference of a service provided by the specified bundle, offering the specified interface and having the given name.
static ServiceReference getServiceReferenceByName(ServiceContext serviceContext, String itf, String name)
          Returns the service reference of a service registered in the specified service context, offering the specified interface and having the given name.
 ServiceReference getServiceReferenceByName(String itf, String name)
          Returns the service reference of a service provided by the local bundle, offering the specified interface and having the given name.
static ServiceReference getServiceReferenceByPID(ServiceContext serviceContext, String itf, String pid)
          Returns the service reference of the service registered in the specified service context, offering the specified interface and having the given persistent ID.
static ServiceReference[] getServiceReferences(ServiceContext serviceContext, String itf, String filter)
          Returns the service reference of all the services registered in the specified service context, offering the specified interface and matching the given filter.
static boolean isServiceAvailable(ServiceContext sc, String itf)
          Checks the availability of a service inside the given service context.
static boolean isServiceAvailableByName(ServiceContext sc, String itf, String name)
          Checks the availability of a service inside the given service context.
 boolean isServiceAvailableByName(String itf, String name)
          Checks if the service is available.
static boolean isServiceAvailableByPID(ServiceContext sc, String itf, String pid)
          Checks the availability of a service inside the given service context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IPOJOHelper

public IPOJOHelper(OSGiTestCase tc)
Creates a IPOJOHelper.

Parameters:
tc - the OSGi Test Case
Method Detail

dispose

public void dispose()
Disposes created instances.

Specified by:
dispose in class Helper
See Also:
Helper.dispose()

getInstanceByName

public ComponentInstance getInstanceByName(String name)
Gets a created instance from the instance name.

Parameters:
name - the instance name.
Returns:
the created ComponentInstance or null if the instance was not created during the session.

createComponentInstance

public static ComponentInstance createComponentInstance(Bundle bundle,
                                                        String factoryName,
                                                        String instanceName)
Creates a new component instance with the given name (and empty configuration), from the factory specified in the given bundle.

Parameters:
bundle - the bundle from which the component factory is defined.
factoryName - the name of the component factory, defined in the specified bundle.
instanceName - the name of the component instance to create.
Returns:
the newly created component instance.

createComponentInstance

public static ComponentInstance createComponentInstance(Bundle bundle,
                                                        String factoryName,
                                                        Dictionary configuration)
Creates a new component instance with the given configuration, from the factory specified in the given bundle.

Parameters:
bundle - the bundle from which the component factory is defined.
factoryName - the name of the component factory, defined in the specified bundle.
configuration - the configuration of the component instance to create.
Returns:
the newly created component instance.

createComponentInstance

public static ComponentInstance createComponentInstance(Bundle bundle,
                                                        String factoryName,
                                                        String instanceName,
                                                        Dictionary configuration)
Creates a new component instance with the given name and configuration, from the factory specified in the given bundle.

Parameters:
bundle - the bundle from which the component factory is defined.
factoryName - the name of the component factory, defined in the specified bundle.
instanceName - the name of the component instance to create.
configuration - the configuration of the instance to create.
Returns:
the newly created component instance.

createComponentInstance

public static ComponentInstance createComponentInstance(ServiceContext serviceContext,
                                                        String factoryName,
                                                        String instanceName)
Creates a new component instance with the given name (and an empty configuration), from the factory specified in the given service context.

Parameters:
serviceContext - the service context in which the component factory service is registered.
factoryName - the name of the component factory, defined in the specified service context.
instanceName - the name of the component instance to create.
Returns:
the newly created component instance.

createComponentInstance

public static ComponentInstance createComponentInstance(ServiceContext serviceContext,
                                                        String factoryName,
                                                        Dictionary configuration)
Creates a new component instance with the given name and configuration, from the factory specified in the given service context.

Parameters:
serviceContext - the service context in which the component factory service is registered.
factoryName - the name of the component factory, defined in the specified service context.
configuration - the configuration of the instance to create.
Returns:
the newly created component instance.

createComponentInstance

public static ComponentInstance createComponentInstance(ServiceContext serviceContext,
                                                        String factoryName,
                                                        String instanceName,
                                                        Dictionary configuration)
Creates a new component instance with the given name and configuration, from the factory specified in the given service context.

Parameters:
serviceContext - the service context in which the component factory service is registered.
factoryName - the name of the component factory, defined in the specified service context.
instanceName - the name of the component instance to create.
configuration - the configuration of the instance to create.
Returns:
the newly created component instance.

createComponentInstance

public ComponentInstance createComponentInstance(String factoryName,
                                                 String instanceName)
Creates a new component instance with the given name (and empty configuration), from the factory specified in the local bundle.

Parameters:
factoryName - the name of the component factory, defined in the local bundle.
instanceName - the name of the component instance to create.
Returns:
the newly created component instance.

createComponentInstance

public ComponentInstance createComponentInstance(String factoryName,
                                                 Dictionary configuration)
Creates a new component instance with the given configuration, from the factory specified in the local bundle.

Parameters:
factoryName - the name of the component factory, in the local bundle.
configuration - the configuration of the component instance to create.
Returns:
the newly created component instance.

createComponentInstance

public ComponentInstance createComponentInstance(String factoryName)
Creates a new component instance with no configuration, from the factory specified in the local bundle.

Parameters:
factoryName - the name of the component factory, in the local bundle.
Returns:
the newly created component instance.

createComponentInstance

public ComponentInstance createComponentInstance(String factoryName,
                                                 String instanceName,
                                                 Dictionary configuration)
Creates a new component instance with the given name and configuration, from the factory specified in the given bundle.

Parameters:
factoryName - the name of the component factory, defined in the specified bundle.
instanceName - the name of the component instance to create.
configuration - the configuration of the instance to create.
Returns:
the newly created component instance.

getFactory

public Factory getFactory(String factoryName)
Returns the component factory with the given name in the local bundle.

Parameters:
factoryName - the name of the factory to retrieve.
Returns:
the component factory with the given name in the local bundle, or null if not found.

getHandlerFactory

public HandlerFactory getHandlerFactory(String factoryName)
Returns the handler factory with the given name in the local bundle.

Parameters:
factoryName - the name of the handler factory to retrieve.
Returns:
the handler factory with the given name in the local bundle, or null if not found.

getMetadata

public Element getMetadata(String component)
Returns the metadata description of the component defined in this bundle.

Parameters:
component - the name of the locally defined component.
Returns:
the metadata description of the component with the given name, defined in this given bundle, or null if not found.

getFactory

public static Factory getFactory(Bundle bundle,
                                 String factoryName)
Returns the component factory with the given name in the given bundle.

Parameters:
bundle - the bundle from which the component factory is defined.
factoryName - the name of the defined factory.
Returns:
the component factory with the given name in the given bundle, or null if not found.

getFactory

public static Factory getFactory(ServiceContext serviceContext,
                                 String factoryName)
Returns the component factory with the given name, registered in the given service context.

Parameters:
serviceContext - the service context in which the factory service is defined.
factoryName - the name of the factory.
Returns:
the component factory with the given name, registered in the given service context.

getHandlerFactory

public static HandlerFactory getHandlerFactory(Bundle bundle,
                                               String factoryName)
Returns the handler factory with the given name in the given bundle.

Parameters:
bundle - the bundle from which the handler factory is defined.
factoryName - the name of the handler factory to retrieve.
Returns:
the handler factory with the given name in the given bundle, or null if not found.

getMetadata

public static Element getMetadata(Bundle bundle,
                                  String component)
Returns the metadata description of the component with the given name, defined in the given bundle.

Parameters:
bundle - the bundle from which the component is defined.
component - the name of the defined component.
Returns:
the metadata description of the component with the given name, defined in the given bundle, or null if not found.

getServiceObject

public static Object getServiceObject(ServiceContext serviceContext,
                                      String itf,
                                      String filter)
Returns the service object of a service registered in the specified service context, offering the specified interface and matching the given filter.

Parameters:
serviceContext - the service context in which the service is searched.
itf - the interface provided by the searched service.
filter - an additional filter (can be null).
Returns:
the service object provided by the specified bundle, offering the specified interface and matching the given filter.

getServiceObjects

public static Object[] getServiceObjects(ServiceContext serviceContext,
                                         String itf,
                                         String filter)
Returns the service objects of the services registered in the specified service context, offering the specified interface and matching the given filter.

Parameters:
serviceContext - the service context in which services are searched.
itf - the interface provided by the searched services.
filter - an additional filter (can be null).
Returns:
the service objects provided by the specified bundle, offering the specified interface and matching the given filter.

getServiceReference

public static ServiceReference getServiceReference(ServiceContext serviceContext,
                                                   String itf,
                                                   String filter)
Returns the service reference of a service registered in the specified service context, offering the specified interface and matching the given filter.

Parameters:
serviceContext - the service context in which services are searched.
itf - the interface provided by the searched service.
filter - an additional filter (can be null).
Returns:
a service reference registered in the specified service context, offering the specified interface and matching the given filter. If no service is found, null is returned.

getServiceReferenceByPID

public static ServiceReference getServiceReferenceByPID(ServiceContext serviceContext,
                                                        String itf,
                                                        String pid)
Returns the service reference of the service registered in the specified service context, offering the specified interface and having the given persistent ID.

Parameters:
serviceContext - the service context in which services are searched.
itf - the interface provided by the searched service.
pid - the persistent ID of the searched service.
Returns:
a service registered in the specified service context, offering the specified interface and having the given persistent ID.

getServiceReferences

public static ServiceReference[] getServiceReferences(ServiceContext serviceContext,
                                                      String itf,
                                                      String filter)
Returns the service reference of all the services registered in the specified service context, offering the specified interface and matching the given filter.

Parameters:
serviceContext - the service context in which services are searched.
itf - the interface provided by the searched services.
filter - an additional filter (can be null).
Returns:
all the service references registered in the specified service context, offering the specified interface and matching the given filter. If no service matches, an empty array is returned.

getServiceReferenceByName

public static ServiceReference getServiceReferenceByName(ServiceContext serviceContext,
                                                         String itf,
                                                         String name)
Returns the service reference of a service registered in the specified service context, offering the specified interface and having the given name.

Parameters:
serviceContext - the service context in which services are searched.
itf - the interface provided by the searched service.
name - the name of the searched service.
Returns:
a service registered in the specified service context, offering the specified interface and having the given name.

isServiceAvailable

public static boolean isServiceAvailable(ServiceContext sc,
                                         String itf)
Checks the availability of a service inside the given service context.

Parameters:
sc - the service context
itf - the service interface to found
Returns:
true if the service is available in the service context, false otherwise.

isServiceAvailableByName

public static boolean isServiceAvailableByName(ServiceContext sc,
                                               String itf,
                                               String name)
Checks the availability of a service inside the given service context.

Parameters:
sc - the service context
itf - the service interface to found
name - the service provider name
Returns:
true if the service is available in the service context, false otherwise.

isServiceAvailableByPID

public static boolean isServiceAvailableByPID(ServiceContext sc,
                                              String itf,
                                              String pid)
Checks the availability of a service inside the given service context.

Parameters:
sc - the service context
itf - the service interface to found
pid - the pid of the service
Returns:
true if the service is available in the service context, false otherwise.

getServiceReferenceByName

public static ServiceReference getServiceReferenceByName(Bundle bundle,
                                                         String itf,
                                                         String name)
Returns the service reference of a service provided by the specified bundle, offering the specified interface and having the given name.

Parameters:
bundle - the bundle from which the service is searched.
itf - the interface provided by the searched service.
name - the name of the searched service.
Returns:
a service provided by the specified bundle, offering the specified interface and having the given name.

getServiceReferenceByName

public ServiceReference getServiceReferenceByName(String itf,
                                                  String name)
Returns the service reference of a service provided by the local bundle, offering the specified interface and having the given name.

Parameters:
itf - the interface provided by the searched service.
name - the name of the searched service.
Returns:
a service provided by the specified bundle, offering the specified interface and having the given name.

isServiceAvailableByName

public boolean isServiceAvailableByName(String itf,
                                        String name)
Checks if the service is available.

Parameters:
itf - the service interface
name - the service provider name
Returns:
true if the service is available, false otherwise.


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.