Adding interceptors is a common technique to implement
non-functional aspects such as security. The ServiceBinder supports the
addition of interceptors that sit between component instances. The
addition of an interceptor for a particular component instance can be
done either at the providing side or at the requiring side.
The GenericActivator provides two methods methods to insert the
interceptors, these methods need to be redefined in the subclass of the
GenericActivator to add the interceptors (otherwise this is not
necessary). It is interesting to note
that since these methods are located inside the activator, they can
access the service registry, so that it is possible to use OSGi
services to implement the non-functional capabilities.
The methods that can must be overloaded to insert interceptors are the following:
protected Object proxyProvidedServiceObject(Object obj, InstanceMetadata metadata)
protected Object proxyRequiredServiceObject(Object obj, DependencyMetadata metadata)
The first parameter of both methods contains the object to which a proxy will be added.
The first method is called right after the component instance is created. The InstanceMetadata passed as a parameter provides the information about the component found on the descriptor file.
The second method is called right before an invocation to a bind
method
takes place. The DependencyMetadata passed as a
parameter
contains information about the dependency such as the filter and the
name of the service.
Next : Factories and scopes
Previous : The component implementation class