1 package com.thoughtworks.xstream.io.xml.xppdom; 2 3 import java.util.ArrayList ; 4 import java.util.HashMap ; 5 import java.util.List ; 6 import java.util.Map ; 7 8 public class Xpp3Dom { 9 protected String name; 10 11 protected String value; 12 13 protected Map attributes; 14 15 protected List childList; 16 17 protected Map childMap; 18 19 protected Xpp3Dom parent; 20 21 public Xpp3Dom(String name) { 22 this.name = name; 23 childList = new ArrayList (); 24 childMap = new HashMap (); 25 } 26 27 31 public String getName() { 32 return name; 33 } 34 35 39 public String getValue() { 40 return value; 41 } 42 43 public void setValue(String value) { 44 this.value = value; 45 } 46 47 51 public String [] getAttributeNames() { 52 if ( null == attributes ) { 53 return new String [0]; 54 } 55 else { 56 return (String []) attributes.keySet().toArray( new String [0] ); 57 } 58 } 59 60 public String getAttribute(String name) { 61 return (null != attributes) ? (String ) attributes.get(name) : null; 62 } 63 64 public void setAttribute(String name, String value) { 65 if (null == attributes) { 66 attributes = new HashMap (); 67 } 68 69 attributes.put(name, value); 70 } 71 72 76 public Xpp3Dom getChild(int i) { 77 return (Xpp3Dom) childList.get(i); 78 } 79 80 public Xpp3Dom getChild(String name) { 81 return (Xpp3Dom) childMap.get(name); 82 } 83 84 public void addChild(Xpp3Dom xpp3Dom) { 85 xpp3Dom.setParent(this); 86 childList.add(xpp3Dom); 87 childMap.put(xpp3Dom.getName(), xpp3Dom); 88 } 89 90 public Xpp3Dom[] getChildren() { 91 if ( null == childList ) { 92 return new Xpp3Dom[0]; 93 } 94 else { 95 return (Xpp3Dom[]) childList.toArray( new Xpp3Dom[0] ); 96 } 97 } 98 99 public Xpp3Dom[] getChildren( String name ) { 100 if ( null == childList ) { 101 return new Xpp3Dom[0]; 102 } 103 else { 104 ArrayList children = new ArrayList (); 105 int size = this.childList.size(); 106 107 for ( int i = 0; i < size; i++ ) { 108 Xpp3Dom configuration = (Xpp3Dom) this.childList.get( i ); 109 if ( name.equals( configuration.getName() ) ) { 110 children.add( configuration ); 111 } 112 } 113 114 return (Xpp3Dom[]) children.toArray( new Xpp3Dom[0] ); 115 } 116 } 117 118 public int getChildCount() { 119 if (null == childList) { 120 return 0; 121 } 122 123 return childList.size(); 124 } 125 126 130 public Xpp3Dom getParent() { 131 return parent; 132 } 133 134 public void setParent(Xpp3Dom parent) { 135 this.parent = parent; 136 } 137 } 138 | Popular Tags |