|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
DOMAttributeNodeMap.java | 0% | 10% | 20% | 10,5% |
|
1 | /* | |
2 | * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. | |
3 | * | |
4 | * This software is open source. | |
5 | * See the bottom of this file for the licence. | |
6 | * | |
7 | * $Id: DOMAttributeNodeMap.java,v 1.6 2004/06/25 08:03:34 maartenc Exp $ | |
8 | */ | |
9 | ||
10 | package org.dom4j.dom; | |
11 | ||
12 | import org.w3c.dom.Attr; | |
13 | import org.w3c.dom.DOMException; | |
14 | import org.w3c.dom.Node; | |
15 | ||
16 | /** <p><code>DOMAttributeNodeMap</code> implements a W3C NameNodeMap | |
17 | * for the attributes of an element.</p> | |
18 | * | |
19 | * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a> | |
20 | * @version $Revision: 1.6 $ | |
21 | */ | |
22 | public class DOMAttributeNodeMap implements org.w3c.dom.NamedNodeMap { | |
23 | ||
24 | private DOMElement element; | |
25 | ||
26 | 70 | public DOMAttributeNodeMap(DOMElement element) { |
27 | 70 | this.element = element; |
28 | } | |
29 | ||
30 | ||
31 | // org.w3c.dom.NamedNodeMap interface | |
32 | //------------------------------------------------------------------------- | |
33 | 0 | public void foo() throws DOMException { |
34 | 0 | DOMNodeHelper.notSupported(); |
35 | } | |
36 | ||
37 | 0 | public Node getNamedItem(String name) { |
38 | 0 | return element.getAttributeNode(name); |
39 | } | |
40 | ||
41 | 0 | public Node setNamedItem(Node arg) throws DOMException { |
42 | 0 | if ( arg instanceof Attr ) { |
43 | 0 | return element.setAttributeNode( (org.w3c.dom.Attr) arg ); |
44 | } | |
45 | else { | |
46 | 0 | throw new DOMException( DOMException.NOT_SUPPORTED_ERR, "Node is not an Attr: " + arg ); |
47 | } | |
48 | } | |
49 | ||
50 | 0 | public Node removeNamedItem(String name) throws DOMException { |
51 | 0 | org.w3c.dom.Attr attr = element.getAttributeNode(name); |
52 | 0 | if ( attr == null ) { |
53 | 0 | throw new DOMException(DOMException.NOT_FOUND_ERR, |
54 | "No attribute named " + name); | |
55 | } | |
56 | 0 | return element.removeAttributeNode( attr ); |
57 | } | |
58 | ||
59 | 0 | public Node item(int index) { |
60 | 0 | return DOMNodeHelper.asDOMAttr( element.attribute(index) ); |
61 | } | |
62 | ||
63 | 70 | public int getLength() { |
64 | 70 | return element.attributeCount(); |
65 | } | |
66 | ||
67 | 0 | public Node getNamedItemNS(String namespaceURI, String localName) { |
68 | 0 | return element.getAttributeNodeNS( namespaceURI, localName ); |
69 | } | |
70 | ||
71 | 0 | public Node setNamedItemNS(Node arg) throws DOMException { |
72 | 0 | if ( arg instanceof Attr ) { |
73 | 0 | return element.setAttributeNodeNS( (org.w3c.dom.Attr) arg ); |
74 | } | |
75 | else { | |
76 | 0 | throw new DOMException( DOMException.NOT_SUPPORTED_ERR, "Node is not an Attr: " + arg ); |
77 | } | |
78 | } | |
79 | ||
80 | 0 | public Node removeNamedItemNS(String namespaceURI, String localName) throws DOMException { |
81 | 0 | org.w3c.dom.Attr attr = element.getAttributeNodeNS( namespaceURI, localName ); |
82 | 0 | if ( attr != null ) { |
83 | 0 | return element.removeAttributeNode( attr ); |
84 | } | |
85 | 0 | return attr; |
86 | } | |
87 | ||
88 | } | |
89 | ||
90 | ||
91 | ||
92 | ||
93 | /* | |
94 | * Redistribution and use of this software and associated documentation | |
95 | * ("Software"), with or without modification, are permitted provided | |
96 | * that the following conditions are met: | |
97 | * | |
98 | * 1. Redistributions of source code must retain copyright | |
99 | * statements and notices. Redistributions must also contain a | |
100 | * copy of this document. | |
101 | * | |
102 | * 2. Redistributions in binary form must reproduce the | |
103 | * above copyright notice, this list of conditions and the | |
104 | * following disclaimer in the documentation and/or other | |
105 | * materials provided with the distribution. | |
106 | * | |
107 | * 3. The name "DOM4J" must not be used to endorse or promote | |
108 | * products derived from this Software without prior written | |
109 | * permission of MetaStuff, Ltd. For written permission, | |
110 | * please contact dom4j-info@metastuff.com. | |
111 | * | |
112 | * 4. Products derived from this Software may not be called "DOM4J" | |
113 | * nor may "DOM4J" appear in their names without prior written | |
114 | * permission of MetaStuff, Ltd. DOM4J is a registered | |
115 | * trademark of MetaStuff, Ltd. | |
116 | * | |
117 | * 5. Due credit should be given to the DOM4J Project - | |
118 | * http://www.dom4j.org | |
119 | * | |
120 | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS | |
121 | * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT | |
122 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
123 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
124 | * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
125 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
126 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
127 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
128 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
129 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
130 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
131 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |
132 | * | |
133 | * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. | |
134 | * | |
135 | * $Id: DOMAttributeNodeMap.java,v 1.6 2004/06/25 08:03:34 maartenc Exp $ | |
136 | */ |
|