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