Path: blob/jdk8u272-b10-aarch32-20201026/jaxp/src/javax/xml/namespace/NamespaceContext.java
48789 views
/*1* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.xml.namespace;2627import java.util.Iterator;2829/**30* <p>Interface for read only XML Namespace context processing.</p>31*32* <p>An XML Namespace has the properties:</p>33* <ul>34* <li>Namespace URI:35* Namespace name expressed as a URI to which the prefix is bound</li>36* <li>prefix: syntactically, this is the part of the attribute name37* following the <code>XMLConstants.XMLNS_ATTRIBUTE</code>38* ("xmlns") in the Namespace declaration</li>39* </ul>40* <p>example:41* <code><element xmlns:prefix="http://Namespace-name-URI"></code></p>42*43* <p>All <code>get*(*)</code> methods operate in the current scope44* for Namespace URI and prefix resolution.</p>45*46* <p>Note that a Namespace URI can be bound to47* <strong>multiple</strong> prefixes in the current scope. This can48* occur when multiple <code>XMLConstants.XMLNS_ATTRIBUTE</code>49* ("xmlns") Namespace declarations occur in the same Start-Tag and50* refer to the same Namespace URI. e.g.<br />51* <pre>52* <element xmlns:prefix1="http://Namespace-name-URI"53* xmlns:prefix2="http://Namespace-name-URI">54* </pre>55* This can also occur when the same Namespace URI is used in multiple56* <code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns") Namespace57* declarations in the logical parent element hierarchy. e.g.<br />58* <pre>59* <parent xmlns:prefix1="http://Namespace-name-URI">60* <child xmlns:prefix2="http://Namespace-name-URI">61* ...62* </child>63* </parent>64* </pre></p>65*66* <p>A prefix can only be bound to a <strong>single</strong>67* Namespace URI in the current scope.</p>68*69* @author <a href="mailto:[email protected]">Jeff Suttor</a>70* @see javax.xml.XMLConstants71* javax.xml.XMLConstants for declarations of common XML values72* @see <a href="http://www.w3.org/TR/xmlschema-2/#QName">73* XML Schema Part2: Datatypes</a>74* @see <a href="http://www.w3.org/TR/REC-xml-names/#ns-qualnames">75* Namespaces in XML</a>76* @see <a href="http://www.w3.org/XML/xml-names-19990114-errata">77* Namespaces in XML Errata</a>78* @since 1.579*/8081public interface NamespaceContext {8283/**84* <p>Get Namespace URI bound to a prefix in the current scope.</p>85*86* <p>When requesting a Namespace URI by prefix, the following87* table describes the returned Namespace URI value for all88* possible prefix values:</p>89*90* <table border="2" rules="all" cellpadding="4">91* <thead>92* <tr>93* <td align="center" colspan="2">94* <code>getNamespaceURI(prefix)</code>95* return value for specified prefixes96* </td>97* </tr>98* <tr>99* <td>prefix parameter</td>100* <td>Namespace URI return value</td>101* </tr>102* </thead>103* <tbody>104* <tr>105* <td><code>DEFAULT_NS_PREFIX</code> ("")</td>106* <td>default Namespace URI in the current scope or107* <code>{@link108* javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI("")}109* </code>110* when there is no default Namespace URI in the current scope</td>111* </tr>112* <tr>113* <td>bound prefix</td>114* <td>Namespace URI bound to prefix in current scope</td>115* </tr>116* <tr>117* <td>unbound prefix</td>118* <td>119* <code>{@link120* javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI("")}121* </code>122* </td>123* </tr>124* <tr>125* <td><code>XMLConstants.XML_NS_PREFIX</code> ("xml")</td>126* <td><code>XMLConstants.XML_NS_URI</code>127* ("http://www.w3.org/XML/1998/namespace")</td>128* </tr>129* <tr>130* <td><code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns")</td>131* <td><code>XMLConstants.XMLNS_ATTRIBUTE_NS_URI</code>132* ("http://www.w3.org/2000/xmlns/")</td>133* </tr>134* <tr>135* <td><code>null</code></td>136* <td><code>IllegalArgumentException</code> is thrown</td>137* </tr>138* </tbody>139* </table>140*141* @param prefix prefix to look up142*143* @return Namespace URI bound to prefix in the current scope144*145* @throws IllegalArgumentException When <code>prefix</code> is146* <code>null</code>147*/148String getNamespaceURI(String prefix);149150/**151* <p>Get prefix bound to Namespace URI in the current scope.</p>152*153* <p>To get all prefixes bound to a Namespace URI in the current154* scope, use {@link #getPrefixes(String namespaceURI)}.</p>155*156* <p>When requesting a prefix by Namespace URI, the following157* table describes the returned prefix value for all Namespace URI158* values:</p>159*160* <table border="2" rules="all" cellpadding="4">161* <thead>162* <tr>163* <th align="center" colspan="2">164* <code>getPrefix(namespaceURI)</code> return value for165* specified Namespace URIs166* </th>167* </tr>168* <tr>169* <th>Namespace URI parameter</th>170* <th>prefix value returned</th>171* </tr>172* </thead>173* <tbody>174* <tr>175* <td><default Namespace URI></td>176* <td><code>XMLConstants.DEFAULT_NS_PREFIX</code> ("")177* </td>178* </tr>179* <tr>180* <td>bound Namespace URI</td>181* <td>prefix bound to Namespace URI in the current scope,182* if multiple prefixes are bound to the Namespace URI in183* the current scope, a single arbitrary prefix, whose184* choice is implementation dependent, is returned</td>185* </tr>186* <tr>187* <td>unbound Namespace URI</td>188* <td><code>null</code></td>189* </tr>190* <tr>191* <td><code>XMLConstants.XML_NS_URI</code>192* ("http://www.w3.org/XML/1998/namespace")</td>193* <td><code>XMLConstants.XML_NS_PREFIX</code> ("xml")</td>194* </tr>195* <tr>196* <td><code>XMLConstants.XMLNS_ATTRIBUTE_NS_URI</code>197* ("http://www.w3.org/2000/xmlns/")</td>198* <td><code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns")</td>199* </tr>200* <tr>201* <td><code>null</code></td>202* <td><code>IllegalArgumentException</code> is thrown</td>203* </tr>204* </tbody>205* </table>206*207* @param namespaceURI URI of Namespace to lookup208*209* @return prefix bound to Namespace URI in current context210*211* @throws IllegalArgumentException When <code>namespaceURI</code> is212* <code>null</code>213*/214String getPrefix(String namespaceURI);215216/**217* <p>Get all prefixes bound to a Namespace URI in the current218* scope.</p>219*220* <p>An Iterator over String elements is returned in an arbitrary,221* <strong>implementation dependent</strong>, order.</p>222*223* <p><strong>The <code>Iterator</code> is224* <em>not</em> modifiable. e.g. the225* <code>remove()</code> method will throw226* <code>UnsupportedOperationException</code>.</strong></p>227*228* <p>When requesting prefixes by Namespace URI, the following229* table describes the returned prefixes value for all Namespace230* URI values:</p>231*232* <table border="2" rules="all" cellpadding="4">233* <thead>234* <tr>235* <th align="center" colspan="2"><code>236* getPrefixes(namespaceURI)</code> return value for237* specified Namespace URIs</th>238* </tr>239* <tr>240* <th>Namespace URI parameter</th>241* <th>prefixes value returned</th>242* </tr>243* </thead>244* <tbody>245* <tr>246* <td>bound Namespace URI,247* including the <default Namespace URI></td>248* <td>249* <code>Iterator</code> over prefixes bound to Namespace URI in250* the current scope in an arbitrary,251* <strong>implementation dependent</strong>,252* order253* </td>254* </tr>255* <tr>256* <td>unbound Namespace URI</td>257* <td>empty <code>Iterator</code></td>258* </tr>259* <tr>260* <td><code>XMLConstants.XML_NS_URI</code>261* ("http://www.w3.org/XML/1998/namespace")</td>262* <td><code>Iterator</code> with one element set to263* <code>XMLConstants.XML_NS_PREFIX</code> ("xml")</td>264* </tr>265* <tr>266* <td><code>XMLConstants.XMLNS_ATTRIBUTE_NS_URI</code>267* ("http://www.w3.org/2000/xmlns/")</td>268* <td><code>Iterator</code> with one element set to269* <code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns")</td>270* </tr>271* <tr>272* <td><code>null</code></td>273* <td><code>IllegalArgumentException</code> is thrown</td>274* </tr>275* </tbody>276* </table>277*278* @param namespaceURI URI of Namespace to lookup279*280* @return <code>Iterator</code> for all prefixes bound to the281* Namespace URI in the current scope282*283* @throws IllegalArgumentException When <code>namespaceURI</code> is284* <code>null</code>285*/286Iterator getPrefixes(String namespaceURI);287}288289290