KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > editor > indentation > programmatic > DefinitionScanner


1 /*
2  * File: DefinitionScanner.java
3  * Generated from: definition.dtd
4  * Date: March 16, 2002 6:05 PM
5  *
6  * @author lahvac
7  * @version generated by NetBeans XML module
8  */

9 package org.netbeans.test.editor.indentation.programmatic;
10 /**
11  * This is a scanner of DOM tree.
12  *
13  * Example:
14  * <pre>
15  * javax.xml.parsers.DocumentBuilderFactory builderFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
16  * javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder();
17  * org.w3c.dom.Document document = builder.parse (new org.xml.sax.InputSource (???));
18  * <font color="blue">DefinitionScanner scanner = new DefinitionScanner (document);</font>
19  * <font color="blue">scanner.visitDocument();</font>
20  * </pre>
21  *
22  * @see org.w3c.dom.Document
23  * @see org.w3c.dom.Element
24  * @see org.w3c.dom.NamedNodeMap
25  */

26 public class DefinitionScanner {
27     /** org.w3c.dom.Document document */
28     org.w3c.dom.Document JavaDoc document;
29     
30     private IndentCoreGenerator.TestCase testCase;
31     
32     /** Create new DefinitionScanner with org.w3c.dom.Document. */
33     public DefinitionScanner(org.w3c.dom.Document JavaDoc document) {
34         this.document = document;
35     }
36     
37     /** Scan through org.w3c.dom.Document document. */
38     public void visitDocument() {
39         org.w3c.dom.Element JavaDoc element = document.getDocumentElement();
40         if ((element != null) && element.getTagName().equals("definition")) {
41             visitElement_definition(element);
42         }
43         if ((element != null) && element.getTagName().equals("fail")) {
44             visitElement_fail(element);
45         }
46         if ((element != null) && element.getTagName().equals("indentation-properties")) {
47             visitElement_indentation_properties(element);
48         }
49         if ((element != null) && element.getTagName().equals("property")) {
50             visitElement_property(element);
51         }
52         if ((element != null) && element.getTagName().equals("reason")) {
53             visitElement_reason(element);
54         }
55         if ((element != null) && element.getTagName().equals("test-case")) {
56             visitElement_test_case(element);
57         }
58         if ((element != null) && element.getTagName().equals("text")) {
59             visitElement_text(element);
60         }
61     }
62     
63     /** Scan through org.w3c.dom.Element named definition. */
64     void visitElement_definition(org.w3c.dom.Element JavaDoc element) { // <definition>
65
// element.getValue();
66
org.w3c.dom.NodeList JavaDoc nodes = element.getChildNodes();
67         for (int i = 0; i < nodes.getLength(); i++) {
68             org.w3c.dom.Node JavaDoc node = nodes.item(i);
69             switch (node.getNodeType()) {
70                 case org.w3c.dom.Node.CDATA_SECTION_NODE:
71                     // ((org.w3c.dom.CDATASection)node).getData();
72
break;
73                 case org.w3c.dom.Node.ELEMENT_NODE:
74                     org.w3c.dom.Element JavaDoc nodeElement = (org.w3c.dom.Element JavaDoc)node;
75                     if (nodeElement.getTagName().equals("test-case")) {
76                         visitElement_test_case(nodeElement);
77                     }
78                     break;
79                 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE:
80                     // ((org.w3c.dom.ProcessingInstruction)node).getTarget();
81
// ((org.w3c.dom.ProcessingInstruction)node).getData();
82
break;
83             }
84         }
85     }
86     
87     /** Scan through org.w3c.dom.Element named fail. */
88     void visitElement_fail(org.w3c.dom.Element JavaDoc element) { // <fail>
89
// element.getValue();
90
org.w3c.dom.NamedNodeMap JavaDoc attrs = element.getAttributes();
91         for (int i = 0; i < attrs.getLength(); i++) {
92             org.w3c.dom.Attr JavaDoc attr = (org.w3c.dom.Attr JavaDoc)attrs.item(i);
93             if (attr.getName().equals("supposed-to-fail")) { // <fail supposed-to-fail="???">
94
testCase.setWillFail(Boolean.valueOf(attr.getValue()).booleanValue());
95             }
96         }
97         org.w3c.dom.NodeList JavaDoc nodes = element.getChildNodes();
98         for (int i = 0; i < nodes.getLength(); i++) {
99             org.w3c.dom.Node JavaDoc node = nodes.item(i);
100             switch (node.getNodeType()) {
101                 case org.w3c.dom.Node.CDATA_SECTION_NODE:
102                     // ((org.w3c.dom.CDATASection)node).getData();
103
break;
104                 case org.w3c.dom.Node.ELEMENT_NODE:
105                     org.w3c.dom.Element JavaDoc nodeElement = (org.w3c.dom.Element JavaDoc)node;
106                     if (nodeElement.getTagName().equals("reason")) {
107                         visitElement_reason(nodeElement);
108                     }
109                     break;
110                 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE:
111                     // ((org.w3c.dom.ProcessingInstruction)node).getTarget();
112
// ((org.w3c.dom.ProcessingInstruction)node).getData();
113
break;
114             }
115         }
116     }
117     
118     /** Scan through org.w3c.dom.Element named indentation-properties. */
119     void visitElement_indentation_properties(org.w3c.dom.Element JavaDoc element) { // <indentation-properties>
120
// element.getValue();
121
org.w3c.dom.NodeList JavaDoc nodes = element.getChildNodes();
122         for (int i = 0; i < nodes.getLength(); i++) {
123             org.w3c.dom.Node JavaDoc node = nodes.item(i);
124             switch (node.getNodeType()) {
125                 case org.w3c.dom.Node.CDATA_SECTION_NODE:
126                     // ((org.w3c.dom.CDATASection)node).getData();
127
break;
128                 case org.w3c.dom.Node.ELEMENT_NODE:
129                     org.w3c.dom.Element JavaDoc nodeElement = (org.w3c.dom.Element JavaDoc)node;
130                     if (nodeElement.getTagName().equals("property")) {
131                         visitElement_property(nodeElement);
132                     }
133                     break;
134                 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE:
135                     // ((org.w3c.dom.ProcessingInstruction)node).getTarget();
136
// ((org.w3c.dom.ProcessingInstruction)node).getData();
137
break;
138             }
139         }
140     }
141     
142     /** Scan through org.w3c.dom.Element named property. */
143     void visitElement_property(org.w3c.dom.Element JavaDoc element) { // <property>
144
// element.getValue();
145
org.w3c.dom.NamedNodeMap JavaDoc attrs = element.getAttributes();
146         String JavaDoc property_name = null;
147         String JavaDoc property_value = null;
148         for (int i = 0; i < attrs.getLength(); i++) {
149             org.w3c.dom.Attr JavaDoc attr = (org.w3c.dom.Attr JavaDoc)attrs.item(i);
150             if (attr.getName().equals("name")) { // <property name="???">
151
property_name = attr.getValue();
152             }
153             if (attr.getName().equals("value")) { // <property value="???">
154
property_value = attr.getValue();
155             }
156         }
157         testCase.addIndentProperty(property_name, property_value);
158         org.w3c.dom.NodeList JavaDoc nodes = element.getChildNodes();
159         for (int i = 0; i < nodes.getLength(); i++) {
160             org.w3c.dom.Node JavaDoc node = nodes.item(i);
161             switch (node.getNodeType()) {
162                 case org.w3c.dom.Node.CDATA_SECTION_NODE:
163                     // ((org.w3c.dom.CDATASection)node).getData();
164
break;
165                 case org.w3c.dom.Node.ELEMENT_NODE:
166                     org.w3c.dom.Element JavaDoc nodeElement = (org.w3c.dom.Element JavaDoc)node;
167                     break;
168                 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE:
169                     // ((org.w3c.dom.ProcessingInstruction)node).getTarget();
170
// ((org.w3c.dom.ProcessingInstruction)node).getData();
171
break;
172             }
173         }
174     }
175     
176     /** Scan through org.w3c.dom.Element named reason. */
177     void visitElement_reason(org.w3c.dom.Element JavaDoc element) { // <reason>
178
testCase.setFailReason(element.getNodeValue()); //??Here or in TEXT_NODE ??
179
org.w3c.dom.NodeList JavaDoc nodes = element.getChildNodes();
180         for (int i = 0; i < nodes.getLength(); i++) {
181             org.w3c.dom.Node JavaDoc node = nodes.item(i);
182             switch (node.getNodeType()) {
183                 case org.w3c.dom.Node.CDATA_SECTION_NODE:
184                     // ((org.w3c.dom.CDATASection)node).getData();
185
break;
186                 case org.w3c.dom.Node.ELEMENT_NODE:
187                     org.w3c.dom.Element JavaDoc nodeElement = (org.w3c.dom.Element JavaDoc)node;
188                     break;
189                 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE:
190                     // ((org.w3c.dom.ProcessingInstruction)node).getTarget();
191
// ((org.w3c.dom.ProcessingInstruction)node).getData();
192
break;
193                 case org.w3c.dom.Node.TEXT_NODE:
194                     // ((org.w3c.dom.Text)node).getData();
195
break;
196             }
197         }
198     }
199     
200     /** Scan through org.w3c.dom.Element named test-case. */
201     void visitElement_test_case(org.w3c.dom.Element JavaDoc element) { // <test-case>
202
// element.getValue();
203
testCase = new IndentCoreGenerator.TestCase();
204         org.w3c.dom.NamedNodeMap JavaDoc attrs = element.getAttributes();
205         for (int i = 0; i < attrs.getLength(); i++) {
206             org.w3c.dom.Attr JavaDoc attr = (org.w3c.dom.Attr JavaDoc)attrs.item(i);
207             if (attr.getName().equals("name")) { // <test-case name="???">
208
testCase.setName(attr.getValue());
209             }
210         }
211         org.w3c.dom.NodeList JavaDoc nodes = element.getChildNodes();
212         for (int i = 0; i < nodes.getLength(); i++) {
213             org.w3c.dom.Node JavaDoc node = nodes.item(i);
214             switch (node.getNodeType()) {
215                 case org.w3c.dom.Node.CDATA_SECTION_NODE:
216                     // ((org.w3c.dom.CDATASection)node).getData();
217
break;
218                 case org.w3c.dom.Node.ELEMENT_NODE:
219                     org.w3c.dom.Element JavaDoc nodeElement = (org.w3c.dom.Element JavaDoc)node;
220                     if (nodeElement.getTagName().equals("fail")) {
221                         visitElement_fail(nodeElement);
222                     }
223                     if (nodeElement.getTagName().equals("indentation-properties")) {
224                         visitElement_indentation_properties(nodeElement);
225                     }
226                     if (nodeElement.getTagName().equals("text")) {
227                         visitElement_text(nodeElement);
228                     }
229                     break;
230                 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE:
231                     // ((org.w3c.dom.ProcessingInstruction)node).getTarget();
232
// ((org.w3c.dom.ProcessingInstruction)node).getData();
233
break;
234             }
235         }
236         IndentCoreGenerator.addTestCase(testCase);
237     }
238     
239     /** Scan through org.w3c.dom.Element named text. */
240     void visitElement_text(org.w3c.dom.Element JavaDoc element) { // <text>
241
// element.getValue();
242
org.w3c.dom.NamedNodeMap JavaDoc attrs = element.getAttributes();
243         for (int i = 0; i < attrs.getLength(); i++) {
244             org.w3c.dom.Attr JavaDoc attr = (org.w3c.dom.Attr JavaDoc)attrs.item(i);
245             if (attr.getName().equals("location")) { // <text location="???">
246
testCase.setTextLocation(attr.getValue());
247             }
248             if (attr.getName().equals("mime-type")) { // <text mime-type="???">
249
testCase.setTextMIMEType(attr.getValue());
250             }
251         }
252         org.w3c.dom.NodeList JavaDoc nodes = element.getChildNodes();
253         for (int i = 0; i < nodes.getLength(); i++) {
254             org.w3c.dom.Node JavaDoc node = nodes.item(i);
255             switch (node.getNodeType()) {
256                 case org.w3c.dom.Node.CDATA_SECTION_NODE:
257                     // ((org.w3c.dom.CDATASection)node).getData();
258
break;
259                 case org.w3c.dom.Node.ELEMENT_NODE:
260                     org.w3c.dom.Element JavaDoc nodeElement = (org.w3c.dom.Element JavaDoc)node;
261                     break;
262                 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE:
263                     // ((org.w3c.dom.ProcessingInstruction)node).getTarget();
264
// ((org.w3c.dom.ProcessingInstruction)node).getData();
265
break;
266             }
267         }
268     }
269     
270     
271 }
272
Popular Tags