001: package com.rimfaxe.xml.compatibility;
002:
003: import org.w3c.dom.NamedNodeMap;
004: import org.w3c.dom.Node;
005: import org.w3c.dom.DOMException;
006: import java.util.*;
007:
008: /**
009: * Wrapper around set of {@link org.w3c.dom.Attr}s.
010:
011: <blockquote><small> Copyright (C) 2002 Hewlett-Packard Company.
012: This file is part of Sparta, an XML Parser, DOM, and XPath library.
013: This library is free software; you can redistribute it and/or
014: modify it under the terms of the <a href="doc-files/LGPL.txt">GNU
015: Lesser General Public License</a> as published by the Free Software
016: Foundation; either version 2.1 of the License, or (at your option)
017: any later version. This library is distributed in the hope that it
018: will be useful, but WITHOUT ANY WARRANTY; without even the implied
019: warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
020: PURPOSE. </small></blockquote>
021: @version $Date: 2003/01/27 23:30:58 $ $Revision: 1.2 $
022: @author Eamonn O'Brien-Strain
023: @author Sergio Marti
024: * add Observer pattern
025: * @stereotype container
026: */
027:
028: public class NamedNodeMapImpl implements NamedNodeMap {
029:
030: NamedNodeMapImpl(ElementImpl wrapperElement) {
031: wrapperElement_ = wrapperElement;
032: com.rimfaxe.xml.xmlreader.Element spartanElement = wrapperElement
033: .getSpartanElement();
034: Map orderHack = new TreeMap();
035: for (Enumeration i = spartanElement.getAttributeNames(); i
036: .hasMoreElements();) {
037: String name = (String) i.nextElement();
038: String value = spartanElement.getAttribute(name);
039: AttrImpl attr = new AttrImpl(wrapperElement, name, value);
040: //vector_.add( attr );
041: orderHack.put(name, attr);
042: dict_.put(name, attr);
043: }
044: //This is a hack to get the same order as Xerces for easier
045: //diff testing
046: for (Iterator i = orderHack.keySet().iterator(); i.hasNext();)
047: vector_.addElement(orderHack.get(i.next()));
048: }
049:
050: public int getLength() {
051: return dict_.size();
052: }
053:
054: public Node getNamedItem(String name) {
055: return (AttrImpl) dict_.get(name);
056: }
057:
058: public Node getNamedItemNS(String parm1, String parm2) {
059: /**@todo: Implement this org.w3c.dom.NamedNodeMap method*/
060: throw new Error("not implemented: getNamedItemNS");
061: }
062:
063: public Node item(int i) {
064: return (AttrImpl) vector_.elementAt(i);
065: }
066:
067: public Node removeNamedItem(String name) throws DOMException {
068: wrapperElement_.removeAttribute(name);
069: vector_.removeElement(dict_.get(name));
070: return (Node) dict_.remove(name);
071: }
072:
073: public Node removeNamedItemNS(String parm1, String parm2)
074: throws DOMException {
075: /**@todo: Implement this org.w3c.dom.NamedNodeMap method*/
076: throw new Error("not implemented: removeNamedItemNS");
077: }
078:
079: public Node setNamedItem(Node parm1) throws DOMException {
080: /**@todo: Implement this org.w3c.dom.NamedNodeMap method*/
081: throw new Error("not implemented: setNamedItem");
082: }
083:
084: public Node setNamedItemNS(Node parm1) throws DOMException {
085: /**@todo: Implement this org.w3c.dom.NamedNodeMap method*/
086: throw new Error("not implemented: setNamedItemNS");
087: }
088:
089: /** @associates AttrImpl */
090: private final Map dict_ = new HashMap();
091: private final Vector vector_ = new Vector();
092: private final ElementImpl wrapperElement_;
093: }
094:
095: // $Log: NamedNodeMapImpl.java,v $
096: // Revision 1.2 2003/01/27 23:30:58 yuhongx
097: // Replaced Hashtable with HashMap.
098: //
099: // Revision 1.1.1.1 2002/08/19 05:04:16 eobrain
100: // import from HP Labs internal CVS
101: //
102: // Revision 1.8 2002/08/19 00:39:07 eob
103: // Tweak javadoc comment.
104: //
105: // Revision 1.7 2002/08/18 05:45:54 eob
106: // Add copyright and other formatting and commenting in preparation for
107: // release to SourceForge.
108: //
109: // Revision 1.6 2002/06/21 00:33:06 eob
110: // Make work with old JDK 1.1.*
111: //
112: // Revision 1.5 2002/03/26 05:23:21 eob
113: // Comment change only
114: //
115: // Revision 1.4 2002/02/01 22:01:16 eob
116: // Comment change only.
117: //
118: // Revision 1.3 2002/01/05 21:31:30 eob
119: // Add hack to get same order as Xerces.
120: //
121: // Revision 1.2 2002/01/05 08:06:19 eob
122: // Implement remove
123: //
124: // Revision 1.1 2002/01/04 19:44:37 eob
125: // initial
|