1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2023, 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  
15  package ch.qos.logback.core.joran;
16  
17  import ch.qos.logback.core.Context;
18  import ch.qos.logback.core.model.*;
19  import ch.qos.logback.core.model.conditional.ElseModel;
20  import ch.qos.logback.core.model.conditional.IfModel;
21  import ch.qos.logback.core.model.conditional.ThenModel;
22  import ch.qos.logback.core.model.processor.*;
23  import ch.qos.logback.core.model.processor.conditional.ElseModelHandler;
24  import ch.qos.logback.core.model.processor.conditional.IfModelHandler;
25  import ch.qos.logback.core.model.processor.conditional.ThenModelHandler;
26  import ch.qos.logback.core.sift.SiftModelHandler;
27  
28  /**
29   * For a given DefaultProcessor instance link a {@link ch.qos.logback.core.model.Model Model} class to
30   * a {@link ch.qos.logback.core.model.processor.ModelHandlerBase ModelHandler} instance in logback-core.
31   *
32   * <p>Derived classes are likely to add further links.</p>
33   *
34   * @since 1.3.9/1.4.9
35   */
36  public class ModelClassToModelHandlerLinkerBase {
37  
38  
39      protected Context context;
40  
41      public ModelClassToModelHandlerLinkerBase(Context context) {
42          this.context = context;
43      }
44  
45      public void link(DefaultProcessor defaultProcessor) {
46          defaultProcessor.addHandler(ImportModel.class, ImportModelHandler::makeInstance);
47  
48          defaultProcessor.addHandler(ShutdownHookModel.class, ShutdownHookModelHandler::makeInstance);
49          defaultProcessor.addHandler(SequenceNumberGeneratorModel.class, SequenceNumberGeneratorModelHandler::makeInstance);
50          defaultProcessor.addHandler(SerializeModelModel.class, SerializeModelModelHandler::makeInstance);
51  
52          defaultProcessor.addHandler(EventEvaluatorModel.class, EventEvaluatorModelHandler::makeInstance);
53          defaultProcessor.addHandler(ConversionRuleModel.class, ConversionRuleModelHandler::makeInstance);
54  
55          defaultProcessor.addHandler(DefineModel.class, DefineModelHandler::makeInstance);
56          defaultProcessor.addHandler(IncludeModel.class, IncludeModelHandler::makeInstance);
57  
58  
59          defaultProcessor.addHandler(ParamModel.class, ParamModelHandler::makeInstance);
60          defaultProcessor.addHandler(PropertyModel.class, PropertyModelHandler::makeInstance);
61          defaultProcessor.addHandler(TimestampModel.class, TimestampModelHandler::makeInstance);
62          defaultProcessor.addHandler(StatusListenerModel.class, StatusListenerModelHandler::makeInstance);
63          defaultProcessor.addHandler(ImplicitModel.class, ImplicitModelHandler::makeInstance);
64  
65          defaultProcessor.addHandler(IfModel.class, IfModelHandler::makeInstance);
66          defaultProcessor.addHandler(ThenModel.class, ThenModelHandler::makeInstance);
67          defaultProcessor.addHandler(ElseModel.class, ElseModelHandler::makeInstance);
68  
69          defaultProcessor.addHandler(SiftModel.class, SiftModelHandler::makeInstance);
70      }
71  
72      // The final filters in the two filter chain are rather crucial.
73      // They ensure that only Models attached to the firstPhaseFilter will
74      // be handled in the first phase and all models not previously handled
75      // in the second phase will be handled in a catch-all fallback case.
76      protected void sealModelFilters(DefaultProcessor defaultProcessor) {
77          defaultProcessor.getPhaseOneFilter().denyAll();
78          defaultProcessor.getPhaseTwoFilter().allowAll();
79      }
80  }