1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.joran.action;
15
16 import java.util.Stack;
17
18 import org.xml.sax.Attributes;
19
20 import ch.qos.logback.core.joran.spi.ActionException;
21 import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
22 import ch.qos.logback.core.model.ImplicitModel;
23 import ch.qos.logback.core.model.Model;
24 import ch.qos.logback.core.spi.ErrorCodes;
25
26
27
28
29
30
31
32
33
34
35 public class ImplicitModelAction extends Action {
36
37 Stack<ImplicitModel> currentImplicitModelStack = new Stack<>();
38
39 @Override
40 public void begin(SaxEventInterpretationContext interpretationContext, String name, Attributes attributes)
41 throws ActionException {
42 ImplicitModel currentImplicitModel = new ImplicitModel();
43 currentImplicitModel.setTag(name);
44
45 String className = attributes.getValue(CLASS_ATTRIBUTE);
46 currentImplicitModel.setClassName(className);
47 currentImplicitModelStack.push(currentImplicitModel);
48 interpretationContext.pushModel(currentImplicitModel);
49 }
50
51 @Override
52 public void body(SaxEventInterpretationContext ec, String body) {
53 ImplicitModel implicitModel = currentImplicitModelStack.peek();
54 implicitModel.addText(body);
55 }
56
57 @Override
58 public void end(SaxEventInterpretationContext interpretationContext, String name) throws ActionException {
59
60 ImplicitModel implicitModel = currentImplicitModelStack.peek();
61 Model otherImplicitModel = interpretationContext.popModel();
62
63 if (implicitModel != otherImplicitModel) {
64 addError(implicitModel + " does not match " + otherImplicitModel);
65 return;
66 }
67 Model parentModel = interpretationContext.peekModel();
68 if(parentModel != null) {
69 parentModel.addSubModel(implicitModel);
70 } else {
71 addWarn(ErrorCodes.PARENT_MODEL_NOT_FOUND);
72 addWarn(ErrorCodes.SKIPPING_IMPLICIT_MODEL_ADDITION);
73 }
74 currentImplicitModelStack.pop();
75
76 }
77
78 }