You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bu...@apache.org on 2014/09/08 16:50:56 UTC

svn commit: r921603 - in /websites/staging/sling/trunk/content: ./ documentation/bundles/models.html

Author: buildbot
Date: Mon Sep  8 14:50:56 2014
New Revision: 921603

Log:
Staging update by buildbot for sling

Modified:
    websites/staging/sling/trunk/content/   (props changed)
    websites/staging/sling/trunk/content/documentation/bundles/models.html

Propchange: websites/staging/sling/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Mon Sep  8 14:50:56 2014
@@ -1 +1 @@
-1623399
+1623417

Modified: websites/staging/sling/trunk/content/documentation/bundles/models.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/bundles/models.html (original)
+++ websites/staging/sling/trunk/content/documentation/bundles/models.html Mon Sep  8 14:50:56 2014
@@ -103,6 +103,7 @@
 <li><a href="#custom-annotations">Custom Annotations</a></li>
 </ul>
 </li>
+<li><a href="#specifying-an-alternate-adapter-class-since-sling-model-110">Specifying an Alternate Adapter Class (Since Sling Model 1.1.0)</a></li>
 </ul>
 </div>
 <p>Many Sling projects want to be able to create model objects - POJOs which are automatically mapped from Sling objects, typically resources, but also request objects. Sometimes these POJOs need OSGi services as well.</p>
@@ -573,8 +574,29 @@ the following advantages over using the 
 <p>To create a custom annotation, implement the <code>org.apache.sling.models.spi.injectorspecific.InjectAnnotationProcessorFactory</code> interface.
 This interface may be implemented by the same class as implements an injector, but this is not strictly necessary. Please refer to the
 injectors in <a href="http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/injectors/">Subversion</a> for examples.</p>
+<h1 id="specifying-an-alternate-adapter-class-since-sling-model-110">Specifying an Alternate Adapter Class (Since Sling Model 1.1.0)</h1>
+<p>By default, each model class is registered using its own implementation class as adapter. If the class has additional interfaces this is not relevant.</p>
+<p>The <code>@Model</code> annotations provides an optional <code>adapters</code> attribute which allows specifying under which type(s) the model
+implementation should be registered in the Models Adapter Factory. With this property it is possible to register the model
+to one (or multiple) interfaces, or a superclass. This allows separating the model interface from the implementation, which
+makes it easier to provide mock implementations for unit tests as well.</p>
+<p>Example:</p>
+<div class="codehilite"><pre><span class="nd">@Model</span><span class="o">(</span><span class="n">adaptables</span> <span class="o">=</span> <span class="n">Resource</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="n">adapters</span> <span class="o">=</span> <span class="n">MyService</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
+<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyModel</span> <span class="kd">implements</span> <span class="n">MyService</span> <span class="o">{</span>
+    <span class="c1">// injects fields and implements the MyService methods</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>In this example a <code>Resource</code> can be adapted to a <code>MyService</code> interface, and the Sling Models implementation instantiates a
+<code>MyModel</code> class for this.</p>
+<p>It is possible to have multiple models implementing the same interface. By default Sling Models will just take the first one
+ordered alphabetically by the class name. Applications can provide an OSGi service implementing the <code>ImplementationPicker</code>
+SPI interface which could use context to determine which implementation can be chosen, e.g. depending an a tenant or
+content path context. If multiple implementations of the <code>ImplementationPicker</code> interface are present, they are queried
+one after another in order of their service ranking property, the first one that picks an implementation wins.</p>
       <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
-        Rev. 1622790 by justin on Fri, 5 Sep 2014 20:32:39 +0000
+        Rev. 1623417 by justin on Mon, 8 Sep 2014 14:50:50 +0000
       </div>
       <div class="trademarkFooter"> 
         Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project