org.apache.felix.ipojo.handlers.dependency

## Class Dependency

- java.lang.Object
- - org.apache.felix.ipojo.util.DependencyModel
  - - org.apache.felix.ipojo.handlers.dependency.Dependency

All Implemented Interfaces:
  ConstructorInjector, FieldInterceptor, MethodInterceptor

    public class Dependency
    extends DependencyModel
    implements FieldInterceptor, MethodInterceptor, ConstructorInjector

Represent a service dependency of the component instance.

Author:
  Felix Project Team

### Nested Class Summary

### Nested classes/interfaces inherited from class org.apache.felix.ipojo.util.DependencyModel

`DependencyModel.DependencyEventType, DependencyModel.ServiceBindingHolder`

### Field Summary

### Fields inherited from class org.apache.felix.ipojo.util.DependencyModel

`BROKEN, DYNAMIC_BINDING_POLICY, DYNAMIC_PRIORITY_BINDING_POLICY, m_serviceReferenceManager, RESOLVED, STATIC_BINDING_POLICY, UNRESOLVED`

### Constructor Summary

Constructors
Constructor and Description
`Dependency(DependencyHandler handler, java.lang.String field, java.lang.Class spec, org.osgi.framework.Filter filter, boolean isOptional, boolean isAggregate, boolean nullable, boolean isProxy, java.lang.String identity, org.osgi.framework.BundleContext context, int policy, java.util.Comparator cmp, java.lang.String defaultImplementation, java.lang.String exception)` Dependency constructor.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `addConstructorInjection(int index)`
`protected void` `addDependencyCallback(DependencyCallback callback)` Add a callback to the dependency.
`AggregateDependencyInjectionType` `getAggregateType()`
`protected DependencyCallback[]` `getCallbacks()`
`java.lang.Object` `getConstructorParameter(int index)` Gets the object to inject in the constructor parameter.
`int` `getConstructorParameterIndex()` Gets the constructor parameter.
`java.lang.Class` `getConstructorParameterType(int index)` Gets the type of the constructor parameter.
`java.lang.String` `getDefaultImplementation()`
`DependencyCallback[]` `getDependencyCallbacks()` Gets the list of callbacks attached to the current dependency.
`java.lang.String` `getException()`
`java.lang.String` `getField()`
`DependencyHandler` `getHandler()`
`java.lang.String` `getId()` Gets the dependency id.
`java.lang.Object` `getService()` Called by the proxy to get service objects to delegate a method.
`java.util.List<org.osgi.framework.ServiceReference>` `getServiceReferencesAsList()` Get the used service references list.
`int` `getTimeout()`
`boolean` `isFrozen()` Is the reference set frozen (cannot change anymore)? This method must be override by concrete dependency to support the static binding policy.
`boolean` `isProxy()`
`boolean` `isServiceLevelRequirement()`
`void` `onDependencyReconfiguration(org.osgi.framework.ServiceReference[] departs, org.osgi.framework.ServiceReference[] arrivals)` The dependency has been reconfigured.
`void` `onEntry(java.lang.Object pojo, java.lang.reflect.Member method, java.lang.Object[] args)` A POJO method will be invoked.
`void` `onError(java.lang.Object pojo, java.lang.reflect.Member method, java.lang.Throwable throwable)` A POJO method has thrown an error.
`void` `onExit(java.lang.Object pojo, java.lang.reflect.Member method, java.lang.Object returnedObj)` A POJO method has returned.
`void` `onFinally(java.lang.Object pojo, java.lang.reflect.Member method)` A POJO method is finished.
`java.lang.Object` `onGet(java.lang.Object pojo, java.lang.String fieldName, java.lang.Object value)` This method is called by the replaced code in the component implementation class.
`protected void` `onObjectCreation(java.lang.Object pojo)` Call the bind method.
`void` `onServiceArrival(org.osgi.framework.ServiceReference reference)` A new service has to be injected.
`void` `onServiceDeparture(org.osgi.framework.ServiceReference ref)` A used (already injected) service disappears.
`void` `onServiceModification(org.osgi.framework.ServiceReference reference)` An already injected service is modified.
`void` `onSet(java.lang.Object pojo, java.lang.String fieldName, java.lang.Object value)` The field was set.
`void` `resetLocalCache()` Reset the thread local cache if used.
`protected void` `setAggregateType(AggregateDependencyInjectionType type)` Set the type to inject.
`void` `setProxy(boolean proxy)`
`void` `setServiceLevelDependency()` Set that this dependency is a service level dependency.
`void` `setSpecification(java.lang.Class spec)` Set the specification of the current dependency.
`void` `setTimeout(int timeout)` Sets the dependency timeout.
`void` `start()` Start the dependency.
`void` `stop()` Stop the current dependency.
`boolean` `supportsNullable()` Gets true if the dependency use Nullable objects.
`void` `unfreeze()` Unfreeze the dependency.

### Methods inherited from class org.apache.felix.ipojo.util.DependencyModel

`acquireReadLockIfNotHeld, acquireWriteLockIfNotHeld, addListener, applyReconfiguration, cleanup, getBindingPolicy, getBundleContext, getComparator, getComponentInstance, getContextSourceManager, getFilter, getService, getService, getServiceReference, getServiceReferenceManager, getServiceReferences, getSize, getSpecification, getState, getTracker, getUsedServiceReferences, invalidateMatchingServices, invalidateSelectedServices, isAggregate, isOptional, match, notifyListeners, onChange, releaseReadLockIfHeld, releaseWriteLockIfHeld, removeListener, setAggregate, setBundleContext, setComparator, setFilter, setOptionality, ungetService`

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

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

### Constructor Detail

#### Dependency

    public Dependency(DependencyHandler handler,
                      java.lang.String field,
                      java.lang.Class spec,
                      org.osgi.framework.Filter filter,
                      boolean isOptional,
                      boolean isAggregate,
                      boolean nullable,
                      boolean isProxy,
                      java.lang.String identity,
                      org.osgi.framework.BundleContext context,
                      int policy,
                      java.util.Comparator cmp,
                      java.lang.String defaultImplementation,
                      java.lang.String exception)

Dependency constructor. After the creation the dependency is not started.

Parameters:
  `handler` - : the dependency handler managing this dependency
  `field` - : field of the dependency
  `spec` - : required specification
  `filter` - : LDAP filter of the dependency
  `isOptional` - : is the dependency an optional dependency ?
  `isAggregate` - : is the dependency an aggregate dependency
  `nullable` - : describe if the nullable ability is enable or disable
  `isProxy` - : is the proxied dependency
  `identity` - : id of the dependency, may be null
  `context` - : bundle context (or service context) to use.
  `policy` - : resolution policy
  `cmp` - : comparator to sort references
  `defaultImplementation` - : default-implementation class

### Method Detail

#### setSpecification

    public void setSpecification(java.lang.Class spec)

Set the specification of the current dependency. In order to store the id of the dependency, this method is override. This method is called during the configuration.

Overrides:
  `setSpecification` in class `DependencyModel`
Parameters:
  `spec` - : request service Class
See Also:
  `DependencyModel.setSpecification(java.lang.Class)`

#### getField

    public java.lang.String getField()

#### addDependencyCallback

    protected void addDependencyCallback(DependencyCallback callback)

Add a callback to the dependency. This method is called during the configuration.

Parameters:
  `callback` - : callback to add

#### addConstructorInjection

    protected void addConstructorInjection(int index)
                                    throws ConfigurationException

Throws:
  `ConfigurationException`

#### stop

    public void stop()

Stop the current dependency.

Overrides:
  `stop` in class `DependencyModel`
See Also:
  `DependencyModel.stop()`

#### getHandler

    public DependencyHandler getHandler()

#### isFrozen

    public boolean isFrozen()

Description copied from class: `DependencyModel`
Is the reference set frozen (cannot change anymore)? This method must be override by concrete dependency to support the static binding policy. In fact, this method allows optimizing the static dependencies to become frozen only when needed. This method returns `false` by default. The method must always return `false` for non-static dependencies.

Overrides:
  `isFrozen` in class `DependencyModel`
Returns:
  `true` if the reference set is frozen.

#### unfreeze

    public void unfreeze()

Unfreeze the dependency.

Overrides:
  `unfreeze` in class `DependencyModel`
See Also:
  `DependencyModel.unfreeze()`

#### onObjectCreation

    protected void onObjectCreation(java.lang.Object pojo)

Call the bind method.

Parameters:
  `pojo` - : pojo instance on which calling the bind method.

#### start

    public void start()

Start the dependency.

Overrides:
  `start` in class `DependencyModel`
See Also:
  `DependencyModel.computeAndSetDependencyState()`

#### getCallbacks

    protected DependencyCallback[] getCallbacks()

#### setServiceLevelDependency

    public void setServiceLevelDependency()

Set that this dependency is a service level dependency. This forces the scoping policy to be STRICT.

#### getId

    public java.lang.String getId()

Description copied from class: `DependencyModel`
Gets the dependency id.

Overrides:
  `getId` in class `DependencyModel`
Returns:
  the dependency id. Specification name by default.

#### isServiceLevelRequirement

    public boolean isServiceLevelRequirement()

#### onServiceArrival

    public void onServiceArrival(org.osgi.framework.ServiceReference reference)

A new service has to be injected.

Specified by:
  `onServiceArrival` in class `DependencyModel`
Parameters:
  `reference` - : the new matching service reference.
See Also:
  `DependencyModel.onServiceArrival(org.osgi.framework.ServiceReference)`

#### onServiceModification

    public void onServiceModification(org.osgi.framework.ServiceReference reference)

An already injected service is modified.

Specified by:
  `onServiceModification` in class `DependencyModel`
Parameters:
  `reference` - : the modified service reference.
See Also:
  `DependencyModel.onServiceModification(org.osgi.framework.ServiceReference)`

#### onServiceDeparture

    public void onServiceDeparture(org.osgi.framework.ServiceReference ref)

A used (already injected) service disappears.

Specified by:
  `onServiceDeparture` in class `DependencyModel`
Parameters:
  `ref` - : leaving service reference.
See Also:
  `DependencyModel.onServiceDeparture(org.osgi.framework.ServiceReference)`

#### onDependencyReconfiguration

    public void onDependencyReconfiguration(org.osgi.framework.ServiceReference[] departs,
                                            org.osgi.framework.ServiceReference[] arrivals)

The dependency has been reconfigured. Call unbind method and then bind methods. If the dependency cache is not reset, the thread continues to get older services.

Specified by:
  `onDependencyReconfiguration` in class `DependencyModel`
Parameters:
  `departs` - : no more matching services.
  `arrivals` - : new services
See Also:
  `DependencyModel.onDependencyReconfiguration(org.osgi.framework.ServiceReference[], org.osgi.framework.ServiceReference[])`

#### resetLocalCache

    public void resetLocalCache()

Reset the thread local cache if used. For testing purpose only.

#### getServiceReferencesAsList

    public java.util.List<org.osgi.framework.ServiceReference> getServiceReferencesAsList()

Get the used service references list.

Returns:
  the used service reference or null if no service reference are available.

#### getDependencyCallbacks

    public DependencyCallback[] getDependencyCallbacks()

Gets the list of callbacks attached to the current dependency.

Returns:
  the array of dependency callback, `null` if no callbacks are attached to the current dependency.

#### getService

    public java.lang.Object getService()

Called by the proxy to get service objects to delegate a method. On aggregate dependencies, it returns a list.

Returns:
  a service object or a nullable/default-implementation object. For aggregate dependencies it returns a list or an empty list.

#### onGet

    public java.lang.Object onGet(java.lang.Object pojo,
                                  java.lang.String fieldName,
                                  java.lang.Object value)

This method is called by the replaced code in the component implementation class. Construct the service object list is necessary.

Specified by:
  `onGet` in interface `FieldInterceptor`
Parameters:
  `pojo` - : POJO object.
  `fieldName` - : field
  `value` - : last value.
Returns:
  the service object or a nullable / default implementation if defined.
See Also:
  `FieldInterceptor.onGet(java.lang.Object, java.lang.String, java.lang.Object)`

#### onSet

    public void onSet(java.lang.Object pojo,
                      java.lang.String fieldName,
                      java.lang.Object value)

The field was set. This method should not be call if the POJO is written correctly.

Specified by:
  `onSet` in interface `FieldInterceptor`
Parameters:
  `pojo` - : POJO object
  `fieldName` - : field name
  `value` - : set value.
See Also:
  `FieldInterceptor.onSet(java.lang.Object, java.lang.String, java.lang.Object)`

#### onEntry

    public void onEntry(java.lang.Object pojo,
                        java.lang.reflect.Member method,
                        java.lang.Object[] args)

A POJO method will be invoked.

Specified by:
  `onEntry` in interface `MethodInterceptor`
Parameters:
  `pojo` - : Pojo object
  `method` - : called method
  `args` - : arguments
See Also:
  `MethodInterceptor.onEntry(java.lang.Object, java.lang.reflect.Member, java.lang.Object[])`

#### onError

    public void onError(java.lang.Object pojo,
                        java.lang.reflect.Member method,
                        java.lang.Throwable throwable)

A POJO method has thrown an error. This method does nothing and wait for the finally.

Specified by:
  `onError` in interface `MethodInterceptor`
Parameters:
  `pojo` - : POJO object.
  `method` - : Method object.
  `throwable` - : thrown error
See Also:
  `MethodInterceptor.onError(java.lang.Object, java.lang.reflect.Member, java.lang.Throwable)`

#### onExit

    public void onExit(java.lang.Object pojo,
                       java.lang.reflect.Member method,
                       java.lang.Object returnedObj)

A POJO method has returned.

Specified by:
  `onExit` in interface `MethodInterceptor`
Parameters:
  `pojo` - : POJO object.
  `method` - : Method object.
  `returnedObj` - : returned object (null for void method)
See Also:
  `MethodInterceptor.onExit(java.lang.Object, java.lang.reflect.Member, java.lang.Object)`

#### onFinally

    public void onFinally(java.lang.Object pojo,
                          java.lang.reflect.Member method)

A POJO method is finished.

Specified by:
  `onFinally` in interface `MethodInterceptor`
Parameters:
  `pojo` - : POJO object.
  `method` - : Method object.
See Also:
  `MethodInterceptor.onFinally(java.lang.Object, java.lang.reflect.Member)`

#### supportsNullable

    public boolean supportsNullable()

Gets true if the dependency use Nullable objects.

Returns:
  true if the dependency is optional and supports nullable objects.

#### getDefaultImplementation

    public java.lang.String getDefaultImplementation()

#### isProxy

    public boolean isProxy()

#### setProxy

    public void setProxy(boolean proxy)

#### setAggregateType

    protected void setAggregateType(AggregateDependencyInjectionType type)

Set the type to inject. This method set the dependency as aggregate.

Parameters:
  `type` - the type to inject.

#### setTimeout

    public void setTimeout(int timeout)

Sets the dependency timeout.

Parameters:
  `timeout` - the timeout in ms.

#### getConstructorParameterIndex

    public int getConstructorParameterIndex()

Gets the constructor parameter.

Returns:
  the index of the constructor parameter, or `-1` if not set.

#### getConstructorParameter

    public java.lang.Object getConstructorParameter(int index)

Gets the object to inject in the constructor parameter.

Specified by:
  `getConstructorParameter` in interface `ConstructorInjector`
Parameters:
  `index` - the index of the parameter
Returns:
  the created proxy object
See Also:
  `ConstructorInjector.getConstructorParameter(int)`

#### getConstructorParameterType

    public java.lang.Class getConstructorParameterType(int index)

Gets the type of the constructor parameter.

Specified by:
  `getConstructorParameterType` in interface `ConstructorInjector`
Parameters:
  `index` - the parameter index
Returns:
  the class of the object. For scalar dependency, it's the specification, for aggregate it depends of the container object: `List` or `Set`.
See Also:
  `ConstructorInjector.getConstructorParameterType(int)`

#### getException

    public java.lang.String getException()

#### getTimeout

    public int getTimeout()

#### getAggregateType

    public AggregateDependencyInjectionType getAggregateType()