org.apache.felix.ipojo.handlers.dependency
Class Dependency

java.lang.Object
  extended by org.apache.felix.ipojo.util.DependencyModel
      extended by org.apache.felix.ipojo.handlers.dependency.Dependency
All Implemented Interfaces:
FieldInterceptor, MethodInterceptor, TrackerCustomizer

public class Dependency
extends DependencyModel
implements FieldInterceptor, MethodInterceptor

Represent a service dependency of the component instance.

Author:
Felix Project Team

Field Summary
 
Fields inherited from class org.apache.felix.ipojo.util.DependencyModel
BROKEN, DYNAMIC_BINDING_POLICY, DYNAMIC_PRIORITY_BINDING_POLICY, RESOLVED, STATIC_BINDING_POLICY, UNRESOLVED
 
Constructor Summary
Dependency(DependencyHandler handler, java.lang.String field, java.lang.Class spec, org.osgi.framework.Filter filter, boolean isOptional, boolean isAggregate, boolean nullable, java.lang.String identity, org.osgi.framework.BundleContext context, int policy, java.util.Comparator cmp, java.lang.String defaultImplem)
          Dependency constructor.
 
Method Summary
protected  void addDependencyCallback(DependencyCallback callback)
          Add a callback to the dependency.
protected  DependencyCallback[] getCallbacks()
           
 java.lang.String getField()
           
 DependencyHandler getHandler()
           
 java.lang.String getId()
           
 java.util.List getServiceReferencesAsList()
          Get the used service references list.
 java.lang.String getStringFilter()
          Get the string form of the filter.
 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 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.Method method, java.lang.Object[] args)
          A POJO method will be invoked.
 void onError(java.lang.Object pojo, java.lang.reflect.Method method, java.lang.Throwable throwable)
          A POJO method has thrown an error.
 void onExit(java.lang.Object pojo, java.lang.reflect.Method method, java.lang.Object returnedObj)
          A POJO method has returned.
 void onFinally(java.lang.Object pojo, java.lang.reflect.Method 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 onSet(java.lang.Object pojo, java.lang.String fieldName, java.lang.Object value)
          The field was set.
 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 start()
          Start the dependency.
 void stop()
          Stop the current dependency.
 
Methods inherited from class org.apache.felix.ipojo.util.DependencyModel
addedService, addingService, getBindingPolicy, getComparator, getFilter, getPolicy, getService, getServiceReference, getServiceReferences, getSize, getSpecification, getState, getUsedServiceReferences, isAggregate, isOptional, loadSpecification, match, modifiedService, onServiceModification, removedService, setAggregate, setBindingPolicy, 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,
                  java.lang.String identity,
                  org.osgi.framework.BundleContext context,
                  int policy,
                  java.util.Comparator cmp,
                  java.lang.String defaultImplem)
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
identity - : id of the dependency, may be null
context - : bundle context (or service context) to use.
policy - : resolution policy
cmp - : comparator to sort references
defaultImplem - : 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.

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.

Parameters:
callback - : callback to add

stop

public void stop()
Stop the current dependency.

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

getStringFilter

public java.lang.String getStringFilter()
Get the string form of the filter.

Returns:
: the string form of the filter.

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. This method is just used by default. The method must always return false for non-static dependency.

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

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

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()

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)

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.

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

getServiceReferencesAsList

public java.util.List getServiceReferencesAsList()
Get the used service references list.

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

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.Method 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.Method, java.lang.Object[])

onError

public void onError(java.lang.Object pojo,
                    java.lang.reflect.Method 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.Method, java.lang.Throwable)

onExit

public void onExit(java.lang.Object pojo,
                   java.lang.reflect.Method 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.Method, java.lang.Object)

onFinally

public void onFinally(java.lang.Object pojo,
                      java.lang.reflect.Method 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.Method)