1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45:
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55:
56: public class IIOMetadataNode
57: implements Element, NodeList
58: {
59: private String name;
60: private HashMap attrs = new HashMap();
61: private List children = new ArrayList();
62: private IIOMetadataNode parent;
63: private Object obj;
64:
65: public IIOMetadataNode()
66: {
67:
68: }
69:
70: public IIOMetadataNode(String nodename)
71: {
72: name = nodename;
73: }
74:
75: public Object getUserObject()
76: {
77: return obj;
78: }
79:
80: public void setUserObject(Object o)
81: {
82: obj = o;
83: }
84:
85: public short compareDocumentPosition(Node other)
86: throws DOMException
87: {
88: throw new Error("not implemented");
89: }
90:
91:
94: public String getAttribute(String name)
95: {
96: Attr anode = (Attr) attrs.get(name);
97: return anode != null ? anode.getValue() : null;
98: }
99:
100:
103: public Attr getAttributeNode(String name)
104: {
105: String val = getAttribute(name);
106: if (val != null)
107: return new IIOAttr(name, val, this);
108: return null;
109: }
110:
111:
114: public Attr getAttributeNodeNS(String namespaceURI, String localName)
115: {
116: return getAttributeNode(localName);
117: }
118:
119:
122: public String getAttributeNS(String namespaceURI, String localName)
123: {
124: return getAttribute(localName);
125: }
126:
127: public String getBaseURI()
128: {
129: throw new Error("not implemented");
130: }
131:
132:
133: private void getElementsRecurse(IIONodeList list, String name)
134: {
135: for (int i=0; i < children.size(); i++)
136: {
137: if (((Node)children.get(i)).getNodeName().equals(name))
138: list.children.add(children.get(i));
139: getElementsRecurse(list, name);
140: }
141: }
142:
143:
146: public NodeList getElementsByTagName(String name)
147: {
148: IIONodeList list = new IIONodeList();
149: getElementsRecurse(list, name);
150: return list;
151: }
152:
153:
156: public NodeList getElementsByTagNameNS(String namespaceURI, String localName)
157: {
158: IIONodeList list = new IIONodeList();
159: getElementsRecurse(list, name);
160: return list;
161: }
162:
163:
166: public String getTagName()
167: {
168: return name;
169: }
170:
171:
174: public boolean hasAttribute(String name)
175: {
176: return attrs.containsKey(name);
177: }
178:
179:
182: public boolean hasAttributeNS(String namespaceURI, String localName)
183: {
184: return attrs.containsKey(localName);
185: }
186:
187:
190: public void removeAttribute(String name)
191: {
192: attrs.remove(name);
193: }
194:
195:
198: public Attr removeAttributeNode(Attr oldAttr)
199: {
200: return (Attr)attrs.remove(oldAttr.getName());
201: }
202:
203:
206: public void removeAttributeNS(String namespaceURI, String localName)
207: {
208: removeAttribute(localName);
209: }
210:
211:
214: public void setAttribute(String name, String value)
215: {
216: Attr attr = (Attr) getAttributeNode(name);
217: if (attr != null)
218: attr.setValue(value);
219: else
220: attrs.put(name, new IIOAttr(name, value, this));
221: }
222:
223:
226: public Attr setAttributeNode(Attr newAttr)
227: {
228: return (Attr)attrs.put(newAttr.getName(), newAttr);
229: }
230:
231:
234: public Attr setAttributeNodeNS(Attr newAttr)
235: {
236: return (Attr)attrs.put(newAttr.getName(), newAttr);
237: }
238:
239:
242: public void setAttributeNS(String namespaceURI, String qualifiedName, String value)
243: {
244: setAttribute(qualifiedName, value);
245: }
246:
247:
250: public int getLength()
251: {
252: return children.size();
253: }
254:
255:
258: public Node item(int index)
259: {
260: if (index < children.size())
261: return (Node)children.get(index);
262: else
263: return null;
264: }
265:
266:
269: public Node appendChild(Node newChild)
270: {
271: if (newChild == null)
272: throw new IllegalArgumentException("Child node is null");
273:
274: IIOMetadataNode child = (IIOMetadataNode) newChild;
275:
276: children.add(child);
277: child.parent = this;
278: return this;
279: }
280:
281:
284: public Node cloneNode(boolean deep)
285: {
286: IIOMetadataNode newnode = new IIOMetadataNode(name);
287: newnode.parent = null;
288: newnode.obj = obj;
289: if (deep)
290: {
291: for (int i=0; i < children.size(); i++)
292: newnode.children.add(((Node)children.get(i)).cloneNode(deep));
293: }
294:
295:
296: for (Iterator it = attrs.values().iterator(); it.hasNext();)
297: {
298: IIOAttr attr = (IIOAttr)it.next();
299: newnode.attrs.put(attr.name, attr.cloneNode(deep));
300: attr.owner = newnode;
301: }
302:
303: return newnode;
304: }
305:
306:
309: public NamedNodeMap getAttributes()
310: {
311: return new IIONamedNodeMap(attrs);
312: }
313:
314:
317: public NodeList getChildNodes()
318: {
319: return this;
320: }
321:
322: public Object getFeature(String feature, String version)
323: {
324: throw new Error("not implemented");
325: }
326:
327:
330: public Node getFirstChild()
331: {
332: return (children.size() > 0) ? (Node)children.get(0) : null;
333: }
334:
335:
338: public Node getLastChild()
339: {
340: return (children.size() > 0) ? (Node)children.get(children.size() - 1)
341: : null;
342: }
343:
344:
347: public String getLocalName()
348: {
349: return name;
350: }
351:
352:
355: public String getNamespaceURI()
356: {
357: return null;
358: }
359:
360:
363: public Node getNextSibling()
364: {
365:
366: if (parent == null) return null;
367: int idx = parent.children.indexOf(this);
368: return (idx == parent.children.size() - 1) ? null
369: : (Node)parent.children.get(idx + 1);
370: }
371:
372:
375: public String getNodeName()
376: {
377: return name;
378: }
379:
380:
383: public short getNodeType()
384: {
385: return ELEMENT_NODE;
386: }
387:
388:
391: public String getNodeValue()
392: {
393: return null;
394: }
395:
396:
399: public Document getOwnerDocument()
400: {
401:
402: return null;
403: }
404:
405:
408: public Node getParentNode()
409: {
410: return parent;
411: }
412:
413:
416: public String getPrefix()
417: {
418: return null;
419: }
420:
421:
424: public Node getPreviousSibling()
425: {
426:
427: if (parent == null) return null;
428: int idx = parent.children.indexOf(this);
429: return (idx == 0) ? null
430: : (Node)parent.children.get(idx - 1);
431: }
432:
433: public TypeInfo getSchemaTypeInfo()
434: {
435: throw new Error("not implemented");
436: }
437:
438: public String getTextContent()
439: throws DOMException
440: {
441: throw new Error("not implemented");
442: }
443:
444: public Object getUserData(String key)
445: {
446: throw new Error("not implemented");
447: }
448:
449:
452: public boolean hasAttributes()
453: {
454: return !attrs.isEmpty();
455: }
456:
457:
460: public boolean hasChildNodes()
461: {
462: return !children.isEmpty();
463: }
464:
465:
468: public Node insertBefore(Node newChild, Node refChild)
469: {
470: if (newChild == null)
471: throw new IllegalArgumentException();
472:
473: int idx = children.indexOf(refChild);
474: if (idx == -1)
475: children.add(newChild);
476: else
477: children.add(idx, newChild);
478: ((IIOMetadataNode)newChild).parent = this;
479:
480: return newChild;
481: }
482:
483: public boolean isDefaultNamespace(String namespaceURI)
484: {
485: throw new Error("not implemented");
486: }
487:
488: public boolean isEqualNode(Node arg)
489: {
490: throw new Error("not implemented");
491: }
492:
493: public boolean isSameNode(Node other)
494: {
495: return this == other;
496: }
497:
498:
501: public boolean isSupported(String feature, String version)
502: {
503:
504: return false;
505: }
506:
507: public String lookupNamespaceURI(String prefix)
508: {
509: throw new Error("not implemented");
510: }
511:
512: public String lookupPrefix(String namespaceURI)
513: {
514: throw new Error("not implemented");
515: }
516:
517:
520: public void normalize()
521: {
522:
523: }
524:
525:
528: public Node removeChild(Node oldChild)
529: {
530: if (oldChild == null)
531: throw new IllegalArgumentException();
532: children.remove(oldChild);
533: ((IIOMetadataNode)oldChild).parent = null;
534:
535: return oldChild;
536: }
537:
538:
541: public Node replaceChild(Node newChild, Node oldChild)
542: {
543: if (newChild == null)
544: throw new IllegalArgumentException();
545: children.set(children.indexOf(oldChild), newChild);
546: ((IIOMetadataNode)oldChild).parent = null;
547: return oldChild;
548: }
549:
550: public void setIdAttribute(String name, boolean isId)
551: throws DOMException
552: {
553: throw new Error("not implemented");
554: }
555:
556: public void setIdAttributeNode(Attr idAttr, boolean isId)
557: throws DOMException
558: {
559: throw new Error("not implemented");
560: }
561:
562: public void setIdAttributeNS(String namespaceURI, String localName, boolean isId)
563: throws DOMException
564: {
565: throw new Error("not implemented");
566: }
567:
568:
571: public void setNodeValue(String nodeValue) throws DOMException
572: {
573: }
574:
575:
578: public void setPrefix(String prefix)
579: {
580: }
581:
582: public void setTextContent(String textContent)
583: throws DOMException
584: {
585: throw new Error("not implemented");
586: }
587:
588: public Object setUserData(String key, Object data, UserDataHandler handler)
589: {
590: throw new Error("not implemented");
591: }
592: }