1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.sift;
15
16 import java.util.List;
17 import java.util.Map;
18
19 import ch.qos.logback.core.Appender;
20 import ch.qos.logback.core.CoreConstants;
21 import ch.qos.logback.core.joran.GenericConfigurator;
22 import ch.qos.logback.core.joran.action.NestedBasicPropertyIA;
23 import ch.qos.logback.core.joran.action.NestedComplexPropertyIA;
24 import ch.qos.logback.core.joran.event.SaxEvent;
25 import ch.qos.logback.core.joran.spi.Interpreter;
26 import ch.qos.logback.core.joran.spi.JoranException;
27
28 public abstract class SiftingJoranConfiguratorBase<E> extends
29 GenericConfigurator {
30
31 final static String ONE_AND_ONLY_ONE_URL = CoreConstants.CODES_URL
32 + "#1andOnly1";
33
34 @Override
35 protected void addImplicitRules(Interpreter interpreter) {
36 NestedComplexPropertyIA nestedComplexIA = new NestedComplexPropertyIA();
37 nestedComplexIA.setContext(context);
38 interpreter.addImplicitAction(nestedComplexIA);
39
40 NestedBasicPropertyIA nestedSimpleIA = new NestedBasicPropertyIA();
41 nestedSimpleIA.setContext(context);
42 interpreter.addImplicitAction(nestedSimpleIA);
43 }
44
45 abstract public Appender<E> getAppender();
46
47 int errorEmmissionCount = 0;
48
49 protected void oneAndOnlyOneCheck(Map appenderMap) {
50 String errMsg = null;
51 if (appenderMap.size() == 0) {
52 errorEmmissionCount++;
53 errMsg = "No nested appenders found within the <sift> element in SiftingAppender.";
54 } else if (appenderMap.size() > 1) {
55 errorEmmissionCount++;
56 errMsg = "Only and only one appender can be nested the <sift> element in SiftingAppender. See also "
57 + ONE_AND_ONLY_ONE_URL;
58 }
59
60 if (errMsg != null && errorEmmissionCount < CoreConstants.MAX_ERROR_COUNT) {
61 addError(errMsg);
62 }
63 }
64
65 public void doConfigure(final List<SaxEvent> eventList) throws JoranException {
66 super.doConfigure(eventList);
67 }
68 }