View Javadoc
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.core.model.processor;
15  
16  import ch.qos.logback.core.Context;
17  import ch.qos.logback.core.model.Model;
18  
19  public class RefContainerDependencyAnalyser extends ModelHandlerBase {
20  
21      final Class<?> modelClass;
22  
23      public RefContainerDependencyAnalyser(Context context, Class<?> modelClass) {
24          super(context);
25          this.modelClass = modelClass;
26      }
27  
28      @Override
29      protected boolean isSupportedModelType(Model model) {
30  
31          if (modelClass.isInstance(model)) {
32              return true;
33          }
34  
35          StringBuilder buf = new StringBuilder("This handler can only handle models of type ");
36          buf.append(modelClass.getName());
37          addError(buf.toString());
38          return false;
39      }
40  
41      @Override
42      public void handle(ModelInterpretationContext mic, Model model) throws ModelHandlerException {
43          mic.pushModel(model);
44      }
45  
46      @Override
47      public void postHandle(ModelInterpretationContext mic, Model model) throws ModelHandlerException {
48          Model poppedModel = mic.popModel();
49          if (model != poppedModel) {
50              addError("Popped model [" + poppedModel + "] different than expected [" + model + "]");
51          }
52      }
53  }