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:
ConstructorInjector, FieldInterceptor, MethodInterceptor, TrackerCustomizer

public class Dependency
extends DependencyModel
implements FieldInterceptor, MethodInterceptor, ConstructorInjector

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, String field, Class spec, Filter filter, boolean isOptional, boolean isAggregate, boolean nullable, boolean isProxy, String identity, BundleContext context, int policy, Comparator cmp, String defaultImplem)
          Dependency constructor.
 
Method Summary
protected  void addConstructorInjection(int index)
           
protected  void addDependencyCallback(DependencyCallback callback)
          Add a callback to the dependency.
protected  DependencyCallback[] getCallbacks()
           
 Object getConstructorParameter(int index)
          Gets the object to inject in the constructor parameter.
 int getConstructorParameterIndex()
          Gets the constructor parameter.
 Class getConstructorParameterType(int index)
          Gets the type of the constructor parameter.
 String getDefaultImplementation()
           
 String getField()
           
 DependencyHandler getHandler()
           
 String getId()
           
 Object getService()
          Called by the proxy to get service objects to delegate a method.
 List getServiceReferencesAsList()
          Get the used service references list.
 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(ServiceReference[] departs, ServiceReference[] arrivals)
          The dependency has been reconfigured.
 void onEntry(Object pojo, Method method, Object[] args)
          A POJO method will be invoked.
 void onError(Object pojo, Method method, Throwable throwable)
          A POJO method has thrown an error.
 void onExit(Object pojo, Method method, Object returnedObj)
          A POJO method has returned.
 void onFinally(Object pojo, Method method)
          A POJO method is finished.
 Object onGet(Object pojo, String fieldName, Object value)
          This method is called by the replaced code in the component implementation class.
protected  void onObjectCreation(Object pojo)
          Call the bind method.
 void onServiceArrival(ServiceReference reference)
          A new service has to be injected.
 void onServiceDeparture(ServiceReference ref)
          A used (already injected) service disappears.
 void onServiceModification(ServiceReference reference)
          An already injected service is modified.
 void onSet(Object pojo, String fieldName, Object value)
          The field was set.
 void resetLocalCache()
          Reset the thread local cache if used.
 void setProxy(boolean proxy)
           
 void setServiceLevelDependency()
          Set that this dependency is a service level dependency.
 void setSpecification(Class spec)
          Set the specification of the current dependency.
protected  void setType(int type)
          Set the type to inject.
 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
addedService, addingService, getBindingPolicy, getComparator, getComparator, getFilter, getPolicy, getService, getServiceReference, getServiceReferences, getSize, getSpecification, getState, getUsedServiceReferences, isAggregate, isOptional, loadSpecification, manageModification, match, modifiedService, 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,
                  String field,
                  Class spec,
                  Filter filter,
                  boolean isOptional,
                  boolean isAggregate,
                  boolean nullable,
                  boolean isProxy,
                  String identity,
                  BundleContext context,
                  int policy,
                  Comparator cmp,
                  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
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
defaultImplem - : default-implementation class
Method Detail

setSpecification

public void setSpecification(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 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(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.computeDependencyState()

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

isServiceLevelRequirement

public boolean isServiceLevelRequirement()

onServiceArrival

public void onServiceArrival(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(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(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(ServiceReference[] departs,
                                        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.


getServiceReferencesAsList

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

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

getService

public 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 Object onGet(Object pojo,
                    String fieldName,
                    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(Object pojo,
                  String fieldName,
                  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(Object pojo,
                    Method method,
                    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(Object pojo,
                    Method method,
                    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(Object pojo,
                   Method method,
                   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(Object pojo,
                      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)

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

isProxy

public boolean isProxy()

setProxy

public void setProxy(boolean proxy)

setType

protected void setType(int type)
Set the type to inject. This method set the dependency as aggregate.

Parameters:
type - either list of vector

getConstructorParameterIndex

public int getConstructorParameterIndex()
Gets the constructor parameter.

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

getConstructorParameter

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


Copyright © 2011 Apache Software Foundation. All Rights Reserved.