Apache
Home » Documentation » Apache Felix Maven SCR Plugin

Extending SCR Annotations

Note: This page documents functionality available with the SCR Generator 1.0.0 release providing the declaration file generation mechanism for the Maven SCR Plugin 1.6.0 (and newer) and the SCR Ant Task 1.0.0 (and newer).

The SCR Annotations library has been updated in version 1.4.0 to comply with the rules described here. As such this library may be used as basis to learn more about providing pluggbale Java 5 annotations for the Maven SCR Plugin and SCR Ant Task. The source code for the SCR Annotations library is available from the Apache Felix SVN repository at annotations.

This page outlines the required steps to implement your own extended Java 5 annotations:

  1. Define the Annotations
  2. Define an AnnotationTagProvider
  3. Register the AnnotationsTagProvider

It is interesting to note, that the SCR Annotations 1.4.0 library providing the default and Sling Java 5 tags for the SCR Generator by itself is already implemented according to the rules outlined herein. This means, that actually the SCR Generator does not have any built-in annotations but only provides the framework to allow for the definition of Java 5 Annotations.

Define the Annotations

To start with you will define Java 5 Annotations to suit your application needs. The org.apache.felix.scr.annotations.sling package provides three sample annotations:

These annotations will be used to annotate classes for use with Declarative Services.

It is suggested to maintain the annotations in a separate package or even in a separate module that your projects may depend upon.

Define an AnnotationProcessor

The AnnotationProcessor interface defines the interface of a helper class which is used to convert Java 5 Annotation data into internal data structures to be then used as the basis for the generation of the descriptor files.

Implementations of this interface are provided with the ScannedClass instances and are expected to augment the provided ClassDescription.

The SlingAnnotationProcessor class implements the AnnotationProcessorto handle the Sling annotations described above.

Register the AnnotationProcessor

To finally make the AnnotationProcessor implementations available to the SCR Generator (and thus the Maven SCR Plugin and/or SCR Ant Task) the fully qualified class names of these implementations must be listed in an META-INF/services/org.apache.felix.scrplugin.annotations.AnnotationProcessor file in the library providing the annotations.

The classes listed in this file will automatically be picked up by the SCR Generator from the library placed on the build class path and thus enable support for the respective annotations.

Again, refer to the actual implementation in the SCR Annotations library referred to above.

Rev. 1438983 by fmeschbe on Sat, 26 Jan 2013 22:54:42 +0000
Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.