You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:55:36 UTC

[sling-org-apache-sling-models-api] 09/13: SLING-5992 - Introduce resource type to model class binding

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.models.api-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-api.git

commit d327166a05e50a053a5e580b5ab51df66289a5ab
Author: Justin Edelson <ju...@apache.org>
AuthorDate: Wed Aug 31 13:24:44 2016 +0000

    SLING-5992 - Introduce resource type to model class binding
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/models/api@1758602 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            | 12 +++++-
 .../org/apache/sling/models/annotations/Model.java |  6 +++
 .../sling/models/annotations/package-info.java     |  2 +-
 .../apache/sling/models/factory/ModelFactory.java  | 49 ++++++++++++++++++++++
 .../apache/sling/models/factory/package-info.java  |  2 +-
 5 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index 29efce4..ad3e531 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
     
     <artifactId>org.apache.sling.models.api</artifactId>
     <packaging>bundle</packaging>
-    <version>1.2.3-SNAPSHOT</version>
+    <version>1.3.0-SNAPSHOT</version>
     <name>Apache Sling Models API</name>
     <description>Apache Sling Models API</description>
     <scm>
@@ -69,5 +69,15 @@
             <version>3.0.0</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.api</artifactId>
+            <version>2.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git a/src/main/java/org/apache/sling/models/annotations/Model.java b/src/main/java/org/apache/sling/models/annotations/Model.java
index 5d17b74..7dafa33 100644
--- a/src/main/java/org/apache/sling/models/annotations/Model.java
+++ b/src/main/java/org/apache/sling/models/annotations/Model.java
@@ -60,4 +60,10 @@ public @interface Model {
      */
     public ValidationStrategy validation() default ValidationStrategy.DISABLED;
 
+    /**
+     *
+     * @return the associated resource type for this model class
+     */
+    public String[] resourceType() default {};
+
 }
diff --git a/src/main/java/org/apache/sling/models/annotations/package-info.java b/src/main/java/org/apache/sling/models/annotations/package-info.java
index b262f8a..8da3547 100644
--- a/src/main/java/org/apache/sling/models/annotations/package-info.java
+++ b/src/main/java/org/apache/sling/models/annotations/package-info.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-@Version("1.2.0")
+@Version("1.3.0")
 package org.apache.sling.models.annotations;
 
 import aQute.bnd.annotation.Version;
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/models/factory/ModelFactory.java b/src/main/java/org/apache/sling/models/factory/ModelFactory.java
index 9854648..3717625 100644
--- a/src/main/java/org/apache/sling/models/factory/ModelFactory.java
+++ b/src/main/java/org/apache/sling/models/factory/ModelFactory.java
@@ -20,6 +20,9 @@ package org.apache.sling.models.factory;
 
 import javax.annotation.Nonnull;
 
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.resource.Resource;
+
 import aQute.bnd.annotation.ProviderType;
 
 /**
@@ -77,4 +80,50 @@ public interface ModelFactory {
      */
     public boolean isModelClass(@Nonnull Class<?> type);
 
+    /**
+     * Determine is a model class is available for the resource's resource type.
+     *
+     * @param resource a resource
+     * @return {@code true} if a model class is mapped to the resource type
+     */
+    public boolean isModelAvailableForResource(@Nonnull Resource resource);
+
+    /**
+     * Determine is a model class is available for the request's resource's resource type.
+     *
+     * @param request a request
+     * @return {@code true} if a model class is mapped to the resource type
+     */
+    public boolean isModelAvailableForRequest(@Nonnull SlingHttpServletRequest request);
+
+    /**
+     * Obtain an adapted model class based on the resource type of the provided resource.
+     *
+     * @param resource a resource
+     * @return an adapted model object
+     * @throws MissingElementsException in case no injector was able to inject some required values with the given types
+     * @throws InvalidAdaptableException in case the given class cannot be instantiated from the given adaptable (different adaptable on the model annotation)
+     * @throws ModelClassException in case the model could not be instantiated because model annotation was missing, reflection failed, no valid constructor was found, model was not registered as adapter factory yet, or post-construct could not be called
+     * @throws PostConstructException in case the post-construct method has thrown an exception itself
+     * @throws ValidationException in case validation could not be performed for some reason (e.g. no validation information available)
+     * @throws InvalidModelException in case the given model type could not be validated through the model validation
+     */
+    public Object getModelFromResource(@Nonnull Resource resource) throws MissingElementsException,
+            InvalidAdaptableException, ModelClassException, PostConstructException, ValidationException, InvalidModelException;
+
+    /**
+     * Obtain an adapted model class based on the resource type of the request's resource.
+     *
+     * @param request a request
+     * @return an adapted model object
+     * @throws MissingElementsException in case no injector was able to inject some required values with the given types
+     * @throws InvalidAdaptableException in case the given class cannot be instantiated from the given adaptable (different adaptable on the model annotation)
+     * @throws ModelClassException in case the model could not be instantiated because model annotation was missing, reflection failed, no valid constructor was found, model was not registered as adapter factory yet, or post-construct could not be called
+     * @throws PostConstructException in case the post-construct method has thrown an exception itself
+     * @throws ValidationException in case validation could not be performed for some reason (e.g. no validation information available)
+     * @throws InvalidModelException in case the given model type could not be validated through the model validation
+     */
+    public Object getModelFromRequest(@Nonnull SlingHttpServletRequest request) throws MissingElementsException,
+            InvalidAdaptableException, ModelClassException, PostConstructException, ValidationException, InvalidModelException;
+
 }
diff --git a/src/main/java/org/apache/sling/models/factory/package-info.java b/src/main/java/org/apache/sling/models/factory/package-info.java
index 45cfda3..66be608 100644
--- a/src/main/java/org/apache/sling/models/factory/package-info.java
+++ b/src/main/java/org/apache/sling/models/factory/package-info.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-@Version("1.1.0")
+@Version("1.2.0")
 package org.apache.sling.models.factory;
 
 import aQute.bnd.annotation.Version;
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.