org.apache.felix.ipojo
Class PolicyServiceContext

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

public class PolicyServiceContext
extends Object
implements ServiceContext

The policy service context is a service context aiming to resolve service dependencies inside different service context according to a policy. So, the policy service context behavior follows one of the three following policy:

  • Local : services are only resolved in the local service context.
  • Global : services are only resolved in the global context (hte OSGi one)
  • Local and Global : services are resolved inside the local context and inside the global context
  • Author:
    Felix Project Team

    Field Summary
    static int GLOBAL
              Resolving policy, resolves services inside the global context only.
    static int LOCAL
              Resolving policy, resolves services only in the composite context (local).
    static int LOCAL_AND_GLOBAL
              Resolving policy, resolves services only in the composite (local) and in the global context.
     BundleContext m_global
              The global service registry.
     ServiceContext m_local
              The local (Composite) Service Registry.
     
    Constructor Summary
    PolicyServiceContext(BundleContext global, ServiceContext local, int policy)
              Creates a PolicyServiceContext.
     
    Method Summary
     void addBundleListener(BundleListener arg0)
              Adds a bundle listener.
     void addFrameworkListener(FrameworkListener arg0)
              Adds a framework listener.
     void addServiceListener(ServiceListener listener)
              Adds a service listener according to the policy.
     void addServiceListener(ServiceListener listener, String filter)
              Adds a service listener according to the policy.
     Filter createFilter(String arg0)
              Creates a LDAP filter.
     ServiceReference[] getAllServiceReferences(String clazz, String filter)
              Gets all service references.
     Bundle getBundle()
              Gets the current bundle.
     Bundle getBundle(long bundleId)
              Gets the bundle object with the given id.
     Bundle[] getBundles()
              Gets installed bundles.
     File getDataFile(String filename)
              Gets a data file.
     String getProperty(String key)
              Gets a property value.
     Object getService(ServiceReference ref)
              Gets the service object for the given references.
     ServiceReference getServiceReference(String clazz)
              Gets a service reference for the required service specification.
     ServiceReference[] getServiceReferences(String clazz, String filter)
              Get a service reference for the required service specification.
     Bundle installBundle(String location)
              Installs a bundle.
     Bundle installBundle(String location, InputStream input)
              Installs a bundle.
     ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties)
              This method is not supported.
     ServiceRegistration registerService(String clazz, Object service, Dictionary properties)
              This method is not supported.
     void removeBundleListener(BundleListener listener)
              Removes the bundle listener.
     void removeFrameworkListener(FrameworkListener listener)
              Removes a framework listener.
     void removeServiceListener(ServiceListener listener)
              Removes a service listener.
     boolean ungetService(ServiceReference reference)
              Ungets the service reference.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    LOCAL

    public static final int LOCAL
    Resolving policy, resolves services only in the composite context (local). This policy is the default one for services inherited from service-level dependencies.

    See Also:
    Constant Field Values

    LOCAL_AND_GLOBAL

    public static final int LOCAL_AND_GLOBAL
    Resolving policy, resolves services only in the composite (local) and in the global context. This policy is the default one for implementation dependency.

    See Also:
    Constant Field Values

    GLOBAL

    public static final int GLOBAL
    Resolving policy, resolves services inside the global context only.

    See Also:
    Constant Field Values

    m_global

    public BundleContext m_global
    The global service registry. Targets the OSGi service registry.


    m_local

    public ServiceContext m_local
    The local (Composite) Service Registry.

    Constructor Detail

    PolicyServiceContext

    public PolicyServiceContext(BundleContext global,
                                ServiceContext local,
                                int policy)
    Creates a PolicyServiceContext. If the local context is null, sets the policy to GLOBAL, else use the given policy.

    Parameters:
    global - the global bundle context
    local - the parent (local) service context
    policy - the resolution policy
    Method Detail

    addServiceListener

    public void addServiceListener(ServiceListener listener,
                                   String filter)
                            throws InvalidSyntaxException
    Adds a service listener according to the policy. Be aware, that the listener can be registered both in the local and in the global context if the LOCAL_AND_GLOBAL is used.

    Specified by:
    addServiceListener in interface ServiceContext
    Specified by:
    addServiceListener in interface BundleContext
    Parameters:
    listener - the listener to add
    filter - the LDAP filter
    Throws:
    InvalidSyntaxException - if the filter is malformed.
    See Also:
    ServiceContext.addServiceListener(org.osgi.framework.ServiceListener, java.lang.String)

    addServiceListener

    public void addServiceListener(ServiceListener listener)
    Adds a service listener according to the policy. Be aware, that the listener can be registered both in the local and in the global context if the LOCAL_AND_GLOBAL is used.

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

    getAllServiceReferences

    public ServiceReference[] getAllServiceReferences(String clazz,
                                                      String filter)
                                               throws InvalidSyntaxException
    Gets all service references. These references are found inside the local registry, global registry or both according to the policy. The returned array can contain service references from both context.

    Specified by:
    getAllServiceReferences in interface ServiceContext
    Specified by:
    getAllServiceReferences in interface BundleContext
    Parameters:
    clazz - the required service specification.
    filter - the LDAP filter
    Returns:
    the array of service reference, null if no service available
    Throws:
    InvalidSyntaxException - if the LDAP filter is malformed
    See Also:
    ServiceContext.getAllServiceReferences(java.lang.String, java.lang.String)

    getService

    public Object getService(ServiceReference ref)
    Gets the service object for the given references. The service is get inside the context according to the policy.

    Specified by:
    getService in interface ServiceContext
    Specified by:
    getService in interface BundleContext
    Parameters:
    ref - the service reference
    Returns:
    the service object
    See Also:
    ServiceContext.getService(org.osgi.framework.ServiceReference)

    getServiceReference

    public ServiceReference getServiceReference(String clazz)
    Gets a service reference for the required service specification. The service is looked inside the context according to the policy.

    Specified by:
    getServiceReference in interface ServiceContext
    Specified by:
    getServiceReference in interface BundleContext
    Parameters:
    clazz - the required service specification
    Returns:
    a service reference or null if no matching service available
    See Also:
    ServiceContext.getServiceReference(java.lang.String)

    getServiceReferences

    public ServiceReference[] getServiceReferences(String clazz,
                                                   String filter)
                                            throws InvalidSyntaxException
    Get a service reference for the required service specification. The services are looked inside the context according to the policy.

    Specified by:
    getServiceReferences in interface ServiceContext
    Specified by:
    getServiceReferences in interface BundleContext
    Parameters:
    clazz - the required service specification
    filter - the LDAP filter
    Returns:
    a service reference array or null if not consistent service available
    Throws:
    InvalidSyntaxException - if the LDAP filter is malformed
    See Also:
    ServiceContext.getServiceReference(java.lang.String)

    registerService

    public ServiceRegistration registerService(String[] clazzes,
                                               Object service,
                                               Dictionary properties)
    This method is not supported. This context can only be used to resolve service dependencies.

    Specified by:
    registerService in interface ServiceContext
    Specified by:
    registerService in interface BundleContext
    Parameters:
    clazzes - the specifications
    service - the service object
    properties - the service properties
    Returns:
    the service registration object
    See Also:
    ServiceContext.registerService(java.lang.String[], java.lang.Object, java.util.Dictionary)

    registerService

    public ServiceRegistration registerService(String clazz,
                                               Object service,
                                               Dictionary properties)
    This method is not supported. This context can only be used to resolve service dependencies.

    Specified by:
    registerService in interface ServiceContext
    Specified by:
    registerService in interface BundleContext
    Parameters:
    clazz - the specification
    service - the service object
    properties - the service properties to publish
    Returns:
    the service registration object
    See Also:
    ServiceContext.registerService(java.lang.String, java.lang.Object, java.util.Dictionary)

    removeServiceListener

    public void removeServiceListener(ServiceListener listener)
    Removes a service listener.

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

    ungetService

    public boolean ungetService(ServiceReference reference)
    Ungets the service reference.

    Specified by:
    ungetService in interface ServiceContext
    Specified by:
    ungetService in interface BundleContext
    Parameters:
    reference - the service reference to unget.
    Returns:
    true if the service release if the reference is no more used.
    See Also:
    ServiceContext.ungetService(org.osgi.framework.ServiceReference)

    addBundleListener

    public void addBundleListener(BundleListener arg0)
    Adds a bundle listener. Delegate on the global bundle context.

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

    addFrameworkListener

    public void addFrameworkListener(FrameworkListener arg0)
    Adds a framework listener. Delegates on the global bundle context.

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

    createFilter

    public Filter createFilter(String arg0)
                        throws InvalidSyntaxException
    Creates a LDAP filter.

    Specified by:
    createFilter in interface BundleContext
    Parameters:
    arg0 - the String-form of the filter
    Returns:
    the created filter object
    Throws:
    InvalidSyntaxException - if the given argument is not a valid against the LDAP grammar.
    See Also:
    BundleContext.createFilter(java.lang.String)

    getBundle

    public Bundle getBundle()
    Gets the current bundle.

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

    getBundle

    public Bundle getBundle(long bundleId)
    Gets the bundle object with the given id.

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

    getBundles

    public Bundle[] getBundles()
    Gets installed bundles.

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

    getDataFile

    public File getDataFile(String filename)
    Gets a data file.

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

    getProperty

    public String getProperty(String key)
    Gets a property value.

    Specified by:
    getProperty in interface BundleContext
    Parameters:
    key - the 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)

    installBundle

    public Bundle installBundle(String location)
                         throws BundleException
    Installs a bundle.

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

    installBundle

    public Bundle installBundle(String location,
                                InputStream input)
                         throws BundleException
    Installs a bundle.

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

    removeBundleListener

    public void removeBundleListener(BundleListener listener)
    Removes the bundle listener.

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

    removeFrameworkListener

    public void removeFrameworkListener(FrameworkListener listener)
    Removes a framework listener.

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


    Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.