Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
Consider the following Models
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 { }
If we want to extend this using the delegation pattern we could do
interface A1 extends A { } @Model(adaptables=SlingHttpServletRequest.class, resourceType="specific") class A1Impl implements A1 { @Self @Via(type=ResourceSuperType.class) private A delegate; }
and additionally for B
interface B1 extends B { } @Model(adaptables=SlingHttpServletRequest.class, resourceType="specific") class B1Impl implements B1 { @Self @Via(type=ResourceSuperType.class) private B delegate; }
This will 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.
class AImpl implements A { @Self @Via(type = OriginalResourceType.class) // undo any forced resourceTypes private B other; }
Which then would inject B1Impl, the one for the original "specific" resoruceType.