Path: blob/master/src/java.xml/share/classes/javax/xml/namespace/NamespaceContext.java
40948 views
/*1* Copyright (c) 2003, 2018, 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* Interface for read only XML Namespace context processing.31*32* <p>An XML Namespace has the properties: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}38* ("xmlns") in the Namespace declaration</li>39* </ul>40* <p>example:41* {@code <element xmlns:prefix="http://Namespace-name-URI">}42*43* <p>All {@code get*(*)} methods operate in the current scope44* for Namespace URI and prefix resolution.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}49* ("xmlns") Namespace declarations occur in the same Start-Tag and50* refer to the same Namespace URI. e.g.<br>51* <pre> {@code52* <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} ("xmlns") Namespace57* declarations in the logical parent element hierarchy. e.g.<br>58* <pre> {@code59* <parent xmlns:prefix1="http://Namespace-name-URI">60* <child xmlns:prefix2="http://Namespace-name-URI">61* ...62* </child>63* </parent> }64* </pre>65*66* <p>A prefix can only be bound to a <strong>single</strong>67* Namespace URI in the current scope.68*69* @author Jeff Suttor70* @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/">75* Namespaces in XML</a>76* @since 1.577*/7879public interface NamespaceContext {8081/**82* Get Namespace URI bound to a prefix in the current scope.83*84* <p>When requesting a Namespace URI by prefix, the following85* table describes the returned Namespace URI value for all86* possible prefix values:87*88* <table class="striped">89* <caption>Return value for specified prefixes</caption>90* <thead>91* <tr>92* <th scope="col">prefix parameter</th>93* <th scope="col">Namespace URI return value</th>94* </tr>95* </thead>96* <tbody>97* <tr>98* <th scope="row">{@code DEFAULT_NS_PREFIX} ("")</th>99* <td>default Namespace URI in the current scope or100* <code> {@link101* javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI("")}102* </code>103* when there is no default Namespace URI in the current scope</td>104* </tr>105* <tr>106* <th scope="row">bound prefix</th>107* <td>Namespace URI bound to prefix in current scope</td>108* </tr>109* <tr>110* <th scope="row">unbound prefix</th>111* <td>112* <code> {@link113* javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI("")}114* </code>115* </td>116* </tr>117* <tr>118* <th scope="row">{@code XMLConstants.XML_NS_PREFIX} ("xml")</th>119* <td>{@code XMLConstants.XML_NS_URI}120* ("http://www.w3.org/XML/1998/namespace")</td>121* </tr>122* <tr>123* <th scope="row">{@code XMLConstants.XMLNS_ATTRIBUTE} ("xmlns")</th>124* <td>{@code XMLConstants.XMLNS_ATTRIBUTE_NS_URI}125* ("http://www.w3.org/2000/xmlns/")</td>126* </tr>127* <tr>128* <th scope="row">{@code null}</th>129* <td>{@code IllegalArgumentException} is thrown</td>130* </tr>131* </tbody>132* </table>133*134* @param prefix prefix to look up135*136* @return Namespace URI bound to prefix in the current scope137*138* @throws IllegalArgumentException When {@code prefix} is139* {@code null}140*/141String getNamespaceURI(String prefix);142143/**144* Get prefix bound to Namespace URI in the current scope.145*146* <p>To get all prefixes bound to a Namespace URI in the current147* scope, use {@link #getPrefixes(String namespaceURI)}.148*149* <p>When requesting a prefix by Namespace URI, the following150* table describes the returned prefix value for all Namespace URI151* values:152*153* <table class="striped">154* <caption>Return value for specified Namespace URIs</caption>155* <thead>156* <tr>157* <th scope="col">Namespace URI parameter</th>158* <th scope="col">prefix value returned</th>159* </tr>160* </thead>161* <tbody>162* <tr>163* <th scope="row">{@code <default Namespace URI>}</th>164* <td>{@code XMLConstants.DEFAULT_NS_PREFIX} ("")165* </td>166* </tr>167* <tr>168* <th scope="row">bound Namespace URI</th>169* <td>prefix bound to Namespace URI in the current scope,170* if multiple prefixes are bound to the Namespace URI in171* the current scope, a single arbitrary prefix, whose172* choice is implementation dependent, is returned</td>173* </tr>174* <tr>175* <th scope="row">unbound Namespace URI</th>176* <td>{@code null}</td>177* </tr>178* <tr>179* <th scope="row">{@code XMLConstants.XML_NS_URI}180* ("http://www.w3.org/XML/1998/namespace")</th>181* <td>{@code XMLConstants.XML_NS_PREFIX} ("xml")</td>182* </tr>183* <tr>184* <th scope="row">{@code XMLConstants.XMLNS_ATTRIBUTE_NS_URI}185* ("http://www.w3.org/2000/xmlns/")</th>186* <td>{@code XMLConstants.XMLNS_ATTRIBUTE} ("xmlns")</td>187* </tr>188* <tr>189* <th scope="row">{@code null}</th>190* <td>{@code IllegalArgumentException} is thrown</td>191* </tr>192* </tbody>193* </table>194*195* @param namespaceURI URI of Namespace to lookup196*197* @return prefix bound to Namespace URI in current context198*199* @throws IllegalArgumentException When {@code namespaceURI} is200* {@code null}201*/202String getPrefix(String namespaceURI);203204/**205* Get all prefixes bound to a Namespace URI in the current206* scope.207*208* <p>An Iterator over String elements is returned in an arbitrary,209* <strong>implementation dependent</strong>, order.210*211* <p><strong>The {@code Iterator} is212* <em>not</em> modifiable. e.g. the213* {@code remove()} method will throw214* {@code UnsupportedOperationException}.</strong>215*216* <p>When requesting prefixes by Namespace URI, the following217* table describes the returned prefixes value for all Namespace218* URI values:219*220* <table class="striped">221* <caption>Return value for specified Namespace URIs</caption>222* <thead>223* <tr>224* <th scope="col">Namespace URI parameter</th>225* <th scope="col">prefixes value returned</th>226* </tr>227* </thead>228* <tbody>229* <tr>230* <th scope="row">bound Namespace URI,231* including the {@code <default Namespace URI>}</th>232* <td>233* {@code Iterator} over prefixes bound to Namespace URI in234* the current scope in an arbitrary,235* <strong>implementation dependent</strong>,236* order237* </td>238* </tr>239* <tr>240* <th scope="row">unbound Namespace URI</th>241* <td>empty {@code Iterator}</td>242* </tr>243* <tr>244* <th scope="row">{@code XMLConstants.XML_NS_URI}245* ("http://www.w3.org/XML/1998/namespace")</th>246* <td>{@code Iterator} with one element set to247* {@code XMLConstants.XML_NS_PREFIX} ("xml")</td>248* </tr>249* <tr>250* <th scope="row">{@code XMLConstants.XMLNS_ATTRIBUTE_NS_URI}251* ("http://www.w3.org/2000/xmlns/")</th>252* <td>{@code Iterator} with one element set to253* {@code XMLConstants.XMLNS_ATTRIBUTE} ("xmlns")</td>254* </tr>255* <tr>256* <th scope="row">{@code null}</th>257* <td>{@code IllegalArgumentException} is thrown</td>258* </tr>259* </tbody>260* </table>261*262* @param namespaceURI URI of Namespace to lookup263*264* @return {@code Iterator} for all prefixes bound to the265* Namespace URI in the current scope266*267* @throws IllegalArgumentException When {@code namespaceURI} is268* {@code null}269*/270Iterator<String> getPrefixes(String namespaceURI);271}272273274