@Retention(value=CLASS)
@Target(value=TYPE)
public @interface AdapterService
AspectService
, 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 annotate an adapter class with the @AdapterService
annotation, 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.
For "add", "change", "remove" callbacks, the following method signatures are supported:
(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)
Here, the AdapterService is registered into the OSGI registry each time an AdapteeService is found from the registry. The AdapterImpl class adapts the AdapteeService to the AdapterService. The AdapterService will also have a service property (param=value), and will also include eventual service properties found from the AdapteeService:
@AdapterService(adapteeService = AdapteeService.class) @Property(name="param", value="value") class AdapterImpl implements AdapterService { // The service we are adapting (injected by reflection) protected AdapteeService adaptee; public void doWork() { adaptee.mehod1(); adaptee.method2(); } }
Modifier and Type | Required Element and Description |
---|---|
java.lang.Class<?> |
adapteeService
Sets the adaptee service interface this adapter is applying to.
|
Modifier and Type | Optional Element and Description |
---|---|
java.lang.String |
adapteeFilter
Sets the filter condition to use with the adapted service interface.
|
java.lang.String |
added
The callback method to be invoked when the original service is available.
|
java.lang.String |
changed
The callback method to be invoked when the original service properties have changed.
|
java.lang.String |
factoryMethod
Sets the static method used to create the adapter service implementation instance.
|
java.lang.String |
field
Sets the field name where to inject the original service.
|
boolean |
propagate
Specifies if adaptee service properties should be propagated to the adapter service.
|
Property[] |
properties
Sets some additional properties to use with the adapter service registration.
|
java.lang.Class<?>[] |
provides
Sets the adapter service interface(s).
|
java.lang.String |
removed
The callback method to invoke when the service is lost.
|
java.lang.String |
swap
name of the callback method to invoke on swap.
|
public abstract java.lang.Class<?> adapteeService
public abstract java.lang.Class<?>[] provides
public abstract Property[] properties
public abstract java.lang.String adapteeFilter
public abstract java.lang.String factoryMethod
public abstract java.lang.String field
public abstract java.lang.String added
public abstract java.lang.String changed
public abstract java.lang.String swap