1 package com.thoughtworks.xstream.io.xml; 2 3 import com.thoughtworks.xstream.io.HierarchicalStreamWriter; 4 import com.thoughtworks.xstream.io.xml.xppdom.Xpp3Dom; 5 6 import java.util.LinkedList ; 7 8 public class XppDomWriter 9 implements HierarchicalStreamWriter { 10 private LinkedList elementStack = new LinkedList (); 11 12 private Xpp3Dom configuration; 13 14 public XppDomWriter() { 15 } 16 17 public Xpp3Dom getConfiguration() { 18 return configuration; 19 } 20 21 public void startNode(String name) { 22 Xpp3Dom configuration = new Xpp3Dom(name); 23 24 if (this.configuration == null) { 25 this.configuration = configuration; 26 } else { 27 top().addChild(configuration); 28 } 29 30 elementStack.addLast(configuration); 31 } 32 33 public void setValue(String text) { 34 top().setValue(text); 35 } 36 37 public void addAttribute(String key, String value) { 38 top().setAttribute(key, value); 39 } 40 41 public void endNode() { 42 elementStack.removeLast(); 43 } 44 45 private Xpp3Dom top() { 46 return (Xpp3Dom) elementStack.getLast(); 47 } 48 } 49 | Popular Tags |