1
2
3
4
5
6
7
8
9
10
11 package chapter3.calculator;
12
13 import org.xml.sax.Attributes;
14
15 import ch.qos.logback.core.joran.action.Action;
16 import ch.qos.logback.core.joran.spi.InterpretationContext;
17 import ch.qos.logback.core.util.OptionHelper;
18
19
20
21
22
23
24
25
26
27
28
29 public class LiteralAction extends Action {
30 public static String VALUE_ATR = "value";
31
32 public void begin(InterpretationContext ec, String name, Attributes attributes) {
33 String valueStr = attributes.getValue(VALUE_ATR);
34
35 if (OptionHelper.isEmpty(valueStr)) {
36 ec.addError("The literal action requires a value attribute");
37 return;
38 }
39
40 try {
41 Integer i = Integer.valueOf(valueStr);
42 ec.pushObject(i);
43 } catch (NumberFormatException nfe) {
44 ec.addError("The value [" + valueStr + "] could not be converted to an Integer",
45 nfe);
46 throw nfe;
47 }
48 }
49
50 public void end(InterpretationContext ec, String name) {
51
52
53
54
55 }
56 }