You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Roy Teeuwen (JIRA)" <ji...@apache.org> on 2017/04/12 07:16:41 UTC

[jira] [Commented] (SLING-6778) [Sling Models] Support Delegate Pattern for Models adapted from interfaces

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

Roy Teeuwen commented on SLING-6778:
------------------------------------

Hey [~justinedelson],

Please change your annotation name from SuperResourceType to ResourceSuperType, it is also sling:resourceSuperType, so this would make it very confusing, I have seen developers try and use sling:superResourceType, which of course does not work

Greets,
Roy

> [Sling Models] Support Delegate Pattern for Models adapted from interfaces
> --------------------------------------------------------------------------
>
>                 Key: SLING-6778
>                 URL: https://issues.apache.org/jira/browse/SLING-6778
>             Project: Sling
>          Issue Type: New Feature
>          Components: Extensions
>            Reporter: Justin Edelson
>         Attachments: SLING-6778.diff
>
>
> Consider this interface:
> {code}
> public interface Something {
> 	
> 	String getText();
>         String getOther();
> }
> {code}
> With this model implementation:
> {code}
> @Model(adaptable = Resource.class, adapter = Something.class, resourceType = "myco/something")
> public class SomethingImpl implements Something {
> 	
> 	@Inject
> 	private String text;
>         @Inject
>         private String other;
> 	public String getText() {
> 		return text;
> 	}
>         public String getOther() {
>                 return other;
>          }
> }
> {code}
> And let's say that there is a resource with the type {{myco/somethingelse}} and that {{myco/something}} is the super type of {{myco/somethingelse}}.
> In order to create a model class associated with {{myco/somethingelse}} and have that model class access the original class using the Delegate pattern, it is quite difficult to do so since you need to manually create a wrapping resource and then adapt that. I think we can facilitate this pattern through SLING-5739 and a new @Via provider.
> The syntax would be something along the lines of
> {code}
>                 @Self @Via(type = SuperResourceType.class)
>                 private Something delegate;
> {code}
> Assuming you wanted the super type
> We could also support manually setting the resource type, i.e.
> {code}
>                 @Self @Via(value = “some/other/resourceType”, type = ForcedResourceType.class)
>                 private Something delegate;
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)