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