1. // $Id: NamespaceContext.java,v 1.4.16.1 2004/06/28 18:20:38 ndw Exp $
  2. /*
  3. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  4. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  5. */
  6. package javax.xml.namespace;
  7. import java.util.Iterator;
  8. /**
  9. * <p>Interface for read only XML Namespace context processing.</p>
  10. *
  11. * <p>An XML Namespace has the properties:</p>
  12. * <ul>
  13. * <li>Namespace URI:
  14. * Namespace name expressed as a URI to which the prefix is bound</li>
  15. * <li>prefix: syntactically, this is the part of the attribute name
  16. * following the <code>XMLConstants.XMLNS_ATTRIBUTE</code>
  17. * ("xmlns") in the Namespace declaration</li>
  18. * </ul>
  19. * <p> example: <code><element xmlns:prefix="http://Namespace-name-URI"></code></p>
  20. *
  21. * <p>All <code>get*(*)</code> methods operate in the current scope
  22. * for Namespace URI and prefix resolution.</p>
  23. *
  24. * <p>Note that a Namespace URI can be bound to
  25. * <strong>multiple</strong> prefixes in the current scope. This can
  26. * occur when multiple <code>XMLConstants.XMLNS_ATTRIBUTE</code>
  27. * ("xmlns") Namespace declarations occur in the same Start-Tag and
  28. * refer to the same Namespace URI. e.g.<br />
  29. * <pre>
  30. * <element xmlns:prefix1="http://Namespace-name-URI"
  31. * xmlns:prefix2="http://Namespace-name-URI">
  32. * </pre>
  33. * This can also occur when the same Namespace URI is used in multiple
  34. * <code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns") Namespace
  35. * declarations in the logical parent element hierarchy. e.g.<br />
  36. * <pre>
  37. * <parent xmlns:prefix1="http://Namespace-name-URI">
  38. * <child xmlns:prefix2="http://Namespace-name-URI">
  39. * ...
  40. * </child>
  41. * </parent>
  42. * </pre></p>
  43. *
  44. * <p>A prefix can only be bound to a <strong>single</strong>
  45. * Namespace URI in the current scope.</p>
  46. *
  47. * @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
  48. * @version $Revision: 1.4.16.1 $, $Date: 2004/06/28 18:20:38 $
  49. * @see javax.xml.XMLConstants javax.XMLConstants for declarations of common XML values
  50. * @see <a href="http://www.w3.org/TR/xmlschema-2/#QName">XML Schema Part2: Datatypes</a>
  51. * @see <a href="http://www.w3.org/TR/REC-xml-names/#ns-qualnames">Namespaces in XML</a>
  52. * @see <a href="http://www.w3.org/XML/xml-names-19990114-errata">Namespaces in XML Errata</a>
  53. * @since 1.5
  54. */
  55. public interface NamespaceContext {
  56. /**
  57. * <p>Get Namespace URI bound to a prefix in the current scope.</p>
  58. *
  59. * <p>When requesting a Namespace URI by prefix, the following
  60. * table describes the returned Namespace URI value for all
  61. * possible prefix values:</p>
  62. *
  63. * <table border="2" rules="all" cellpadding="4">
  64. * <thead>
  65. * <tr>
  66. * <td align="center" colspan="2">
  67. * <code>getNamespaceURI(prefix)</code>
  68. * return value for specified prefixes
  69. * </td>
  70. * </tr>
  71. * <tr>
  72. * <td>prefix parameter</td>
  73. * <td>Namespace URI return value</td>
  74. * </tr>
  75. * </thead>
  76. * <tbody>
  77. * <tr>
  78. * <td><code>DEFAULT_NS_PREFIX</code> ("")</td>
  79. * <td>default Namespace URI in the current scope or
  80. * <code>{@link javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI("")}</code>
  81. * when there is no default Namespace URI in the current scope</td>
  82. * </tr>
  83. * <tr>
  84. * <td>bound prefix</td>
  85. * <td>Namespace URI bound to prefix in current scope</td>
  86. * </tr>
  87. * <tr>
  88. * <td>unbound prefix</td>
  89. * <td><code>{@link javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI("")}</code> </td>
  90. * </tr>
  91. * <tr>
  92. * <td><code>XMLConstants.XML_NS_PREFIX</code> ("xml")</td>
  93. * <td><code>XMLConstants.XML_NS_URI</code>
  94. * ("http://www.w3.org/XML/1998/namespace")</td>
  95. * </tr>
  96. * <tr>
  97. * <td><code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns")</td>
  98. * <td><code>XMLConstants.XMLNS_ATTRIBUTE_NS_URI</code>
  99. * ("http://www.w3.org/2000/xmlns/")</td>
  100. * </tr>
  101. * <tr>
  102. * <td><code>null</code></td>
  103. * <td><code>IllegalArgumentException</code> is thrown</td>
  104. * </tr>
  105. * </tbody>
  106. * </table>
  107. *
  108. * @param prefix prefix to look up
  109. * @return Namespace URI bound to prefix in the current scope
  110. */
  111. String getNamespaceURI(String prefix);
  112. /**
  113. * <p>Get prefix bound to Namespace URI in the current scope.</p>
  114. *
  115. * <p>To get all prefixes bound to a Namespace URI in the current
  116. * scope, use {@link #getPrefixes(String namespaceURI)}.</p>
  117. *
  118. * <p>When requesting a prefix by Namespace URI, the following
  119. * table describes the returned prefix value for all Namespace URI
  120. * values:</p>
  121. *
  122. * <table border="2" rules="all" cellpadding="4">
  123. * <thead>
  124. * <tr>
  125. * <td align="center" colspan="2">
  126. * <code>getPrefix(namespaceURI)</code> return value for
  127. * specified Namespace URIs
  128. * </td>
  129. * </tr>
  130. * <tr>
  131. * <td>Namespace URI parameter</td>
  132. * <td>prefix value returned</td>
  133. * </tr>
  134. * </thead>
  135. * <tbody>
  136. * <tr>
  137. * <td><default Namespace URI></td>
  138. * <td><code>XMLConstants.DEFAULT_NS_PREFIX</code> ("")
  139. * </td>
  140. * </tr>
  141. * <tr>
  142. * <td>bound Namespace URI</td>
  143. * <td>prefix bound to Namespace URI in the current scope,
  144. * if multiple prefixes are bound to the Namespace URI in
  145. * the current scope, a single arbitrary prefix, whose
  146. * choice is implementation dependent, is returned</td>
  147. * </tr>
  148. * <tr>
  149. * <td>unbound Namespace URI</td>
  150. * <td><code>null</code></td>
  151. * </tr>
  152. * <tr>
  153. * <td><code>XMLConstants.XML_NS_URI</code>
  154. * ("http://www.w3.org/XML/1998/namespace")</td>
  155. * <td><code>XMLConstants.XML_NS_PREFIX</code> ("xml")</td>
  156. * </tr>
  157. * <tr>
  158. * <td><code>XMLConstants.XMLNS_ATTRIBUTE_NS_URI</code>
  159. * ("http://www.w3.org/2000/xmlns/")</td>
  160. * <td><code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns")</td>
  161. * </tr>
  162. * <tr>
  163. * <td><code>null</code></td>
  164. * <td><code>IllegalArgumentException</code> is thrown</td>
  165. * </tr>
  166. * </tbody>
  167. * </table>
  168. *
  169. * @param namespaceURI URI of Namespace to lookup
  170. * @return prefix bound to Namespace URI in current context
  171. */
  172. String getPrefix(String namespaceURI);
  173. /**
  174. * <p>Get all prefixes bound to a Namespace URI in the current
  175. * scope.</p>
  176. *
  177. * <p>An Iterator over String elements is returned in an arbitrary, <strong>implementation dependent</strong>, order.</p>
  178. *
  179. * <p><strong>The <code>Iterator</code> is
  180. * <em>not</em> modifiable. e.g. the
  181. * <code>remove()</code> method will throw
  182. * <code>UnsupportedOperationException</code>.</strong></p>
  183. *
  184. * <p>When requesting prefixes by Namespace URI, the following
  185. * table describes the returned prefixes value for all Namespace
  186. * URI values:</p>
  187. *
  188. * <table border="2" rules="all" cellpadding="4">
  189. * <thead>
  190. * <tr>
  191. * <td align="center" colspan="2"><code>
  192. * getPrefixes(namespaceURI)</code> return value for
  193. * specified Namespace URIs</td>
  194. * </tr>
  195. * <tr>
  196. * <td>Namespace URI parameter</td>
  197. * <td>prefixes value returned</td>
  198. * </tr>
  199. * </thead>
  200. * <tbody>
  201. * <tr>
  202. * <td>bound Namespace URI,
  203. * including the <default Namespace URI></td>
  204. * <td><code>Iterator</code> over prefixes bound to Namespace URI in
  205. * the current scope in an arbitrary, <strong>implementation dependent</strong>,
  206. * order</td>
  207. * </tr>
  208. * <tr>
  209. * <td>unbound Namespace URI</td>
  210. * <td>empty <code>Iterator</code></td>
  211. * </tr>
  212. * <tr>
  213. * <td><code>XMLConstants.XML_NS_URI</code>
  214. * ("http://www.w3.org/XML/1998/namespace")</td>
  215. * <td><code>Iterator</code> with one element set to
  216. * <code>XMLConstants.XML_NS_PREFIX</code> ("xml")</td>
  217. * </tr>
  218. * <tr>
  219. * <td><code>XMLConstants.XMLNS_ATTRIBUTE_NS_URI</code>
  220. * ("http://www.w3.org/2000/xmlns/")</td>
  221. * <td><code>Iterator</code> with one element set to
  222. * <code>XMLConstants.XMLNS_ATTRIBUTE</code> ("xmlns")</td>
  223. * </tr>
  224. * <tr>
  225. * <td><code>null</code></td>
  226. * <td><code>IllegalArgumentException</code> is thrown</td>
  227. * </tr>
  228. * </tbody>
  229. * </table>
  230. *
  231. * @param namespaceURI URI of Namespace to lookup
  232. * @return <code>Iterator</code> for all prefixes bound to the
  233. * Namespace URI in the current scope
  234. */
  235. Iterator getPrefixes(String namespaceURI);
  236. }