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: DOMAttribute.java,v 1.6 2001/09/25 16:48:10 jstrachan Exp $
008 */
009
010package org.dom4j.dom;
011
012import org.dom4j.Element;
013import org.dom4j.QName;
014import org.dom4j.tree.DefaultAttribute;
015
016import org.w3c.dom.Document;
017import org.w3c.dom.DOMException;
018import org.w3c.dom.NamedNodeMap;
019import org.w3c.dom.NodeList;
020
021/** <p><code>DOMAttribute</code> implements a doubly linked attribute which 
022  * supports the W3C DOM API.</p>
023  *
024  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
025  * @version $Revision: 1.6 $
026  */
027public class DOMAttribute extends DefaultAttribute implements org.w3c.dom.Attr {
028    
029    public DOMAttribute(QName qname) { 
030        super(qname);
031    }
032    
033    public DOMAttribute(QName qname, String value) { 
034        super(qname, value);
035    }
036    
037    public DOMAttribute(Element parent, QName qname, String value) { 
038        super(parent, qname, value);
039    }
040
041    
042    // org.w3c.dom.Node interface
043    //-------------------------------------------------------------------------        
044    public String getNamespaceURI() {
045        return getQName().getNamespaceURI();
046    }
047
048    public String getPrefix() {
049        return getQName().getNamespacePrefix();
050    }
051    
052    public void setPrefix(String prefix) throws DOMException {
053        DOMNodeHelper.setPrefix(this, prefix);
054    }
055
056    public String getLocalName() {
057        return getQName().getName();
058    }
059
060    public String getNodeName() {
061        return getName();
062    }
063    
064    //already part of API  
065    //
066    //public short getNodeType();
067    
068
069    
070    public String getNodeValue() throws DOMException {
071        return DOMNodeHelper.getNodeValue(this);
072    }
073    
074    public void setNodeValue(String nodeValue) throws DOMException {
075        DOMNodeHelper.setNodeValue(this, nodeValue);
076    }
077        
078    
079    public org.w3c.dom.Node getParentNode() {
080        // Per http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-637646024 
081        // and the NIST conformance tests, Attr.getParentNode() should always 
082        // return null
083        return null;
084    }
085    
086    public NodeList getChildNodes() {
087        return DOMNodeHelper.getChildNodes(this);
088    }
089
090    public org.w3c.dom.Node getFirstChild() {
091        return DOMNodeHelper.getFirstChild(this);
092    }
093
094    public org.w3c.dom.Node getLastChild() {
095        return DOMNodeHelper.getLastChild(this);
096    }
097
098    public org.w3c.dom.Node getPreviousSibling() {
099        return DOMNodeHelper.getPreviousSibling(this);
100    }
101
102    public org.w3c.dom.Node getNextSibling() {
103        return DOMNodeHelper.getNextSibling(this);
104    }
105
106    public NamedNodeMap getAttributes() {
107        return DOMNodeHelper.getAttributes(this);
108    }
109
110    public Document getOwnerDocument() {
111        return DOMNodeHelper.getOwnerDocument(this);
112    }
113
114    public org.w3c.dom.Node insertBefore(
115        org.w3c.dom.Node newChild, 
116        org.w3c.dom.Node refChild
117    ) throws DOMException {
118        return DOMNodeHelper.insertBefore(this, newChild, refChild);
119    }
120
121    public org.w3c.dom.Node replaceChild(
122        org.w3c.dom.Node newChild, 
123        org.w3c.dom.Node oldChild
124    ) throws DOMException {
125        return DOMNodeHelper.replaceChild(this, newChild, oldChild);
126    }
127
128    public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild) throws DOMException {
129        return DOMNodeHelper.removeChild(this, oldChild);
130    }
131
132    public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild) throws DOMException {
133        return DOMNodeHelper.appendChild(this, newChild);
134    }
135
136    public boolean hasChildNodes() {
137        return DOMNodeHelper.hasChildNodes(this);
138    }
139
140    public org.w3c.dom.Node cloneNode(boolean deep) {
141        return DOMNodeHelper.cloneNode(this, deep);
142    }
143
144    public void normalize() {
145        DOMNodeHelper.normalize(this);
146    }
147
148    public boolean isSupported(String feature, String version) {
149        return DOMNodeHelper.isSupported(this, feature, version);
150    }
151
152    public boolean hasAttributes() {
153        return DOMNodeHelper.hasAttributes(this);
154    }
155    
156    
157    // org.w3c.dom.Attr interface
158    //-------------------------------------------------------------------------            
159    
160    //public String getName();
161
162    public boolean getSpecified() {
163        return false;
164    }
165
166    //public String getValue();
167    
168    //public void setValue(String value) throws DOMException;
169
170    public org.w3c.dom.Element getOwnerElement() {
171        return DOMNodeHelper.asDOMElement( getParent() );
172    }
173    
174}
175
176
177
178
179/*
180 * Redistribution and use of this software and associated documentation
181 * ("Software"), with or without modification, are permitted provided
182 * that the following conditions are met:
183 *
184 * 1. Redistributions of source code must retain copyright
185 *    statements and notices.  Redistributions must also contain a
186 *    copy of this document.
187 *
188 * 2. Redistributions in binary form must reproduce the
189 *    above copyright notice, this list of conditions and the
190 *    following disclaimer in the documentation and/or other
191 *    materials provided with the distribution.
192 *
193 * 3. The name "DOM4J" must not be used to endorse or promote
194 *    products derived from this Software without prior written
195 *    permission of MetaStuff, Ltd.  For written permission,
196 *    please contact dom4j-info@metastuff.com.
197 *
198 * 4. Products derived from this Software may not be called "DOM4J"
199 *    nor may "DOM4J" appear in their names without prior written
200 *    permission of MetaStuff, Ltd. DOM4J is a registered
201 *    trademark of MetaStuff, Ltd.
202 *
203 * 5. Due credit should be given to the DOM4J Project
204 *    (http://dom4j.org/).
205 *
206 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
207 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
208 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
209 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
210 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
211 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
212 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
213 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
214 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
215 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
216 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
217 * OF THE POSSIBILITY OF SUCH DAMAGE.
218 *
219 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
220 *
221 * $Id: DOMAttribute.java,v 1.6 2001/09/25 16:48:10 jstrachan Exp $
222 */