1
2
3
4
5
6
7
8
9
10
11
12
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 }