1 package com.thoughtworks.xstream.io.xml; 2 3 import org.jdom.Document; 4 import org.jdom.Element; 5 import org.jdom.Parent; 6 import org.jdom.Attribute; 7 8 11 public class JDomReader extends AbstractDocumentReader { 12 13 private Element currentElement; 14 15 public JDomReader(Element root) { 16 super(root); 17 } 18 19 public JDomReader(Document document) { 20 super(document.getRootElement()); 21 } 22 23 protected void reassignCurrentElement(Object current) { 24 currentElement = (Element) current; 25 } 26 27 protected Object getParent() { 28 return currentElement.getParentElement(); 30 31 35 } 38 39 protected Object getChild(int index) { 40 return currentElement.getChildren().get(index); 41 } 42 43 protected int getChildCount() { 44 return currentElement.getChildren().size(); 45 } 46 47 public String getNodeName() { 48 return currentElement.getName(); 49 } 50 51 public String getValue() { 52 return currentElement.getText(); 53 } 54 55 public String getAttribute(String name) { 56 return currentElement.getAttributeValue(name); 57 } 58 59 public String getAttribute(int index) { 60 return ((Attribute) currentElement.getAttributes().get(index)).getValue(); 61 } 62 63 public int getAttributeCount() { 64 return currentElement.getAttributes().size(); 65 } 66 67 public String getAttributeName(int index) { 68 return ((Attribute) currentElement.getAttributes().get(index)).getQualifiedName(); 69 } 70 } 71 72 | Popular Tags |