[ 
https://issues.apache.org/jira/browse/SLING-5992?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15434262#comment-15434262
 ] 

Konrad Windszus commented on SLING-5992:
----------------------------------------

In general I like the idea and I think this is very useful (especially together 
with Sling Validation which registers on resource types as well). 
The API though could be improved IMHO:
Both new methods just return {{null}} in any error case (without having the 
proper JSR305 annotation {{@CheckForNull}}). That is something we should 
prevent. I would prefer if those new methods would instead throw exceptions 
(similar to {{ModelFactory.createModel(..)}}. That way debugging issues during 
development time is much easier and it relieves the developers from always 
implementing the null checks.
To allow to check in advance if such a model is available we should also have 
two separate methods {{isModelAvailableForResource(...)}} and 
{{isModelAvailableForRequest(...)}}.

I am not 100% sure yet if both {{SlingHttpServletRequest}} and {{Resource}} 
should be supported. In the best case those models should only be adaptable 
from {{Resource}}s only. Having a Sling Model registered on a {{resourceType}} 
and adaptable from a {{SlingHttpServletRequest}} sounds kind of weird to me. 
But since some injectors only support acting on a {{SlingHttpServletRequest}} I 
guess that limitation would probably cause some pain during development.

> Provide a way to map Sling Model classes to resource types
> ----------------------------------------------------------
>
>                 Key: SLING-5992
>                 URL: https://issues.apache.org/jira/browse/SLING-5992
>             Project: Sling
>          Issue Type: New Feature
>          Components: Extensions
>            Reporter: Justin Edelson
>             Fix For: Sling Models API 1.3.0, Sling Models Impl 1.3.0
>
>         Attachments: SLING-5992.patch
>
>
> For ease of script development, I would like to introduce a mechanism for 
> mapping Sling Model classes to resource types for Resource and 
> SlingHttpServletRequest objects.
> From an API perspective, this introduces two new methods on ModelFactory:
> {code}
> public Object getModelFromResource(@Nonnull Resource resource);
> public Object getModelFromRequest(@Nonnull SlingHttpServletRequest request);
> {code}
> And a new attribute on the @Model annotations
> {code}
> public String resourceType() default "";
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to