1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.betwixt.digester;
19
20 import org.apache.commons.betwixt.Descriptor;
21 import org.apache.commons.digester.Rule;
22 import org.xml.sax.Attributes;
23
24 /***
25 * Maps option tree to an option in the
26 * {@link org.apache.commons.betwixt.Options}
27 * on the current description.
28 * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
29 * @since 0.5
30 */
31 public class OptionRule extends Rule {
32
33 private String currentValue;
34 private String currentName;
35
36 /***
37 * @see org.apache.commons.digester.Rule#begin(java.lang.String, java.lang.String, Attributes)
38 */
39 public void begin(String namespace, String name, Attributes attributes)
40 throws Exception {
41 currentValue = null;
42 currentName = null;
43 }
44
45
46
47 /***
48 * @see org.apache.commons.digester.Rule#end(java.lang.String, java.lang.String)
49 */
50 public void end(String namespace, String name) {
51 if (currentName != null && currentValue != null) {
52 Object top = getDigester().peek();
53 if (top instanceof Descriptor) {
54 Descriptor descriptor = (Descriptor) top;
55 descriptor.getOptions().addOption(currentName, currentValue);
56 }
57 }
58 }
59
60 /***
61 * Gets the rule that maps the <code>name</code> element
62 * associated with the option
63 * @return <code>Rule</code>, not null
64 */
65 public Rule getNameRule() {
66 return new Rule() {
67 public void body(String namespace, String name, String text) {
68 currentName = text;
69 }
70 };
71 }
72
73 /***
74 * Gets the rule that maps the <code>value</code> element
75 * associated with the option
76 * @return <code>Rule</code>, not null
77 */
78 public Rule getValueRule() {
79 return new Rule() {
80 public void body(String namespace, String name, String text) {
81 currentValue = text;
82 }
83 };
84 }
85 }