1
2
3
4
5
6
7
8
9
10
11 package chapter10.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 public class LiteralAction extends Action {
29 public static String VALUE_ATR = "value";
30
31 public void begin(InterpretationContext ic, String name, Attributes attributes) {
32 String valueStr = attributes.getValue(VALUE_ATR);
33
34 if (OptionHelper.isEmpty(valueStr)) {
35 ic.addError("The literal action requires a value attribute");
36 return;
37 }
38
39 try {
40 Integer i = Integer.valueOf(valueStr);
41 ic.pushObject(i);
42 } catch (NumberFormatException nfe) {
43 ic.addError("The value [" + valueStr
44 + "] could not be converted to an Integer", nfe);
45 throw nfe;
46 }
47 }
48
49 public void end(InterpretationContext ic, String name) {
50
51
52
53
54 }
55 }