You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Dirk Rudolph (Jira)" <ji...@apache.org> on 2022/01/19 10:20:00 UTC

[jira] [Assigned] (SLING-11073) Support for Via "Original Resource"

     [ https://issues.apache.org/jira/browse/SLING-11073?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dirk Rudolph reassigned SLING-11073:
------------------------------------

    Assignee: Dirk Rudolph

> Support for Via "Original Resource"
> -----------------------------------
>
>                 Key: SLING-11073
>                 URL: https://issues.apache.org/jira/browse/SLING-11073
>             Project: Sling
>          Issue Type: Improvement
>          Components: Sling Models
>            Reporter: Dirk Rudolph
>            Assignee: Dirk Rudolph
>            Priority: Major
>
> Consider the following Models
> {code}
> interface A { }
> interface B { }
> @Model(adaptables=SlingHttpServletRequest.class, resourceType="generic")
> class AImpl implements A { @Self private B other; }
> @Model(adaptables=SlingHttpServletRequest.class, resourceType="generic")
> class BImpl implements B { }
> {code}
> If we want to extend this using the delegation pattern we could do
> {code}
> interface A1 extends A { }
> @Model(adaptables=SlingHttpServletRequest.class, resourceType="specific")
> class A1Impl implements A1 { @Self @Via(type=ResourceSuperType.class) private A delegate; }
> {code}
> and additionally for B
> {code}
> interface B1 extends B { }
> @Model(adaptables=SlingHttpServletRequest.class, resourceType="specific")
> class B1Impl implements B1 { @Self @Via(type=ResourceSuperType.class) private B delegate; }
> {code}
> This will however still inject {{BImpl}} into the instance of {{AImpl}} (the delegate in {{A1Impl}}) when adapting a request on a resource with resourceType="specific" even though there is a more specific implementation of it that would match the original resourceType (would be {{B1Impl}}). The reason is that the ResourceTypeBasedResourcePicker picks {{BImpl}} based on the resourceType forced by the ResourceSuperTypeViaProvider.
> This behaviour may be desired in some cases but not in others. That's why I propose to introduce a OriginalResourceViaProvider which unwraps the changes made by the AbstractResourceTypeViaProvider. This can explicitly be specified to enable it.
> {code}
> class AImpl implements A {
>  @Self 
>  @Via(type = OriginalResource.class) // undo any forced resourceTypes
>  private B other;
> }
> {code}
> Which then would inject {{B1Impl}}, the one for the original "specific" resoruceType.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)