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 ; 8 9 13 public class XppDomReader 14 implements HierarchicalStreamReader { 15 private Xpp3Dom current; 16 17 private LinkedList pointers = new LinkedList (); 18 19 public XppDomReader(Xpp3Dom xpp3Dom) { 20 current = xpp3Dom; 21 22 pointers.addLast(new Pointer()); 23 } 24 25 public String getNodeName() { 26 return current.getName(); 27 } 28 29 public String getValue() { 30 String text = null; 31 32 try { 33 text = current.getValue(); 34 } catch (Exception e) { 35 } 37 38 return text == null ? "" : text; 39 } 40 41 public String getAttribute(String attributeName) { 42 String text = null; 43 44 try { 45 text = current.getAttribute(attributeName); 46 } catch (Exception e) { 47 } 49 50 return text; 51 } 52 53 public Object 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 |