View Javadoc
1   package ch.qos.logback.core.blackbox.model.processor;
2   
3   import java.util.Stack;
4   
5   import ch.qos.logback.core.Context;
6   import ch.qos.logback.core.ContextBase;
7   import ch.qos.logback.core.blackbox.model.BlackboxStackModel;
8   import ch.qos.logback.core.model.Model;
9   import ch.qos.logback.core.model.processor.ModelHandlerBase;
10  import ch.qos.logback.core.model.processor.ModelHandlerException;
11  import ch.qos.logback.core.model.processor.ModelInterpretationContext;
12  
13  public class BlackboxStackModelHandler extends ModelHandlerBase {
14  
15      static public final String STACK_TEST = "STACK_TEST"; 
16      
17      public BlackboxStackModelHandler(Context context) {
18          super(context);
19      }
20  
21      static public BlackboxStackModelHandler makeInstance(Context context, ModelInterpretationContext ic) {
22          return new BlackboxStackModelHandler(context);
23      }
24  
25      @Override
26      protected Class<BlackboxStackModel> getSupportedModelClass() {
27          return BlackboxStackModel.class;
28      }
29      
30      @Override
31      public void handle(ModelInterpretationContext mic, Model model) throws ModelHandlerException {
32  
33          BlackboxStackModel stackModel = (BlackboxStackModel) model;
34          
35          String name = stackModel.getName();
36          
37          ContextBase contextBase = (ContextBase) context;
38          
39          @SuppressWarnings("unchecked")
40          Stack<String> aStack = (Stack) context.getObject(STACK_TEST);
41          if(aStack == null) {
42              aStack = new Stack<>();
43              contextBase.putObject(STACK_TEST, aStack);
44          }
45          aStack.push(name);
46      }
47      
48      @Override
49      public void postHandle(ModelInterpretationContext intercon, Model model) throws ModelHandlerException {
50      }
51  
52  }