public interface AdapterComponent extends Component<AdapterComponent>
AspectComponent
, are used to "extend"
existing services, and can publish different services based on the existing one.
An example would be implementing a management interface for an existing service, etc ....
When you create an adapter component, it will be applied to any service that matches the implemented interface and filter. The adapter will be registered with the specified interface and existing properties from the original service plus any extra properties you supply here. If you declare the original service as a member it will be injected.
public class Activator extends DependencyActivatorBase { &Override public void init(BundleContext context, DependencyManager dm) throws Exception { Component adapterComponent = createAdapterComponent() .setAdaptee(HelloService.class, "(foo=bar)") .setInterface(HttpServlet.class.getName(), null) .setImplementation(HelloServlet.class); dm.add(adapterComponent); } } public interface HelloService { String sayHello(); } public class HelloServlet extends HttpServlet { volatile HelloService adatpee; // injected void doGet(HttpServletRequest req, HttpServletResponse resp) { ... resp.getWriter().println(adaptee.sayHello()); } }
When you use callbacks to get injected with the adaptee service, the "add", "change", "remove" callbacks support the following method signatures:
(Component comp, ServiceReference ref, Service service)
(Component comp, ServiceReference ref, Object service)
(Component comp, ServiceReference ref)
(Component comp, Service service)
(Component comp, Object service)
(Component comp)
(Component comp, Map properties, Service service)
(ServiceReference ref, Service service)
(ServiceReference ref, Object service)
(ServiceReference ref)
(Service service)
(Service service, Map propeerties)
(Map properties, Service, service)
(Service service, Dictionary properties)
(Dictionary properties, Service service)
(Object service)
For "swap" callbacks, the following method signatures are supported:
(Service old, Service replace)
(Object old, Object replace)
(ServiceReference old, Service old, ServiceReference replace, Service replace)
(ServiceReference old, Object old, ServiceReference replace, Object replace)
(Component comp, Service old, Service replace)
(Component comp, Object old, Object replace)
(Component comp, ServiceReference old, Service old, ServiceReference replace, Service replace)
(Component comp, ServiceReference old, Object old, ServiceReference replace, Object replace)
(ServiceReference old, ServiceReference replace)
(Component comp, ServiceReference old, ServiceReference replace)
Component.ServiceScope
Modifier and Type | Method and Description |
---|---|
AdapterComponent |
setAdaptee(java.lang.Class<?> service,
java.lang.String filter)
Sets the service interface to apply the adapter to
|
AdapterComponent |
setAdapteeCallbackInstance(java.lang.Object callbackInstance)
Sets the instance to invoke the callbacks on (null by default, meaning the callbacks have to be invoked on the adapter itself)
|
AdapterComponent |
setAdapteeCallbacks(java.lang.String add,
java.lang.String change,
java.lang.String remove,
java.lang.String swap)
Sets the callbacks to invoke when injecting the adaptee service into the adapter component.
|
AdapterComponent |
setAdapteeField(java.lang.String autoConfig)
Sets the name of the member to inject the service into
|
AdapterComponent |
setPropagate(boolean propagate)
Sets if the adaptee service properties should be propagated to the adapter service consumer (true by default)
|
add, add, getServiceRegistration, remove, remove, setAutoConfig, setAutoConfig, setCallbacks, setCallbacks, setComposition, setComposition, setDebug, setFactory, setFactory, setImplementation, setInterface, setInterface, setInterface, setInterface, setScope, setServiceProperties
getComponentDeclaration, getDependencyManager, getInstance, getInstances, getServiceProperties
AdapterComponent setAdaptee(java.lang.Class<?> service, java.lang.String filter)
service
- the service interface to apply the adapter tofilter
- the filter condition to use with the service interfaceAdapterComponent setAdapteeField(java.lang.String autoConfig)
autoConfig
- the name of the member to inject the service intoAdapterComponent setAdapteeCallbacks(java.lang.String add, java.lang.String change, java.lang.String remove, java.lang.String swap)
add
- name of the callback method to invoke on addchange
- name of the callback method to invoke on changeremove
- name of the callback method to invoke on removeswap
- name of the callback method to invoke on swapAdapterComponent setAdapteeCallbackInstance(java.lang.Object callbackInstance)
callbackInstance
- the instance to invoke the callbacks on (null by default, meaning the callbacks have to be invoked on the adapter itself)AdapterComponent setPropagate(boolean propagate)
propagate
- true if the adaptee service properties should be propagated to the adapter service consumers.
The provided adapter service properties take precedence over the propagated adaptee service properties.
It means an adaptee service property won't override an adapter service property having the same name.