001/* 002 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 003 * 004 * This software is open source. 005 * See the bottom of this file for the licence. 006 * 007 * $Id: DOMAttributeNodeMap.java,v 1.1 2001/04/10 23:43:44 jstrachan Exp $ 008 */ 009 010package org.dom4j.dom; 011 012import org.w3c.dom.Attr; 013import org.w3c.dom.Document; 014import org.w3c.dom.DOMException; 015import org.w3c.dom.NamedNodeMap; 016import org.w3c.dom.NodeList; 017import org.w3c.dom.Node; 018 019/** <p><code>DOMAttributeNodeMap</code> implements a W3C NameNodeMap 020 * for the attributes of an element.</p> 021 * 022 * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a> 023 * @version $Revision: 1.1 $ 024 */ 025public class DOMAttributeNodeMap implements org.w3c.dom.NamedNodeMap { 026 027 private DOMElement element; 028 029 public DOMAttributeNodeMap(DOMElement element) { 030 this.element = element; 031 } 032 033 034 // org.w3c.dom.NamedNodeMap interface 035 //------------------------------------------------------------------------- 036 public void foo() throws DOMException { 037 DOMNodeHelper.notSupported(); 038 } 039 040 public Node getNamedItem(String name) { 041 return element.getAttributeNode(name); 042 } 043 044 public Node setNamedItem(Node arg) throws DOMException { 045 if ( arg instanceof Attr ) { 046 return element.setAttributeNode( (org.w3c.dom.Attr) arg ); 047 } 048 else { 049 throw new DOMException( DOMException.NOT_SUPPORTED_ERR, "Node is not an Attr: " + arg ); 050 } 051 } 052 053 public Node removeNamedItem(String name) throws DOMException { 054 org.w3c.dom.Attr attr = element.getAttributeNode(name); 055 if ( attr != null ) { 056 return element.removeAttributeNode( attr ); 057 } 058 return attr; 059 } 060 061 public Node item(int index) { 062 return DOMNodeHelper.asDOMAttr( element.attribute(index) ); 063 } 064 065 public int getLength() { 066 return element.attributeCount(); 067 } 068 069 public Node getNamedItemNS(String namespaceURI, String localName) { 070 return element.getAttributeNodeNS( namespaceURI, localName ); 071 } 072 073 public Node setNamedItemNS(Node arg) throws DOMException { 074 if ( arg instanceof Attr ) { 075 return element.setAttributeNodeNS( (org.w3c.dom.Attr) arg ); 076 } 077 else { 078 throw new DOMException( DOMException.NOT_SUPPORTED_ERR, "Node is not an Attr: " + arg ); 079 } 080 } 081 082 public Node removeNamedItemNS(String namespaceURI, String localName) throws DOMException { 083 org.w3c.dom.Attr attr = element.getAttributeNodeNS( namespaceURI, localName ); 084 if ( attr != null ) { 085 return element.removeAttributeNode( attr ); 086 } 087 return attr; 088 } 089 090} 091 092 093 094 095/* 096 * Redistribution and use of this software and associated documentation 097 * ("Software"), with or without modification, are permitted provided 098 * that the following conditions are met: 099 * 100 * 1. Redistributions of source code must retain copyright 101 * statements and notices. Redistributions must also contain a 102 * copy of this document. 103 * 104 * 2. Redistributions in binary form must reproduce the 105 * above copyright notice, this list of conditions and the 106 * following disclaimer in the documentation and/or other 107 * materials provided with the distribution. 108 * 109 * 3. The name "DOM4J" must not be used to endorse or promote 110 * products derived from this Software without prior written 111 * permission of MetaStuff, Ltd. For written permission, 112 * please contact dom4j-info@metastuff.com. 113 * 114 * 4. Products derived from this Software may not be called "DOM4J" 115 * nor may "DOM4J" appear in their names without prior written 116 * permission of MetaStuff, Ltd. DOM4J is a registered 117 * trademark of MetaStuff, Ltd. 118 * 119 * 5. Due credit should be given to the DOM4J Project 120 * (http://dom4j.org/). 121 * 122 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS 123 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 124 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 125 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 126 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 127 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 128 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 129 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 130 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 131 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 132 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 133 * OF THE POSSIBILITY OF SUCH DAMAGE. 134 * 135 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 136 * 137 * $Id: DOMAttributeNodeMap.java,v 1.1 2001/04/10 23:43:44 jstrachan Exp $ 138 */