org.apache.felix.ipojo
Class PolicyServiceContext

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

public class PolicyServiceContext
extends java.lang.Object
implements ServiceContext

The policy service context is a service context aiming to solve service requirement. It's parameterized by a resolving policy. Three policies are managed : - Local : services are only solve un the local service registry - Global : services are resolved only in the global (i.e. OSGi) service registry - Local and Global : services are resolved inside the local registry and the global registry

Author:
Felix Project Team

Field Summary
static int GLOBAL
          Resolving policy, look inside the global only.
static int LOCAL
          Resolving policy, look only in the composite.
static int LOCAL_AND_GLOBAL
          Resolving policy, look inside the composite and in the global scope.
 org.osgi.framework.BundleContext m_global
          Global service registry.
 ServiceContext m_local
          Local (Composite) Service Registry.
 
Constructor Summary
PolicyServiceContext(org.osgi.framework.BundleContext global, ServiceContext local, int policy)
          Create a new PolicyServiceContext.
 
Method Summary
 void addBundleListener(org.osgi.framework.BundleListener arg0)
          Add a bundle listener.
 void addFrameworkListener(org.osgi.framework.FrameworkListener arg0)
          Add a framework listener.
 void addServiceListener(org.osgi.framework.ServiceListener listener)
          Add a service listener according to the policy.
 void addServiceListener(org.osgi.framework.ServiceListener listener, java.lang.String filter)
          Add a service listener according to the policy.
 org.osgi.framework.Filter createFilter(java.lang.String arg0)
          Create a LDAP filter.
 org.osgi.framework.ServiceReference[] getAllServiceReferences(java.lang.String clazz, java.lang.String filter)
          Get all service references.
 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.
 java.lang.String getProperty(java.lang.String key)
          Get a property value.
 java.lang.Object getService(org.osgi.framework.ServiceReference ref)
          Get the service object for the given reference.
 org.osgi.framework.ServiceReference getServiceReference(java.lang.String clazz)
          Get a service reference for the required service specification.
 org.osgi.framework.ServiceReference[] getServiceReferences(java.lang.String clazz, java.lang.String filter)
          Get a service reference for the required service specification.
 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)
          This method is not supported.
 org.osgi.framework.ServiceRegistration registerService(java.lang.String clazz, java.lang.Object service, java.util.Dictionary properties)
          This method is not supported.
 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
 

Field Detail

LOCAL

public static final int LOCAL
Resolving policy, look only in the composite.

See Also:
Constant Field Values

LOCAL_AND_GLOBAL

public static final int LOCAL_AND_GLOBAL
Resolving policy, look inside the composite and in the global scope. This policy is the default one for implementation dependency.

See Also:
Constant Field Values

GLOBAL

public static final int GLOBAL
Resolving policy, look inside the global only.

See Also:
Constant Field Values

m_global

public org.osgi.framework.BundleContext m_global
Global service registry.


m_local

public ServiceContext m_local
Local (Composite) Service Registry.

Constructor Detail

PolicyServiceContext

public PolicyServiceContext(org.osgi.framework.BundleContext global,
                            ServiceContext local,
                            int policy)
Create a new PolicyServiceContext.

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

addServiceListener

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

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

addServiceListener

public void addServiceListener(org.osgi.framework.ServiceListener listener)
Add a service listener according to the policy.

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

getAllServiceReferences

public org.osgi.framework.ServiceReference[] getAllServiceReferences(java.lang.String clazz,
                                                                     java.lang.String filter)
                                                              throws org.osgi.framework.InvalidSyntaxException
Get all service references. These reference are found inside the local registry, global registry or both according to the policy.

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

getService

public java.lang.Object getService(org.osgi.framework.ServiceReference ref)
Get the service object for the given reference.

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

getServiceReference

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

Specified by:
getServiceReference in interface ServiceContext
Specified by:
getServiceReference in interface org.osgi.framework.BundleContext
Parameters:
clazz - : the required service specification
Returns:
a service reference or null if not consistent service available
See Also:
ServiceContext.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 a service reference for the required service specification.

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

registerService

public org.osgi.framework.ServiceRegistration registerService(java.lang.String[] clazzes,
                                                              java.lang.Object service,
                                                              java.util.Dictionary properties)
This method is not supported.

Specified by:
registerService in interface ServiceContext
Specified by:
registerService in interface org.osgi.framework.BundleContext
Parameters:
clazzes - : specifications
service - : service object
properties - : service properties
Returns:
: the service registration object
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)
This method is not supported.

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

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)

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 service reference to unget.
Returns:
true if the unget is successful.
See Also:
ServiceContext.ungetService(org.osgi.framework.ServiceReference)

addBundleListener

public void addBundleListener(org.osgi.framework.BundleListener arg0)
Add a bundle listener. Delegate on the global bundle context.

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

addFrameworkListener

public void addFrameworkListener(org.osgi.framework.FrameworkListener arg0)
Add a framework listener. Delegate on the global bundle context.

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

createFilter

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

Specified by:
createFilter in interface org.osgi.framework.BundleContext
Parameters:
arg0 - : String-form of the filter
Returns:
the created filter object
Throws:
org.osgi.framework.InvalidSyntaxException - : if the given argument is not a valid against the LDAP grammar.
See Also:
BundleContext.createFilter(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)

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)

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)