org.apache.felix.ipojo.handlers.providedservice

## Class ProvidedService

- java.lang.Object
- - org.apache.felix.ipojo.handlers.providedservice.ProvidedService

All Implemented Interfaces:
  org.osgi.framework.ServiceFactory

    public class ProvidedService
    extends java.lang.Object
    implements org.osgi.framework.ServiceFactory

Provided Service represent a provided service by the component.

Author:
  Felix Project Team

### Field Summary

Fields
`static java.lang.String` `ALL_SPECIFICATIONS_FOR_CONTROLLERS`
`static int` `CUSTOM_STRATEGY` Factory policy : CUSTOMIZED.
`static int` `INSTANCE_STRATEGY` Factory policy : INSTANCE.
`static int` `REGISTERED` Service State : REGISTRED.
`static int` `SERVICE_STRATEGY` Factory policy : SERVICE_FACTORY.
`static int` `SINGLETON_STRATEGY` Factory Policy : SINGLETON_FACTORY.
`static int` `STATIC_STRATEGY` Factory policy : STATIC_FACTORY.
`static int` `UNREGISTERED` Service State : UNREGISTRED.

### Constructor Summary

Constructors
Constructor and Description
`ProvidedService(ProvidedServiceHandler handler, java.lang.String[] specification, int factoryPolicy, java.lang.Class creationStrategyClass, java.util.Dictionary conf)` Creates a provided service object.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addListener(ProvidedServiceListener listener)` Add the given listener to the provided service handler's list of listeners.
`protected void` `addProperties(java.util.Dictionary props)` Add properties to the list.
`void` `cleanup()` Removes all the listeners from this provided service before it gets disposed.
`protected void` `deleteProperties(java.util.Dictionary props)` Remove properties from the list.
`org.apache.felix.ipojo.handlers.providedservice.ProvidedService.ServiceController` `getController(java.lang.String field)` Gets the service controller attached to the given field.
`org.apache.felix.ipojo.handlers.providedservice.ProvidedService.ServiceController` `getControllerBySpecification(java.lang.String spec)` Gets the service controller handling the service publishing the given specification.
`java.lang.Class<? extends CreationStrategy>` `getCreationStrategy()`
`protected InstanceManager` `getInstanceManager()`
`int` `getPolicy()`
`Property[]` `getProperties()` Get the list of properties attached to the service registration.
`java.lang.Object` `getService(org.osgi.framework.Bundle bundle, org.osgi.framework.ServiceRegistration registration)` Returns a service object for the dependency.
`org.osgi.framework.ServiceReference` `getServiceReference()` Get the service reference of the service registration.
`org.osgi.framework.ServiceRegistration` `getServiceRegistration()` Get the service registration.
`java.lang.String[]` `getServiceSpecifications()` Get the published service specifications.
`int` `getState()` Get the current provided service state.
`void` `registerService()` Registers the service.
`void` `removeListener(ProvidedServiceListener listener)` Remove the given listener from the provided service handler's list of listeners.
`void` `setController(java.lang.String field, boolean value, java.lang.String specification)` Sets the service controller on this provided service.
`void` `setPostRegistrationCallback(Callback cb)`
`void` `setPostUnregistrationCallback(Callback cb)`
`protected void` `setProperties(Property[] props)` Add properties to the provided service.
`void` `ungetService(org.osgi.framework.Bundle bundle, org.osgi.framework.ServiceRegistration registration, java.lang.Object service)` The unget method.
`void` `unregisterService()` Withdraws the service from the service registry.
`void` `update()` Update the service properties.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### REGISTERED

    public static final int REGISTERED

Service State : REGISTRED.

See Also:
  Constant Field Values

#### UNREGISTERED

    public static final int UNREGISTERED

Service State : UNREGISTRED.

See Also:
  Constant Field Values

#### SINGLETON_STRATEGY

    public static final int SINGLETON_STRATEGY

Factory Policy : SINGLETON_FACTORY.

See Also:
  Constant Field Values

#### SERVICE_STRATEGY

    public static final int SERVICE_STRATEGY

Factory policy : SERVICE_FACTORY.

See Also:
  Constant Field Values

#### STATIC_STRATEGY

    public static final int STATIC_STRATEGY

Factory policy : STATIC_FACTORY.

See Also:
  Constant Field Values

#### INSTANCE_STRATEGY

    public static final int INSTANCE_STRATEGY

Factory policy : INSTANCE. Creates one service object per instance consuming the service.

See Also:
  Constant Field Values

#### CUSTOM_STRATEGY

    public static final int CUSTOM_STRATEGY

Factory policy : CUSTOMIZED. Custom creation strategy

See Also:
  Constant Field Values

#### ALL_SPECIFICATIONS_FOR_CONTROLLERS

    public static final java.lang.String ALL_SPECIFICATIONS_FOR_CONTROLLERS

See Also:
  Constant Field Values

### Constructor Detail

#### ProvidedService

    public ProvidedService(ProvidedServiceHandler handler,
                           java.lang.String[] specification,
                           int factoryPolicy,
                           java.lang.Class creationStrategyClass,
                           java.util.Dictionary conf)

Creates a provided service object.

Parameters:
  `handler` - the the provided service handler.
  `specification` - the specifications provided by this provided service
  `factoryPolicy` - the service providing policy
  `creationStrategyClass` - the customized service object creation strategy.
  `conf` - the instance configuration.

### Method Detail

#### setProperties

    protected void setProperties(Property[] props)

Add properties to the provided service.

Parameters:
  `props` - : the properties to attached to the service registration

#### getServiceReference

    public org.osgi.framework.ServiceReference getServiceReference()

Get the service reference of the service registration.

Returns:
  the service reference of the provided service (null if the service is not published).

#### getService

    public java.lang.Object getService(org.osgi.framework.Bundle bundle,
                                       org.osgi.framework.ServiceRegistration registration)

Returns a service object for the dependency.

Specified by:
  `getService` in interface `org.osgi.framework.ServiceFactory`
Parameters:
  `bundle` - : the bundle
  `registration` - : the service registration of the registered service
Returns:
  a new service object or a already created service object (in the case of singleton) or `null` if the instance is no more valid.
See Also:
  `ServiceFactory.getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)`

#### ungetService

    public void ungetService(org.osgi.framework.Bundle bundle,
                             org.osgi.framework.ServiceRegistration registration,
                             java.lang.Object service)

The unget method.

Specified by:
  `ungetService` in interface `org.osgi.framework.ServiceFactory`
Parameters:
  `bundle` - : bundle
  `registration` - : service registration
  `service` - : service object
See Also:
  `ServiceFactory.ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)`

#### registerService

    public void registerService()

Registers the service. The service object must be able to serve this service. This method also notifies the creation strategy of the publication.

#### unregisterService

    public void unregisterService()

Withdraws the service from the service registry.

#### getState

    public int getState()

Get the current provided service state.

Returns:
  The state of the provided service.

#### getInstanceManager

    protected InstanceManager getInstanceManager()

#### getProperties

    public Property[] getProperties()

Get the list of properties attached to the service registration.

Returns:
  the properties attached to the provided service.

#### update

    public void update()

Update the service properties. The new list of properties is sent to the service registry.

#### addProperties

    protected void addProperties(java.util.Dictionary props)

Add properties to the list.

Parameters:
  `props` - : properties to add

#### deleteProperties

    protected void deleteProperties(java.util.Dictionary props)

Remove properties from the list.

Parameters:
  `props` - : properties to remove

#### getServiceSpecifications

    public java.lang.String[] getServiceSpecifications()

Get the published service specifications.

Returns:
  the list of provided service specifications (i.e. java interface).

#### getServiceRegistration

    public org.osgi.framework.ServiceRegistration getServiceRegistration()

Get the service registration.

Returns:
  the service registration of this service.

#### setController

    public void setController(java.lang.String field,
                              boolean value,
                              java.lang.String specification)

Sets the service controller on this provided service.

Parameters:
  `field` - the field attached to this controller
  `value` - the value the initial value
  `specification` - the target specification, if `null` affect all specifications.

#### getController

    public org.apache.felix.ipojo.handlers.providedservice.ProvidedService.ServiceController getController(java.lang.String field)

Gets the service controller attached to the given field.

Parameters:
  `field` - the field name
Returns:
  the service controller, `null` if there is no service controller attached to the given field name.

#### getControllerBySpecification

    public org.apache.felix.ipojo.handlers.providedservice.ProvidedService.ServiceController getControllerBySpecification(java.lang.String spec)

Gets the service controller handling the service publishing the given specification.

Parameters:
  `spec` - the specification (qualified class name)
Returns:
  the service controller, `null` if there is no service controller handling the service publishing the given service specification

#### setPostRegistrationCallback

    public void setPostRegistrationCallback(Callback cb)

#### setPostUnregistrationCallback

    public void setPostUnregistrationCallback(Callback cb)

#### getPolicy

    public int getPolicy()

#### getCreationStrategy

    public java.lang.Class<? extends CreationStrategy> getCreationStrategy()

#### addListener

    public void addListener(ProvidedServiceListener listener)

Add the given listener to the provided service handler's list of listeners.

Parameters:
  `listener` - the `ProvidedServiceListener` object to be added
Throws:
  `java.lang.NullPointerException` - if `listener` is `null`

#### removeListener

    public void removeListener(ProvidedServiceListener listener)

Remove the given listener from the provided service handler's list of listeners.

Parameters:
  `listener` - the `ProvidedServiceListener` object to be removed
Throws:
  `java.lang.NullPointerException` - if `listener` is `null`
  `java.util.NoSuchElementException` - if `listener` wasn't present the in provided service handler's list of listeners

#### cleanup

    public void cleanup()

Removes all the listeners from this provided service before it gets disposed.