1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2026, 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 v2.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.model.processor;
16  
17  import java.util.Stack;
18  
19  import ch.qos.logback.core.Context;
20  import ch.qos.logback.core.ContextBase;
21  import ch.qos.logback.core.model.Model;
22  import ch.qos.logback.core.model.StackModel;
23  
24  public class StackModelHandler  extends ModelHandlerBase {
25  
26      static public final String STACK_TEST = "STACK_TEST"; 
27      
28      public StackModelHandler(Context context) {
29          super(context);
30      }
31  
32      static public ModelHandlerBase makeInstance(Context context, ModelInterpretationContext ic) {
33          return new StackModelHandler(context);
34      }
35  
36      @Override
37      protected Class<StackModel> getSupportedModelClass() {
38          return StackModel.class;
39      }
40      
41      @Override
42      public void handle(ModelInterpretationContext mic, Model model) throws ModelHandlerException {
43          
44          StackModel stackModel = (StackModel) model;
45          
46          String name = stackModel.getName();
47          
48          ContextBase contextBase = (ContextBase) context;
49          
50          @SuppressWarnings("unchecked")
51          Stack<String> aStack = (Stack) context.getObject(STACK_TEST);
52          if(aStack == null) {
53              aStack = new Stack<>();
54              contextBase.putObject(STACK_TEST, aStack);
55          }
56          aStack.push(name);
57      }
58      
59      @Override
60      public void postHandle(ModelInterpretationContext intercon, Model model) throws ModelHandlerException {
61      }
62  
63  }