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

ConfigurationBuilder: Add method to check for the existence of the config

    Details

      Description

      Sometimes it is desirable to check if a Context Aware Configuration is there at all via the high level API. Both methods as and asCollection will never return null, as they will always consider the default values. All other methods require to set at least a name.

      So to simply check if a CAC content resource is existing for a certain annotation class (defining a Context Aware Configuration) the following code is necessary:

      ConfigurationBuilder builder = contentResource.adaptTo(ConfigurationBuilder.class);
      builder.name(<derive name from annotation type>).valueMap().isEmpty();
      

      As there is no method exported to derive the name from an annotation type this would require additional custom code.

      I propose to add a simple

      boolean has(@NotNull java.lang.Class<T> clazz)
      

      which is only then supposed to return true in case there is an underlying CAC content resource which can be adapted to the given class.

      Compare also with https://www.mail-archive.com/dev@sling.apache.org/msg83617.html.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                kwin Konrad Windszus
                Reporter:
                kwin Konrad Windszus
              • Votes:
                0 Vote for this issue
                Watchers:
                3 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 - 4h 50m
                  4h 50m