2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 // $Id: NamespaceContext.java 446598 2006-09-15 12:55:40Z jeremias $
20 package javax.xml.namespace;
22 import java.util.Iterator;
25 * <p>Interface for read only XML Namespace context processing.</p>
27 * <p>An XML Namespace has the properties:</p>
30 * Namespace name expressed as a URI to which the prefix is bound</li>
31 * <li>prefix: syntactically, this is the part of the attribute name
32 * following the <code>XMLConstants.XMLNS_ATTRIBUTE</code>
33 * ("xmlns") in the Namespace declaration</li>
35 * <p> example: <code><element xmlns:prefix="http://Namespace-name-URI"></code></p>
37 * <p>All <code>get*(*)</code> methods operate in the current scope
38 * for Namespace URI and prefix resolution.</p>
40 * <p>Note that a Namespace URI can be bound to
41 * <strong>multiple</strong> prefixes in the current scope. This can
42 * occur when multiple <code>XMLConstants.XMLNS_ATTRIBUTE</code>
43 * ("xmlns") Namespace declarations occur in the same Start-Tag and
44 * refer to the same Namespace URI. e.g.<br />
46 * <element xmlns:prefix1="http://Namespace-name-URI"
47 * xmlns:prefix2="http://Namespace-name-URI">
49 * This can also occur when the same Namespace URI is used in multiple
50 * <code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns") Namespace
51 * declarations in the logical parent element hierarchy. e.g.<br />
53 * <parent xmlns:prefix1="http://Namespace-name-URI">
54 * <child xmlns:prefix2="http://Namespace-name-URI">
60 * <p>A prefix can only be bound to a <strong>single</strong>
61 * Namespace URI in the current scope.</p>
63 * @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
64 * @version $Revision: 446598 $, $Date: 2006-09-15 05:55:40 -0700 (Fri, 15 Sep 2006) $
65 * @see javax.xml.XMLConstants javax.XMLConstants for declarations of common XML values
66 * @see <a href="http://www.w3.org/TR/xmlschema-2/#QName">XML Schema Part2: Datatypes</a>
67 * @see <a href="http://www.w3.org/TR/REC-xml-names/#ns-qualnames">Namespaces in XML</a>
68 * @see <a href="http://www.w3.org/XML/xml-names-19990114-errata">Namespaces in XML Errata</a>
72 public interface NamespaceContext {
75 * <p>Get Namespace URI bound to a prefix in the current scope.</p>
77 * <p>When requesting a Namespace URI by prefix, the following
78 * table describes the returned Namespace URI value for all
79 * possible prefix values:</p>
81 * <table border="2" rules="all" cellpadding="4">
84 * <td align="center" colspan="2">
85 * <code>getNamespaceURI(prefix)</code>
86 * return value for specified prefixes
90 * <td>prefix parameter</td>
91 * <td>Namespace URI return value</td>
96 * <td><code>DEFAULT_NS_PREFIX</code> ("")</td>
97 * <td>default Namespace URI in the current scope or
98 * <code>{@link javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI("")}</code>
99 * when there is no default Namespace URI in the current scope</td>
102 * <td>bound prefix</td>
103 * <td>Namespace URI bound to prefix in current scope</td>
106 * <td>unbound prefix</td>
107 * <td><code>{@link javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI("")}</code> </td>
110 * <td><code>XMLConstants.XML_NS_PREFIX</code> ("xml")</td>
111 * <td><code>XMLConstants.XML_NS_URI</code>
112 * ("http://www.w3.org/XML/1998/namespace")</td>
115 * <td><code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns")</td>
116 * <td><code>XMLConstants.XMLNS_ATTRIBUTE_NS_URI</code>
117 * ("http://www.w3.org/2000/xmlns/")</td>
120 * <td><code>null</code></td>
121 * <td><code>IllegalArgumentException</code> is thrown</td>
126 * @param prefix prefix to look up
127 * @return Namespace URI bound to prefix in the current scope
129 String getNamespaceURI(String prefix);
132 * <p>Get prefix bound to Namespace URI in the current scope.</p>
134 * <p>To get all prefixes bound to a Namespace URI in the current
135 * scope, use {@link #getPrefixes(String namespaceURI)}.</p>
137 * <p>When requesting a prefix by Namespace URI, the following
138 * table describes the returned prefix value for all Namespace URI
141 * <table border="2" rules="all" cellpadding="4">
144 * <td align="center" colspan="2">
145 * <code>getPrefix(namespaceURI)</code> return value for
146 * specified Namespace URIs
150 * <td>Namespace URI parameter</td>
151 * <td>prefix value returned</td>
156 * <td><default Namespace URI></td>
157 * <td><code>XMLConstants.DEFAULT_NS_PREFIX</code> ("")
161 * <td>bound Namespace URI</td>
162 * <td>prefix bound to Namespace URI in the current scope,
163 * if multiple prefixes are bound to the Namespace URI in
164 * the current scope, a single arbitrary prefix, whose
165 * choice is implementation dependent, is returned</td>
168 * <td>unbound Namespace URI</td>
169 * <td><code>null</code></td>
172 * <td><code>XMLConstants.XML_NS_URI</code>
173 * ("http://www.w3.org/XML/1998/namespace")</td>
174 * <td><code>XMLConstants.XML_NS_PREFIX</code> ("xml")</td>
177 * <td><code>XMLConstants.XMLNS_ATTRIBUTE_NS_URI</code>
178 * ("http://www.w3.org/2000/xmlns/")</td>
179 * <td><code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns")</td>
182 * <td><code>null</code></td>
183 * <td><code>IllegalArgumentException</code> is thrown</td>
188 * @param namespaceURI URI of Namespace to lookup
189 * @return prefix bound to Namespace URI in current context
191 String getPrefix(String namespaceURI);
194 * <p>Get all prefixes bound to a Namespace URI in the current
197 * <p>An Iterator over String elements is returned in an arbitrary, <strong>implementation dependent</strong>, order.</p>
199 * <p><strong>The <code>Iterator</code> is
200 * <em>not</em> modifiable. e.g. the
201 * <code>remove()</code> method will throw
202 * <code>UnsupportedOperationException</code>.</strong></p>
204 * <p>When requesting prefixes by Namespace URI, the following
205 * table describes the returned prefixes value for all Namespace
208 * <table border="2" rules="all" cellpadding="4">
211 * <td align="center" colspan="2"><code>
212 * getPrefixes(namespaceURI)</code> return value for
213 * specified Namespace URIs</td>
216 * <td>Namespace URI parameter</td>
217 * <td>prefixes value returned</td>
222 * <td>bound Namespace URI,
223 * including the <default Namespace URI></td>
224 * <td><code>Iterator</code> over prefixes bound to Namespace URI in
225 * the current scope in an arbitrary, <strong>implementation dependent</strong>,
229 * <td>unbound Namespace URI</td>
230 * <td>empty <code>Iterator</code></td>
233 * <td><code>XMLConstants.XML_NS_URI</code>
234 * ("http://www.w3.org/XML/1998/namespace")</td>
235 * <td><code>Iterator</code> with one element set to
236 * <code>XMLConstants.XML_NS_PREFIX</code> ("xml")</td>
239 * <td><code>XMLConstants.XMLNS_ATTRIBUTE_NS_URI</code>
240 * ("http://www.w3.org/2000/xmlns/")</td>
241 * <td><code>Iterator</code> with one element set to
242 * <code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns")</td>
245 * <td><code>null</code></td>
246 * <td><code>IllegalArgumentException</code> is thrown</td>
251 * @param namespaceURI URI of Namespace to lookup
252 * @return <code>Iterator</code> for all prefixes bound to the
253 * Namespace URI in the current scope
255 Iterator getPrefixes(String namespaceURI);