felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Felix > Extending SCR Annotations
Date Tue, 09 Nov 2010 13:44:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=FELIX&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/FELIX/Extending+SCR+Annotations">Extending
SCR Annotations</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~fmeschbe">Felix
Meschberger</a>
    </h4>
        <br/>
                         <h4>Changes (6)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-added-lines" style="background-color: #dfd;">*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). <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">{info}</span>
<span class="diff-added-words"style="background-color: #dfd;"> </span> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">This
page is to document how the existing SCR Annotations may be extended to define custom annotations
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">The
SCR Annotations library has been updated in version 1.4.0 to comply with the rules described
here. As such the 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|http://svn.apache.org/repos/asf/felix/trunk/scrplugin/annotations].
<br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">{info}</span>
<span class="diff-added-words"style="background-color: #dfd;"> </span> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">This
page outlines the required steps to implement your own extended Java 5 annotations: <br>
<br> # Define the Annotations <br> # Define an {{AnnotationTagProvider}} <br>
# Register the {{AnnotationsTagProvider}} <br> <br>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. <br> <br> <br>h2.
Define the Annotations <br> <br>To start with you will define Java 5 Annotations
to suit your application needs. The [{{org.apache.felix.scr.annotations.sling}}|http://svn.apache.org/repos/asf/felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/sling]
package provides three sample annotations: <br> <br>* {{SlingServlet}} -- used
to declare a {{javax.servlet.Servlet}} service component with the appropriate service registration
properties to configure the service as an Apache Sling Servlet. <br>* {{SlingFilter}}
-- used to declare a {{javax.servlet.Filter}} service component with the appropriate service
registration properties to configure the service as a Filter used by the Apache Sling Main
Servlet. <br>* {{SlingFilterScope}} -- helper annotation to define the {{filter.scope}}
service registration property for Filters defined with the {{SlingFilter}} annotation. <br>
<br>These annotations will be used by the application programmer to annotate his/her
classes for use with Declarative Services. <br> <br>It is suggested to maintain
the Anntoations in their own package. <br> <br> <br>h2. Define an {{AnnotationTagProvider}}
<br> <br>The [{{AnnotationTagProvider}}|http://svn.apache.org/repos/asf/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProvider.java]
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. <br> <br>Implementations of this interface are fed with the
annotations and are expected to return a list of objects representing the actual information
to be processed into the descriptor files. If a processor does not understand a particular
annotations an empty list is just returned. <br> <br>The objects returned by the
{{AnnotationTagProvider}} must implement the [{{JavaTag}}|http://svn.apache.org/repos/asf/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/JavaTag.java]
interface. To ease the implementation the [{{AbstractTag}}|http://svn.apache.org/repos/asf/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/AbstractTag.java]
may be used as a base class. <br> <br>The [{{org.apache.felix.scrplugin.tags.annotation.sling}}|http://svn.apache.org/repos/asf/felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotations/sling]
package contains the {{AnnotationTagProvider}} supporting Sling Annotations mentioned above
as well as corresponding {{JavaTag}} implementations (mostly extending from {{AbstractTag}}).
<br> <br> <br>h2. Register the {{AnnotationsTagProvider}} <br> <br>To
finally make the {{AnnotationTagProvider}} 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.tags.annotation.AnnotationTagProvider}}|http://svn.apache.org/repos/asf/felix/trunk/scrplugin/annotations/src/main/resources/META-INF/services/org.apache.felix.scrplugin.tags.annotation.AnnotationTagProvider]
file. <br> <br>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. <br> <br>Again, refer to the actual implementation
in the SCR Annotations library referred to above. <br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p><b>Note:</b> 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).</p>

<p>The SCR Annotations library has been updated in version 1.4.0 to comply with the
rules described here. As such the 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 <a href="http://svn.apache.org/repos/asf/felix/trunk/scrplugin/annotations"
class="external-link" rel="nofollow">annotations</a>.</p>

<p>This page outlines the required steps to implement your own extended Java 5 annotations:</p>

<ol>
	<li>Define the Annotations</li>
	<li>Define an <tt>AnnotationTagProvider</tt></li>
	<li>Register the <tt>AnnotationsTagProvider</tt></li>
</ol>


<p>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.</p>


<h2><a name="ExtendingSCRAnnotations-DefinetheAnnotations"></a>Define the
Annotations</h2>

<p>To start with you will define Java 5 Annotations to suit your application needs.
The <a href="http://svn.apache.org/repos/asf/felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/sling"
class="external-link" rel="nofollow"><tt>org.apache.felix.scr.annotations.sling</tt></a>
package provides three sample annotations:</p>

<ul>
	<li><tt>SlingServlet</tt> &#8211; used to declare a <tt>javax.servlet.Servlet</tt>
service component with the appropriate service registration properties to configure the service
as an Apache Sling Servlet.</li>
	<li><tt>SlingFilter</tt> &#8211; used to declare a <tt>javax.servlet.Filter</tt>
service component with the appropriate service registration properties to configure the service
as a Filter used by the Apache Sling Main Servlet.</li>
	<li><tt>SlingFilterScope</tt> &#8211; helper annotation to define the
<tt>filter.scope</tt> service registration property for Filters defined with the
<tt>SlingFilter</tt> annotation.</li>
</ul>


<p>These annotations will be used by the application programmer to annotate his/her
classes for use with Declarative Services.</p>

<p>It is suggested to maintain the Anntoations in their own package.</p>


<h2><a name="ExtendingSCRAnnotations-Definean%7B%7BAnnotationTagProvider%7D%7D"></a>Define
an <tt>AnnotationTagProvider</tt></h2>

<p>The <a href="http://svn.apache.org/repos/asf/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProvider.java"
class="external-link" rel="nofollow"><tt>AnnotationTagProvider</tt></a>
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.</p>

<p>Implementations of this interface are fed with the annotations and are expected to
return a list of objects representing the actual information to be processed into the descriptor
files. If a processor does not understand a particular annotations an empty list is just returned.</p>

<p>The objects returned by the <tt>AnnotationTagProvider</tt> must implement
the <a href="http://svn.apache.org/repos/asf/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/JavaTag.java"
class="external-link" rel="nofollow"><tt>JavaTag</tt></a> interface.
To ease the implementation the <a href="http://svn.apache.org/repos/asf/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/AbstractTag.java"
class="external-link" rel="nofollow"><tt>AbstractTag</tt></a> may be
used as a base class.</p>

<p>The <a href="http://svn.apache.org/repos/asf/felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotations/sling"
class="external-link" rel="nofollow"><tt>org.apache.felix.scrplugin.tags.annotation.sling</tt></a>
package contains the <tt>AnnotationTagProvider</tt> supporting Sling Annotations
mentioned above as well as corresponding <tt>JavaTag</tt> implementations (mostly
extending from <tt>AbstractTag</tt>).</p>


<h2><a name="ExtendingSCRAnnotations-Registerthe%7B%7BAnnotationsTagProvider%7D%7D"></a>Register
the <tt>AnnotationsTagProvider</tt></h2>

<p>To finally make the <tt>AnnotationTagProvider</tt> 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 <a href="http://svn.apache.org/repos/asf/felix/trunk/scrplugin/annotations/src/main/resources/META-INF/services/org.apache.felix.scrplugin.tags.annotation.AnnotationTagProvider"
class="external-link" rel="nofollow"><tt>META-INF/services/org.apache.felix.scrplugin.tags.annotation.AnnotationTagProvider</tt></a>
file.</p>

<p>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.</p>

<p>Again, refer to the actual implementation in the SCR Annotations library referred
to above.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/FELIX/Extending+SCR+Annotations">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=24185817&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/FELIX/Extending+SCR+Annotations?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message