View Javadoc
1   /*
2    * #%L
3    * wcm.io
4    * %%
5    * Copyright (C) 2014 wcm.io
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package io.wcm.sling.models.injectors.impl;
21  
22  import org.osgi.service.component.annotations.Activate;
23  import org.osgi.service.component.annotations.Component;
24  import org.osgi.service.metatype.annotations.AttributeDefinition;
25  import org.osgi.service.metatype.annotations.Designate;
26  import org.osgi.service.metatype.annotations.ObjectClassDefinition;
27  
28  /**
29   * Configures behavior of the wcm.io Injectors for Sling Models
30   */
31  @Component(service = ModelsImplConfiguration.class, immediate = true)
32  @Designate(ocd = ModelsImplConfiguration.Config.class)
33  public class ModelsImplConfiguration {
34  
35    @ObjectClassDefinition(name = "wcm.io Models Configuration",
36        description = "Configures behavior of the wcm.io Injectors for Sling Models")
37    @interface Config {
38  
39      @AttributeDefinition(name = "Request Thread Local",
40          description = "Enables the thread-local based injection of all request-derived objects in AEM Object " +
41              "and Sling Object injectors. These objects can than always be injected regardless of the adaptable.")
42      boolean requestThreadLocal() default true;
43  
44    }
45  
46    private boolean requestThreadLocal;
47  
48    @Activate
49    private void activate(Config config) {
50      requestThreadLocal = config.requestThreadLocal();
51    }
52  
53    /**
54     * Enables the thread-local based injection of all request-derived objects in AEM Object
55     * and Sling Object injectors. These objects can than always be injected regardless of the adaptable.
56     * @return Request Thread Local
57     */
58    public boolean isRequestThreadLocal() {
59      return this.requestThreadLocal;
60    }
61  
62  }