KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > dom > AbstractAttrNS


1 /*
2
3    Copyright 2000 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.dom;
19
20 import org.apache.batik.dom.util.DOMUtilities;
21 import org.apache.batik.dom.util.XMLSupport;
22 import org.w3c.dom.DOMException JavaDoc;
23 import org.w3c.dom.Node JavaDoc;
24
25 /**
26  * This class implements the {@link org.w3c.dom.Attr} interface with
27  * support for namespaces.
28  *
29  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
30  * @version $Id: AbstractAttrNS.java,v 1.5 2005/02/22 09:12:57 cam Exp $
31  */

32
33 public abstract class AbstractAttrNS extends AbstractAttr {
34     /**
35      * The namespace URI
36      */

37     protected String JavaDoc namespaceURI;
38
39     /**
40      * Creates a new Attr object.
41      */

42     protected AbstractAttrNS() {
43     }
44
45     /**
46      * Creates a new Attr object.
47      * @param nsURI The element namespace URI.
48      * @param qname The attribute qualified name for validation purposes.
49      * @param owner The owner document.
50      * @exception DOMException
51      * INVALID_CHARACTER_ERR: Raised if the specified qualified name
52      * contains an illegal character.
53      * <br> NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
54      * malformed, if the <code>qualifiedName</code> has a prefix and the
55      * <code>namespaceURI</code> is <code>null</code> or an empty string,
56      * if the <code>qualifiedName</code> has a prefix that is "xml" and the
57      * <code>namespaceURI</code> is different from
58      * "http://www.w3.org/XML/1998/namespace", if the
59      * <code>qualifiedName</code> has a prefix that is "xmlns" and the
60      * <code>namespaceURI</code> is different from
61      * "http://www.w3.org/2000/xmlns/", or if the <code>qualifiedName</code>
62      * is "xmlns" and the <code>namespaceURI</code> is different from
63      * "http://www.w3.org/2000/xmlns/".
64      */

65     protected AbstractAttrNS(String JavaDoc nsURI,
66                  String JavaDoc qname,
67                  AbstractDocument owner)
68     throws DOMException JavaDoc {
69     super(qname, owner);
70     namespaceURI = nsURI;
71     String JavaDoc prefix = DOMUtilities.getPrefix(qname);
72     if (prefix != null) {
73         if (nsURI == null || nsURI.equals("") ||
74         ("xml".equals(prefix) &&
75          !XMLSupport.XML_NAMESPACE_URI.equals(nsURI)) ||
76         ("xmlns".equals(prefix) &&
77          !XMLSupport.XMLNS_NAMESPACE_URI.equals(nsURI))) {
78         throw createDOMException
79                     (DOMException.NAMESPACE_ERR,
80                      "namespace.uri",
81                      new Object JavaDoc[] { new Integer JavaDoc(getNodeType()),
82                                     getNodeName(),
83                                     nsURI });
84         }
85     } else if ("xmlns".equals(qname) &&
86            !XMLSupport.XMLNS_NAMESPACE_URI.equals(nsURI)) {
87         throw createDOMException(DOMException.NAMESPACE_ERR,
88                      "namespace.uri",
89                      new Object JavaDoc[] { new Integer JavaDoc(getNodeType()),
90                             getNodeName(),
91                             nsURI });
92     }
93     }
94
95     /**
96      * <b>DOM</b>: Implements {@link org.w3c.dom.Node#getNamespaceURI()}.
97      * @return {@link #namespaceURI}.
98      */

99     public String JavaDoc getNamespaceURI() {
100     return namespaceURI;
101     }
102
103     /**
104      * Exports this node to the given document.
105      */

106     protected Node JavaDoc export(Node JavaDoc n, AbstractDocument d) {
107     super.export(n, d);
108     AbstractAttrNS aa = (AbstractAttrNS)n;
109     aa.namespaceURI = namespaceURI;
110     return n;
111     }
112
113     /**
114      * Deeply exports this node to the given document.
115      */

116     protected Node JavaDoc deepExport(Node JavaDoc n, AbstractDocument d) {
117     super.deepExport(n, d);
118     AbstractAttrNS aa = (AbstractAttrNS)n;
119     aa.namespaceURI = namespaceURI;
120     return n;
121     }
122
123     /**
124      * Copy the fields of the current node into the given node.
125      * @param n a node of the type of this.
126      */

127     protected Node JavaDoc copyInto(Node JavaDoc n) {
128     super.copyInto(n);
129     AbstractAttrNS aa = (AbstractAttrNS)n;
130     aa.namespaceURI = namespaceURI;
131     return n;
132     }
133
134     /**
135      * Deeply copy the fields of the current node into the given node.
136      * @param n a node of the type of this.
137      */

138     protected Node JavaDoc deepCopyInto(Node JavaDoc n) {
139     super.deepCopyInto(n);
140     AbstractAttrNS aa = (AbstractAttrNS)n;
141     aa.namespaceURI = namespaceURI;
142     return n;
143     }
144 }
145
Popular Tags