1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2022, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.access.common.joran;
15  
16  import ch.qos.logback.access.common.model.processor.LogbackAccessDefaultNestedComponentRegistryRules;
17  import ch.qos.logback.access.common.spi.IAccessEvent;
18  import ch.qos.logback.access.common.joran.action.ConfigurationAction;
19  import ch.qos.logback.core.joran.JoranConfiguratorBase;
20  import ch.qos.logback.core.joran.action.AppenderRefAction;
21  import ch.qos.logback.core.joran.action.IncludeAction;
22  import ch.qos.logback.core.joran.spi.DefaultNestedComponentRegistry;
23  import ch.qos.logback.core.joran.spi.ElementSelector;
24  import ch.qos.logback.core.joran.spi.RuleStore;
25  import ch.qos.logback.core.model.processor.DefaultProcessor;
26  
27  /**
28   * This JoranConfiguratorclass adds rules specific to logback-access.
29   *
30   * @author Ceki Gülcü
31   */
32  public class JoranConfigurator extends JoranConfiguratorBase<IAccessEvent> {
33  
34      @Override
35      public void addElementSelectorAndActionAssociations(RuleStore rs) {
36          super.addElementSelectorAndActionAssociations(rs);
37  
38          rs.addRule(new ElementSelector("configuration"), () -> new ConfigurationAction());
39          rs.addRule(new ElementSelector("configuration/appender-ref"), () -> new AppenderRefAction());
40          rs.addRule(new ElementSelector("configuration/include"), () -> new IncludeAction());
41      }
42  
43      @Override
44      protected void addModelHandlerAssociations(DefaultProcessor defaultProcessor) {
45  
46          ModelClassToModelHandlerLinker mham = new ModelClassToModelHandlerLinker(context);
47          mham.link(defaultProcessor);
48  
49      }
50  
51  
52      @Override
53      protected void addDefaultNestedComponentRegistryRules(DefaultNestedComponentRegistry registry) {
54          LogbackAccessDefaultNestedComponentRegistryRules.addDefaultNestedComponentRegistryRules(registry);
55      }
56  
57      private JoranConfigurator makeAnotherInstance() {
58          JoranConfigurator jc = new JoranConfigurator();
59          jc.setContext(context);
60          return jc;
61      }
62  
63      public void buildModelInterpretationContext() {
64          super.buildModelInterpretationContext();
65          this.modelInterpretationContext.setConfiguratorSupplier(  () -> this.makeAnotherInstance() );
66      }
67  }