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

[Sling Models] Support Delegate Pattern for Models adapted from interfaces

    XMLWordPrintableJSON

    Details

      Description

      Consider this interface:

      public interface Something {
      	
      	String getText();
      
              String getOther();
      
      }
      

      With this model implementation:

      @Model(adaptable = Resource.class, adapter = Something.class, resourceType = "myco/something")
      public class SomethingImpl implements Something {
      	
      	@Inject
      	private String text;
      
              @Inject
              private String other;
      
      	public String getText() {
      		return text;
      	}
              public String getOther() {
                      return other;
               }
      
      }
      

      And let's say that there is a resource with the type myco/somethingelse and that myco/something is the super type of myco/somethingelse.

      In order to create a model class associated with myco/somethingelse and have that model class access the original class using the Delegate pattern, it is quite difficult to do so since you need to manually create a wrapping resource and then adapt that. I think we can facilitate this pattern through SLING-5739 and a new @Via provider.

      The syntax would be something along the lines of

                      @Self @Via(type = ResourceSuperType.class)
                      private Something delegate;
      

      Assuming you wanted the super type

      We could also support manually setting the resource type, i.e.

                      @Self @Via(value = “some/other/resourceType”, type = ForcedResourceType.class)
                      private Something delegate;
      

        Attachments

        1. SLING-6778.diff
          35 kB
          Justin Edelson
        2. SLING-6778.diff
          36 kB
          Justin Edelson

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                justinedelson Justin Edelson
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: