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: import ;
56:
57: public class IIOMetadataNode
58: implements Element, NodeList
59: {
60: private String name;
61: private HashMap attrs = new HashMap();
62: private List children = new ArrayList();
63: private IIOMetadataNode parent;
64: private Object obj;
65:
66:
71: private class IIONamedNodeMap implements NamedNodeMap
72: {
73: HashMap attrs;
74:
75:
79: public IIONamedNodeMap(HashMap attrs)
80: {
81: this.attrs = attrs;
82: }
83:
84:
87: public Node getNamedItem(String name)
88: {
89: return (Node)attrs.get(name);
90: }
91:
92:
95: public Node setNamedItem(Node arg) throws DOMException
96: {
97: if (arg instanceof IIOMetadataNodeAttr)
98: {
99: IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr) arg;
100:
101: if (attr.owner != null)
102: throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, "");
103: return (Node)attrs.put(attr.name, attr);
104: }
105:
106: throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "");
107: }
108:
109:
112: public Node removeNamedItem(String name) throws DOMException
113: {
114: return (Node)attrs.remove(name);
115: }
116:
117:
120: public Node item(int index)
121: {
122: return (Node)attrs.values().toArray()[index];
123: }
124:
125:
128: public int getLength()
129: {
130: return attrs.size();
131: }
132:
133:
136: public Node getNamedItemNS(String namespaceURI, String localName)
137: {
138: return getNamedItem(localName);
139: }
140:
141:
144: public Node setNamedItemNS(Node arg) throws DOMException
145: {
146: return setNamedItem(arg);
147: }
148:
149:
152: public Node removeNamedItemNS(String namespaceURI, String localName)
153: throws DOMException
154: {
155: return removeNamedItem(localName);
156: }
157: }
158:
159:
165: private class IIONodeList implements NodeList
166: {
167: List children = new ArrayList();
168:
169:
172: public Node item(int index)
173: {
174: return (index < children.size()) ? (Node)children.get(index) : null;
175: }
176:
177:
180: public int getLength()
181: {
182: return children.size();
183: }
184: }
185:
186: public IIOMetadataNode()
187: {
188:
189: }
190:
191: public IIOMetadataNode(String nodename)
192: {
193: name = nodename;
194: }
195:
196: public Object getUserObject()
197: {
198: return obj;
199: }
200:
201: public void setUserObject(Object o)
202: {
203: obj = o;
204: }
205:
206: public short compareDocumentPosition(Node other)
207: throws DOMException
208: {
209: return Element.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
210: }
211:
212:
215: public String getAttribute(String name)
216: {
217: Attr anode = (Attr) attrs.get(name);
218: return anode != null ? anode.getValue() : null;
219: }
220:
221:
224: public Attr getAttributeNode(String name)
225: {
226: String val = getAttribute(name);
227: if (val != null)
228: return new IIOMetadataNodeAttr(this, name, val);
229: return null;
230: }
231:
232:
235: public Attr getAttributeNodeNS(String namespaceURI, String localName)
236: {
237: return getAttributeNode(localName);
238: }
239:
240:
243: public String getAttributeNS(String namespaceURI, String localName)
244: {
245: return getAttribute(localName);
246: }
247:
248: public String getBaseURI()
249: {
250: return null;
251: }
252:
253:
254: private void getElementsRecurse(IIONodeList list, String name)
255: {
256: for (int i=0; i < children.size(); i++)
257: {
258: if (((Node)children.get(i)).getNodeName().equals(name))
259: list.children.add(children.get(i));
260: getElementsRecurse(list, name);
261: }
262: }
263:
264:
267: public NodeList getElementsByTagName(String name)
268: {
269: IIONodeList list = new IIONodeList();
270: getElementsRecurse(list, name);
271: return list;
272: }
273:
274:
277: public NodeList getElementsByTagNameNS(String namespaceURI, String localName)
278: {
279: IIONodeList list = new IIONodeList();
280: getElementsRecurse(list, name);
281: return list;
282: }
283:
284:
287: public String getTagName()
288: {
289: return name;
290: }
291:
292:
295: public boolean hasAttribute(String name)
296: {
297: return attrs.containsKey(name);
298: }
299:
300:
303: public boolean hasAttributeNS(String namespaceURI, String localName)
304: {
305: return attrs.containsKey(localName);
306: }
307:
308:
311: public void removeAttribute(String name)
312: {
313: attrs.remove(name);
314: }
315:
316:
319: public Attr removeAttributeNode(Attr oldAttr)
320: {
321: return (Attr)attrs.remove(oldAttr.getName());
322: }
323:
324:
327: public void removeAttributeNS(String namespaceURI, String localName)
328: {
329: removeAttribute(localName);
330: }
331:
332:
335: public void setAttribute(String name, String value)
336: {
337: Attr attr = getAttributeNode(name);
338: if (attr != null)
339: attr.setValue(value);
340: else
341: attrs.put(name, new IIOMetadataNodeAttr(this, name, value));
342: }
343:
344:
347: public Attr setAttributeNode(Attr newAttr)
348: {
349: return (Attr)attrs.put(newAttr.getName(), newAttr);
350: }
351:
352:
355: public Attr setAttributeNodeNS(Attr newAttr)
356: {
357: return (Attr)attrs.put(newAttr.getName(), newAttr);
358: }
359:
360:
363: public void setAttributeNS(String namespaceURI, String qualifiedName, String value)
364: {
365: setAttribute(qualifiedName, value);
366: }
367:
368:
371: public int getLength()
372: {
373: return children.size();
374: }
375:
376:
379: public Node item(int index)
380: {
381: if (index < children.size())
382: return (Node)children.get(index);
383: else
384: return null;
385: }
386:
387:
390: public Node appendChild(Node newChild)
391: {
392: if (newChild == null)
393: throw new IllegalArgumentException("Child node is null");
394:
395: IIOMetadataNode child = (IIOMetadataNode) newChild;
396:
397: children.add(child);
398: child.parent = this;
399: return this;
400: }
401:
402:
405: public Node cloneNode(boolean deep)
406: {
407: IIOMetadataNode newnode = new IIOMetadataNode(name);
408: newnode.parent = null;
409: newnode.obj = obj;
410: if (deep)
411: {
412: for (int i=0; i < children.size(); i++)
413: newnode.children.add(((Node)children.get(i)).cloneNode(deep));
414: }
415:
416:
417: for (Iterator it = attrs.values().iterator(); it.hasNext();)
418: {
419: IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr)it.next();
420: newnode.attrs.put(attr.name, attr.cloneNode(deep));
421: attr.owner = newnode;
422: }
423:
424: return newnode;
425: }
426:
427:
430: public NamedNodeMap getAttributes()
431: {
432: return new IIONamedNodeMap(attrs);
433: }
434:
435:
438: public NodeList getChildNodes()
439: {
440: return this;
441: }
442:
443: public Object getFeature(String feature, String version)
444: {
445: return null;
446: }
447:
448:
451: public Node getFirstChild()
452: {
453: return (children.size() > 0) ? (Node)children.get(0) : null;
454: }
455:
456:
459: public Node getLastChild()
460: {
461: return (children.size() > 0) ? (Node)children.get(children.size() - 1)
462: : null;
463: }
464:
465:
468: public String getLocalName()
469: {
470: return name;
471: }
472:
473:
476: public String getNamespaceURI()
477: {
478: return null;
479: }
480:
481:
484: public Node getNextSibling()
485: {
486:
487: if (parent == null) return null;
488: int idx = parent.children.indexOf(this);
489: return (idx == parent.children.size() - 1) ? null
490: : (Node)parent.children.get(idx + 1);
491: }
492:
493:
496: public String getNodeName()
497: {
498: return name;
499: }
500:
501:
504: public short getNodeType()
505: {
506: return ELEMENT_NODE;
507: }
508:
509:
512: public String getNodeValue()
513: {
514: return null;
515: }
516:
517:
520: public Document getOwnerDocument()
521: {
522:
523: return null;
524: }
525:
526:
529: public Node getParentNode()
530: {
531: return parent;
532: }
533:
534:
537: public String getPrefix()
538: {
539: return null;
540: }
541:
542:
545: public Node getPreviousSibling()
546: {
547:
548: if (parent == null) return null;
549: int idx = parent.children.indexOf(this);
550: return (idx == 0) ? null
551: : (Node)parent.children.get(idx - 1);
552: }
553:
554: public TypeInfo getSchemaTypeInfo()
555: {
556: return null;
557: }
558:
559: public String getTextContent()
560: throws DOMException
561: {
562: return null;
563: }
564:
565: public Object getUserData(String key)
566: {
567: return null;
568: }
569:
570:
573: public boolean hasAttributes()
574: {
575: return !attrs.isEmpty();
576: }
577:
578:
581: public boolean hasChildNodes()
582: {
583: return !children.isEmpty();
584: }
585:
586:
589: public Node insertBefore(Node newChild, Node refChild)
590: {
591: if (newChild == null)
592: throw new IllegalArgumentException();
593:
594: int idx = children.indexOf(refChild);
595: if (idx == -1)
596: children.add(newChild);
597: else
598: children.add(idx, newChild);
599: ((IIOMetadataNode)newChild).parent = this;
600:
601: return newChild;
602: }
603:
604: public boolean isDefaultNamespace(String namespaceURI)
605: {
606: return true;
607: }
608:
609: public boolean isEqualNode(Node arg)
610: {
611: return true;
612: }
613:
614: public boolean isSameNode(Node other)
615: {
616: return this == other;
617: }
618:
619:
622: public boolean isSupported(String feature, String version)
623: {
624:
625: return false;
626: }
627:
628: public String lookupNamespaceURI(String prefix)
629: {
630: return null;
631: }
632:
633: public String lookupPrefix(String namespaceURI)
634: {
635: return null;
636: }
637:
638:
641: public void normalize()
642: {
643:
644: }
645:
646:
649: public Node removeChild(Node oldChild)
650: {
651: if (oldChild == null)
652: throw new IllegalArgumentException();
653: children.remove(oldChild);
654: ((IIOMetadataNode)oldChild).parent = null;
655:
656: return oldChild;
657: }
658:
659:
662: public Node replaceChild(Node newChild, Node oldChild)
663: {
664: if (newChild == null)
665: throw new IllegalArgumentException();
666: children.set(children.indexOf(oldChild), newChild);
667: ((IIOMetadataNode)oldChild).parent = null;
668: return oldChild;
669: }
670:
671: public void setIdAttribute(String name, boolean isId)
672: throws DOMException
673: {
674: }
675:
676: public void setIdAttributeNode(Attr idAttr, boolean isId)
677: throws DOMException
678: {
679: }
680:
681: public void setIdAttributeNS(String namespaceURI, String localName, boolean isId)
682: throws DOMException
683: {
684: }
685:
686:
689: public void setNodeValue(String nodeValue) throws DOMException
690: {
691: }
692:
693:
696: public void setPrefix(String prefix)
697: {
698: }
699:
700: public void setTextContent(String textContent)
701: throws DOMException
702: {
703: }
704:
705: public Object setUserData(String key, Object data, UserDataHandler handler)
706: {
707: return null;
708: }
709: }