[
https://issues.apache.org/jira/browse/SLING-11073?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Dirk Rudolph updated SLING-11073:
---------------------------------
Description:
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 inject {{BImpl}} into the instance of {{AImpl}} when adapting a
request on a resource with resourceType="specific" even though there is a more
specific implementation of it the 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.
was:
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 inject {{BImpl}} into the instance of {{AImpl}} when adapting a
request on a resource with resourceType="specific" even though there is a more
specific implementation of it the would match the original resourceType (would
be {{B1Impl}}). The reason is that the ResourceTypeBasedResourcePicker picks
{{B1Impl}} 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.
> 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
> 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 inject {{BImpl}} into the instance of {{AImpl}} when adapting a
> request on a resource with resourceType="specific" even though there is a
> more specific implementation of it the 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)