Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-11073

Support for Via "Original Resource Type"

    XMLWordPrintableJSON

Details

    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.

      Attachments

        Activity

          People

            diru Dirk Rudolph
            diru Dirk Rudolph
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 2h 50m
                2h 50m