[
https://issues.apache.org/jira/browse/SLING-11073?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Dirk Rudolph updated SLING-11073:
---------------------------------
Fix Version/s: Models API 1.4.2
Models Implementation 1.5.2
> 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
> Fix For: Models API 1.4.2, Models Implementation 1.5.2
>
> Time Spent: 50m
> Remaining Estimate: 0h
>
> 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)