[
https://issues.apache.org/jira/browse/SLING-7256?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16738346#comment-16738346
]
Stefan Seifert commented on SLING-7256:
---------------------------------------
we will create a separate git repository
*sling-org-apache-sling-models-caconfig* for this type of extensions.
coming back to the API discussion - [~Sc0rpic0m] why do you think the @Via
approach is better?
from my point of view the following features need to be supported by this type
of integration:
* take the current resource as context resource (adapted from request or
resource), and lookup the matching context-aware configuration
* the variable to inject to can be either
** an annotation class describing the configuration (type-safe, automatically
defines the name of the caconfig)
** or a ValueMap (in which case the caconfig name has to be provided manually)
** or for lowlevel access the resource itself (in this case the bucket name has
to be specified as well)
* we also need to support collections of all those for configuration lists
this can be easily done in a Injector annotation. does it also work using Via?
please keep in mind that the value map returned from caconfig is not the same
as adapted from the lowlevel resource, as it respects also default values,
inheritance etc.
> Sling Models injector for CAConfig
> ----------------------------------
>
> Key: SLING-7256
> URL: https://issues.apache.org/jira/browse/SLING-7256
> Project: Sling
> Issue Type: New Feature
> Affects Versions: Sling Models Impl 1.4.4
> Reporter: Henry Kuijpers
> Priority: Major
>
> It would be great to have a Sling Models injector for CAConfig.
> An example could be:
> {code}
> @Component
> public class ContextAwareConfigurationInjector implements Injector {
> public String getName() {
> return "ca-config";
> }
> public Object getValue(Object adaptable, String name, Type declaredType,
> AnnotatedElement element,
> DisposalCallbackRegistry callbackRegistry) {
> if (isConfigurationObject(declaredType)) {
> final Resource resource;
> if (adaptable instanceof Resource) {
> resource = (Resource) adaptable;
> } else if (adaptable instanceof SlingHttpServletRequest) {
> // TODO: Is this always the correct resource? (Most often we
> want the one in /content)
> // So we do not want /conf/... for example
> final SlingHttpServletRequest request =
> (SlingHttpServletRequest)adaptable;
> final ResourceResolver resourceResolver =
> request.getResourceResolver();
> resource = resourceResolver.resolve(request,
> request.getRequestURI());
> } else {
> throw new IllegalArgumentException("Either a resource or the
> request should be used");
> }
> final ConfigurationBuilder builder =
> resource.adaptTo(ConfigurationBuilder.class);
> if (builder != null) {
> return builder.as((Class<?>) declaredType);
> }
> }
> return null;
> }
> private static boolean isConfigurationObject(Type type) {
> if (!(type instanceof Class<?>)) {
> return false;
> }
> Class<?> clazz = (Class<?>) type;
> return clazz.isAnnotation() &&
> clazz.isAnnotationPresent(Configuration.class);
> }
> }
> {code}
> + annotation:
> {code}
> @Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
> @Retention(RetentionPolicy.RUNTIME)
> @InjectAnnotation
> @Source("ca-config")
> @Qualifier
> public @interface CaConfig {
> }
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)