1 8 9 package org.apache.slide.util.conf; 10 11 import java.util.*; 12 13 15 public class Element { 16 17 private String name; 18 private Hashtable attributes; 19 private Vector children; 20 private String data; 21 private String comment; 22 private Element parent; 23 24 public Element getParent() { 25 return parent; 26 } 27 28 public String getName() { 29 return name; 30 } 31 32 public void setName(String s) { 33 name = new String (s); 34 } 35 36 public boolean hasAttributes() { 37 return !attributes.isEmpty(); 38 } 39 40 public Enumeration getAttributeNames() { 41 return attributes.keys(); 42 } 43 44 public String getAttributeValue(String s) { 45 return (String ) attributes.get(s); 46 } 47 48 public void setAttribute(String s, String s1) { 49 attributes.put(s, s1); 50 } 51 52 public void removeAttribute(String s) { 53 attributes.remove(s); 54 } 55 56 public void clearAttributes() { 57 attributes.clear(); 58 } 59 60 public Enumeration getChildren() { 61 return children.elements(); 62 } 63 64 public Enumeration getChildren(String s) { 65 Vector vector = new Vector(); 66 for(Enumeration enumeration = getChildren(); enumeration.hasMoreElements();) { 67 Element element = (Element) enumeration.nextElement(); 68 if(element.getName().equals(s)) 69 vector.addElement(element); 70 } 71 return vector.elements(); 72 } 73 74 public Element getChild(String name) { 75 Enumeration enumeration = getChildren(name); 76 if (!enumeration.hasMoreElements()) { 77 return null; 78 } 79 return (Element) enumeration.nextElement(); 80 } 81 82 public boolean hasChildren() { 83 return !children.isEmpty(); 84 } 85 86 public int countChildren() { 87 return children.size(); 88 } 89 90 public void addChild(Element element) 91 throws NullPointerException { 92 if(element == null) { 93 throw new NullPointerException ("Child cannot be null"); 94 } 95 children.addElement(element); 96 } 97 98 public void clearChildren() { 99 children.removeAllElements(); 100 } 101 102 public String getData() { 103 return data; 104 } 105 106 public void setData(Object s) { 107 data = new String (s.toString()).trim(); 108 } 109 110 public void clearData() { 111 data = new String (); 112 } 113 114 public String getComment() { 115 return comment; 116 } 117 118 public void setComment(String s) { 119 comment = new String (s); 120 } 121 122 public void clearComment() { 123 comment = new String (); 124 } 125 126 public Element() { 127 this("", null); 128 } 129 130 public Element(String s, Element parent) { 131 this.parent = parent; 132 name = new String (s); 133 attributes = new Hashtable(); 134 children = new Vector(); 135 data = new String (); 136 comment = new String (); 137 } 138 139 public String toString() { 140 StringBuffer buffer = new StringBuffer (); 141 buffer.append("Name=" + name); 142 buffer.append(" Data=" + data); 143 for (Enumeration e = getChildren(); e.hasMoreElements(); ) { 144 Element el = (Element) e.nextElement(); 145 buffer.append(" " + el.toString()); 146 } 147 return buffer.toString(); 148 } 149 } 150 | Popular Tags |