KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > xni > NamespaceContext


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

16
17 package org.apache.xerces.xni;
18
19 import java.util.Enumeration JavaDoc;
20
21 /**
22  * Represents an interface to query namespace information.
23  * <p>
24  * The prefix and namespace must be identical references for equal strings, thus
25  * each string should be internalized (@see String.intern())
26  * or added to the <code>SymbolTable</code>
27  *
28  * @see <a HREF="../../../../../xerces2/org/apache/xerces/util/SymbolTable.html">
29  * org.apache.xerces.util.SymbolTable</a>
30  *
31  * @author Andy Clark, IBM
32  *
33  * @version $Id: NamespaceContext.java,v 1.11 2004/02/24 23:15:54 mrglavas Exp $
34  */

35 public interface NamespaceContext {
36
37     //
38
// Constants
39
//
40

41     /**
42      * The XML Namespace ("http://www.w3.org/XML/1998/namespace"). This is
43      * the Namespace URI that is automatically mapped to the "xml" prefix.
44      */

45     public final static String JavaDoc XML_URI = "http://www.w3.org/XML/1998/namespace".intern();
46
47     /**
48      * XML Information Set REC
49      * all namespace attributes (including those named xmlns,
50      * whose [prefix] property has no value) have a namespace URI of http://www.w3.org/2000/xmlns/
51      */

52     public final static String JavaDoc XMLNS_URI = "http://www.w3.org/2000/xmlns/".intern();
53
54     //
55
// NamespaceContext methods
56
//
57

58     /**
59      * Start a new Namespace context.
60      * <p>
61      * A new context should be pushed at the beginning
62      * of each XML element: the new context will automatically inherit
63      * the declarations of its parent context, but it will also keep
64      * track of which declarations were made within this context.
65      * <p>
66      *
67      * @see #popContext
68      */

69     public void pushContext();
70
71    /**
72      * Revert to the previous Namespace context.
73      * <p>
74      * The context should be popped at the end of each
75      * XML element. After popping the context, all Namespace prefix
76      * mappings that were previously in force are restored.
77      * <p>
78      * Users must not attempt to declare additional Namespace
79      * prefixes after popping a context, unless you push another
80      * context first.
81      *
82      * @see #pushContext
83      */

84     public void popContext();
85
86     /**
87      * Declare a Namespace prefix.
88      * <p>
89      * This method declares a prefix in the current Namespace
90      * context; the prefix will remain in force until this context
91      * is popped, unless it is shadowed in a descendant context.
92      * <p>
93      * Note that to declare a default Namespace, use the empty string.
94      * The prefixes "xml" and "xmlns" can't be rebound.
95      * <p>
96      * Note that you must <em>not</em> declare a prefix after
97      * you've pushed and popped another Namespace.
98      *
99      * @param prefix The prefix to declare, or null for the empty
100      * string.
101      * @param uri The Namespace URI to associate with the prefix.
102      *
103      * @return true if the prefix was legal, false otherwise
104      *
105      * @see #getURI
106      * @see #getDeclaredPrefixAt
107      */

108     public boolean declarePrefix(String JavaDoc prefix, String JavaDoc uri);
109     
110
111     /**
112      * Look up a prefix and get the currently-mapped Namespace URI.
113      * <p>
114      * This method looks up the prefix in the current context. If no mapping
115      * is found, this methods will continue lookup in the parent context(s).
116      * Use the empty string ("") for the default Namespace.
117      *
118      * @param prefix The prefix to look up.
119      *
120      * @return The associated Namespace URI, or null if the prefix
121      * is undeclared in this context.
122      */

123     public String JavaDoc getURI(String JavaDoc prefix);
124     
125     /**
126      * Look up a namespace URI and get one of the mapped prefix.
127      * <p>
128      * This method looks up the namespace URI in the current context.
129      * If more than one prefix is currently mapped to the same URI,
130      * this method will make an arbitrary selection
131      * If no mapping is found, this methods will continue lookup in the
132      * parent context(s).
133      *
134      * @param uri The namespace URI to look up.
135      *
136      * @return One of the associated prefixes, or null if the uri
137      * does not map to any prefix.
138      *
139      * @see #getPrefix
140      */

141     public String JavaDoc getPrefix(String JavaDoc uri);
142     
143     /**
144      * Return a count of locally declared prefixes, including
145      * the default prefix if bound.
146      */

147     public int getDeclaredPrefixCount();
148
149     /**
150      * Returns the prefix at the specified index in the current context.
151      */

152     public String JavaDoc getDeclaredPrefixAt(int index);
153
154     /**
155      * Return an enumeration of all prefixes whose declarations are active
156      * in the current context. This includes declarations from parent contexts
157      * that have not been overridden.
158      * @return Enumeration
159      */

160     public Enumeration JavaDoc getAllPrefixes();
161     
162     /**
163      * Reset this Namespace support object for reuse.
164      *
165      * <p>It is necessary to invoke this method before reusing the
166      * Namespace support object for a new session.</p>
167      *
168      * <p>Note that implementations of this method need to ensure that
169      * the declaration of the prefixes "xmlns" and "xml" are available.</p>
170      */

171     public void reset();
172     
173
174
175 } // interface NamespaceContext
176
Popular Tags