[ 
https://issues.apache.org/jira/browse/SLING-8272?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16766066#comment-16766066
 ] 

Stefan Seifert commented on SLING-8272:
---------------------------------------

this makes sense basically.
however, it's a bit difficult to define what means "has" or "has not":
* has = configuration exits for exactly the context->config path the resource 
lies in
* what if it exists in any higher configuration level and is inherited?
* what if it exists in the fallback paths /conf/global or /apps/config or 
/libs/config?
* what if it does not exist, but default values are configured in the 
configuration definition?
* what if it does not exist, but values are provided via other ways (e.g. 
[configuration 
override|https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration-override.html])


> ConfigurationBuilder: Add method to check for the existence of the config
> -------------------------------------------------------------------------
>
>                 Key: SLING-8272
>                 URL: https://issues.apache.org/jira/browse/SLING-8272
>             Project: Sling
>          Issue Type: Improvement
>          Components: Extensions
>    Affects Versions: Context-Aware Configuration API 1.1.2, Context-Aware 
> Configuration Impl 1.4.14
>            Reporter: Konrad Windszus
>            Assignee: Konrad Windszus
>            Priority: Major
>
> 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:
> {code}
> ConfigurationBuilder builder = 
> contentResource.adaptTo(ConfigurationBuilder.class);
> builder.name(<derive name from annotation type>).valueMap().isEmpty();
> {code}
> 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 
> {code}
> boolean has(@NotNull java.lang.Class<T> clazz)
> {code}
> 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/[email protected]/msg83617.html.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to