1 16 17 package org.apache.xerces.impl.xs.opti; 18 19 import org.w3c.dom.Attr ; 20 import org.w3c.dom.Document ; 21 import org.w3c.dom.NamedNodeMap ; 22 import org.w3c.dom.Node ; 23 24 32 public class ElementImpl extends DefaultElement { 33 34 SchemaDOM schemaDOM; 35 Attr [] attrs; 36 int row; 37 int col; 38 int parentRow; 39 40 int line; 41 int column; 42 int charOffset; 43 String fSyntheticAnnotation; 44 45 public ElementImpl(int line, int column, int offset) { 46 row = -1; 47 col = -1; 48 parentRow = -1; 49 nodeType = Node.ELEMENT_NODE; 50 51 this.line = line; 52 this.column = column; 53 charOffset = offset; 54 } 55 56 public ElementImpl(int line, int column) { 57 this(line, column, -1); 58 } 59 60 61 public ElementImpl(String prefix, String localpart, String rawname, 62 String uri, int line, int column, int offset) { 63 super(prefix, localpart, rawname, uri, Node.ELEMENT_NODE); 64 row = -1; 65 col = -1; 66 parentRow = -1; 67 68 this.line = line; 69 this.column = column; 70 charOffset = offset; 71 } 72 73 public ElementImpl(String prefix, String localpart, String rawname, 74 String uri, int line, int column) { 75 this(prefix, localpart, rawname, uri, line, column, -1); 76 } 77 78 79 83 public Document getOwnerDocument() { 84 return schemaDOM; 85 } 86 87 88 public Node getParentNode() { 89 return schemaDOM.relations[row][0]; 90 } 91 92 93 public boolean hasChildNodes() { 94 if (parentRow == -1) { 95 return false; 96 } 97 else { 98 return true; 99 } 100 } 101 102 103 public Node getFirstChild() { 104 if (parentRow == -1) { 105 return null; 106 } 107 return schemaDOM.relations[parentRow][1]; 108 } 109 110 111 public Node getLastChild() { 112 if (parentRow == -1) { 113 return null; 114 } 115 int i=1; 116 for (; i<schemaDOM.relations[parentRow].length; i++) { 117 if (schemaDOM.relations[parentRow][i] == null) { 118 return schemaDOM.relations[parentRow][i-1]; 119 } 120 } 121 if (i ==1) { 122 i++; 123 } 124 return schemaDOM.relations[parentRow][i-1]; 125 } 126 127 128 public Node getPreviousSibling() { 129 if (col == 1) { 130 return null; 131 } 132 return schemaDOM.relations[row][col-1]; 133 } 134 135 136 public Node getNextSibling() { 137 if (col == schemaDOM.relations[row].length-1) { 138 return null; 139 } 140 return schemaDOM.relations[row][col+1]; 141 } 142 143 144 public NamedNodeMap getAttributes() { 145 return new NamedNodeMapImpl(attrs); 146 } 147 148 149 public boolean hasAttributes() { 150 return (attrs.length == 0 ? false : true); 151 } 152 153 154 155 159 public String getTagName() { 160 return rawname; 161 } 162 163 164 public String getAttribute(String name) { 165 166 for (int i=0; i<attrs.length; i++) { 167 if (attrs[i].getName().equals(name)) { 168 return attrs[i].getValue(); 169 } 170 } 171 return ""; 172 } 173 174 175 public Attr getAttributeNode(String name) { 176 for (int i=0; i<attrs.length; i++) { 177 if (attrs[i].getName().equals(name)) { 178 return attrs[i]; 179 } 180 } 181 return null; 182 } 183 184 185 public String getAttributeNS(String namespaceURI, String localName) { 186 for (int i=0; i<attrs.length; i++) { 187 if (attrs[i].getLocalName().equals(localName) && attrs[i].getNamespaceURI().equals(namespaceURI)) { 188 return attrs[i].getValue(); 189 } 190 } 191 return ""; 192 } 193 194 195 public Attr getAttributeNodeNS(String namespaceURI, String localName) { 196 for (int i=0; i<attrs.length; i++) { 197 if (attrs[i].getName().equals(localName) && attrs[i].getNamespaceURI().equals(namespaceURI)) { 198 return attrs[i]; 199 } 200 } 201 return null; 202 } 203 204 205 public boolean hasAttribute(String name) { 206 for (int i=0; i<attrs.length; i++) { 207 if (attrs[i].getName().equals(name)) { 208 return true; 209 } 210 } 211 return false; 212 } 213 214 215 public boolean hasAttributeNS(String namespaceURI, String localName) { 216 for (int i=0; i<attrs.length; i++) { 217 if (attrs[i].getName().equals(localName) && attrs[i].getNamespaceURI().equals(namespaceURI)) { 218 return true; 219 } 220 } 221 return false; 222 } 223 224 225 public void setAttribute(String name, String value) { 226 for (int i=0; i<attrs.length; i++) { 227 if (attrs[i].getName().equals(name)) { 228 attrs[i].setValue(value); 229 return; 230 } 231 } 232 } 233 234 235 public int getLineNumber() { 236 return line; 237 } 238 239 240 public int getColumnNumber() { 241 return column; 242 } 243 244 245 public int getCharacterOffset() { 246 return charOffset; 247 } 248 249 public String getSyntheticAnnotation() { 250 return fSyntheticAnnotation; 251 } 252 } 253 | Popular Tags |