KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > io > xml > XppDomReader


1 package com.thoughtworks.xstream.io.xml;
2
3 import com.thoughtworks.xstream.converters.ErrorWriter;
4 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
5 import com.thoughtworks.xstream.io.xml.xppdom.Xpp3Dom;
6
7 import java.util.LinkedList JavaDoc;
8
9 /**
10  * @author <a HREF="mailto:jason@maven.org">Jason van Zyl</a>
11  * @version $Id: XppDomReader.java,v 1.2 2004/05/08 17:51:19 joe Exp $
12  */

13 public class XppDomReader
14         implements HierarchicalStreamReader {
15     private Xpp3Dom current;
16
17     private LinkedList JavaDoc pointers = new LinkedList JavaDoc();
18
19     public XppDomReader(Xpp3Dom xpp3Dom) {
20         current = xpp3Dom;
21
22         pointers.addLast(new Pointer());
23     }
24
25     public String JavaDoc getNodeName() {
26         return current.getName();
27     }
28
29     public String JavaDoc getValue() {
30         String JavaDoc text = null;
31
32         try {
33             text = current.getValue();
34         } catch (Exception JavaDoc e) {
35             // do nothing.
36
}
37
38         return text == null ? "" : text;
39     }
40
41     public String JavaDoc getAttribute(String JavaDoc attributeName) {
42         String JavaDoc text = null;
43
44         try {
45             text = current.getAttribute(attributeName);
46         } catch (Exception JavaDoc e) {
47             // do nothing.
48
}
49
50         return text;
51     }
52
53     public Object JavaDoc peekUnderlyingNode() {
54         return current;
55     }
56
57     private class Pointer {
58         public int v;
59     }
60
61     public boolean hasMoreChildren() {
62         Pointer pointer = (Pointer) pointers.getLast();
63
64         if (pointer.v < current.getChildCount()) {
65             return true;
66         } else {
67             return false;
68         }
69     }
70
71     public void moveUp() {
72         current = current.getParent();
73
74         pointers.removeLast();
75     }
76
77     public void moveDown() {
78         Pointer pointer = (Pointer) pointers.getLast();
79         pointers.addLast(new Pointer());
80
81         current = current.getChild(pointer.v);
82
83         pointer.v++;
84
85     }
86
87     public void appendErrors(ErrorWriter errorWriter) {
88     }
89 }
90
Popular Tags