Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
OptionRule |
|
| 1.3333333333333333;1.333 |
1 | 1663 | /* |
2 | * Copyright 2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
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/'>Apache Commons Team</a> |
|
28 | * @since 0.5 |
|
29 | */ |
|
30 | 1663 | public class OptionRule extends Rule { |
31 | ||
32 | 299 | private String currentValue; |
33 | 299 | 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 | 312 | currentValue = null; |
41 | 312 | currentName = null; |
42 | 312 | } |
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 | 312 | if (currentName != null && currentValue != null) { |
51 | 286 | Object top = getDigester().peek(); |
52 | 286 | if (top instanceof Descriptor) { |
53 | 286 | Descriptor descriptor = (Descriptor) top; |
54 | 286 | descriptor.getOptions().addOption(currentName, currentValue); |
55 | } |
|
56 | } |
|
57 | 312 | } |
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 | 1663 | return new Rule() { |
66 | public void body(String namespace, String name, String text) { |
|
67 | 299 | currentName = text; |
68 | 299 | } |
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 | 1663 | return new Rule() { |
79 | public void body(String namespace, String name, String text) { |
|
80 | 299 | currentValue = text; |
81 | 299 | } |
82 | }; |
|
83 | } |
|
84 | } |