org.apache.felix.dm.annotation.api
Annotation Type AspectService


@Retention(value=CLASS)
@Target(value=TYPE)
public @interface AspectService

Annotates an Aspect service. Aspects allow you to define an interceptor, or chain of interceptors for a service (to add features like caching or logging, etc ...). The dependency manager intercepts the original service, and allows you to execute some code before invoking the original service ... The aspect will be applied to any service that matches the specified interface and filter and will be registered with the same interface and properties as the original service, plus any extra properties you supply here. It will also inherit all dependencies, and if you declare the original service as a member it will be injected.

Usage Examples

Here, the AspectService is registered into the OSGI registry each time an InterceptedService is found from the registry. The AspectService class intercepts the InterceptedService, and decorates its "doWork()" method. This aspect uses a rank with value "10", meaning that it will intercept some other eventual aspects with lower ranks. The Aspect also uses a service property (param=value), and include eventual service properties found from the InterceptedService:

 
 @AspectService(ranking=10), properties={@Property(name="param", value="value")})
 class AspectService implements InterceptedService {
     // The service we are intercepting (injected by reflection)
     protected InterceptedService intercepted;
   
     public void doWork() {
        intercepted.doWork();
     }
 }
 


Required Element Summary
 int ranking
          Sets the ranking of this aspect.
 
Optional Element Summary
 String factoryMethod
          Sets the static method used to create the AspectService implementation instance.
 String field
          Sets the field name where to inject the original service.
 String filter
          Sets the filter condition to use with the service interface this aspect is applying to.
 Property[] properties
          Sets Additional properties to use with the aspect service registration
 Class<?> service
          Sets the service interface to apply the aspect to.
 

Element Detail

ranking

public abstract int ranking
Sets the ranking of this aspect. Since aspects are chained, the ranking defines the order in which they are chained. Chain ranking is implemented as a service ranking so service lookups automatically retrieve the top of the chain.

service

public abstract Class<?> service
Sets the service interface to apply the aspect to. By default, the directly implemented interface is used.

Default:
java.lang.Object.class

filter

public abstract String filter
Sets the filter condition to use with the service interface this aspect is applying to.

Default:
""

properties

public abstract Property[] properties
Sets Additional properties to use with the aspect service registration

Default:
{}

field

public abstract String field
Sets the field name where to inject the original service. By default, the original service is injected in any attributes in the aspect implementation that are of the same type as the aspect interface.

Default:
""

factoryMethod

public abstract String factoryMethod
Sets the static method used to create the AspectService implementation instance. The default constructor of the annotated class is used. The factoryMethod can be used to provide a specific aspect implements, like a DynamicProxy.

Default:
""


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.