1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ch.qos.logback.core.blackbox.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.blackbox.model.BlackboxStackModel;
22 import ch.qos.logback.core.model.Model;
23 import ch.qos.logback.core.model.processor.ModelHandlerBase;
24 import ch.qos.logback.core.model.processor.ModelHandlerException;
25 import ch.qos.logback.core.model.processor.ModelInterpretationContext;
26
27 public class BlackboxStackModelHandler extends ModelHandlerBase {
28
29 static public final String STACK_TEST = "STACK_TEST";
30
31 public BlackboxStackModelHandler(Context context) {
32 super(context);
33 }
34
35 static public BlackboxStackModelHandler makeInstance(Context context, ModelInterpretationContext ic) {
36 return new BlackboxStackModelHandler(context);
37 }
38
39 @Override
40 protected Class<BlackboxStackModel> getSupportedModelClass() {
41 return BlackboxStackModel.class;
42 }
43
44 @Override
45 public void handle(ModelInterpretationContext mic, Model model) throws ModelHandlerException {
46
47 BlackboxStackModel stackModel = (BlackboxStackModel) model;
48
49 String name = stackModel.getName();
50
51 ContextBase contextBase = (ContextBase) context;
52
53 @SuppressWarnings("unchecked")
54 Stack<String> aStack = (Stack) context.getObject(STACK_TEST);
55 if(aStack == null) {
56 aStack = new Stack<>();
57 contextBase.putObject(STACK_TEST, aStack);
58 }
59 aStack.push(name);
60 }
61
62 @Override
63 public void postHandle(ModelInterpretationContext intercon, Model model) throws ModelHandlerException {
64 }
65
66 }