001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.xni;
019:
020: import java.util.Enumeration;
021:
022: /**
023: * Represents an interface to query namespace information.
024: * <p>
025: * The prefix and namespace must be identical references for equal strings, thus
026: * each string should be internalized (@see String.intern())
027: * or added to the <code>SymbolTable</code>
028: *
029: * @see <a href="../../../../../xerces2/org/apache/xerces/util/SymbolTable.html">
030: * org.apache.xerces.util.SymbolTable</a>
031: *
032: * @author Andy Clark, IBM
033: *
034: * @version $Id: NamespaceContext.java 447247 2006-09-18 05:23:52Z mrglavas $
035: */
036: public interface NamespaceContext {
037:
038: //
039: // Constants
040: //
041:
042: /**
043: * The XML Namespace ("http://www.w3.org/XML/1998/namespace"). This is
044: * the Namespace URI that is automatically mapped to the "xml" prefix.
045: */
046: public final static String XML_URI = "http://www.w3.org/XML/1998/namespace"
047: .intern();
048:
049: /**
050: * XML Information Set REC
051: * all namespace attributes (including those named xmlns,
052: * whose [prefix] property has no value) have a namespace URI of http://www.w3.org/2000/xmlns/
053: */
054: public final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/"
055: .intern();
056:
057: //
058: // NamespaceContext methods
059: //
060:
061: /**
062: * Start a new Namespace context.
063: * <p>
064: * A new context should be pushed at the beginning
065: * of each XML element: the new context will automatically inherit
066: * the declarations of its parent context, but it will also keep
067: * track of which declarations were made within this context.
068: * <p>
069: *
070: * @see #popContext
071: */
072: public void pushContext();
073:
074: /**
075: * Revert to the previous Namespace context.
076: * <p>
077: * The context should be popped at the end of each
078: * XML element. After popping the context, all Namespace prefix
079: * mappings that were previously in force are restored.
080: * <p>
081: * Users must not attempt to declare additional Namespace
082: * prefixes after popping a context, unless you push another
083: * context first.
084: *
085: * @see #pushContext
086: */
087: public void popContext();
088:
089: /**
090: * Declare a Namespace prefix.
091: * <p>
092: * This method declares a prefix in the current Namespace
093: * context; the prefix will remain in force until this context
094: * is popped, unless it is shadowed in a descendant context.
095: * <p>
096: * Note that to declare a default Namespace, use the empty string.
097: * The prefixes "xml" and "xmlns" can't be rebound.
098: * <p>
099: * Note that you must <em>not</em> declare a prefix after
100: * you've pushed and popped another Namespace.
101: *
102: * @param prefix The prefix to declare, or null for the empty
103: * string.
104: * @param uri The Namespace URI to associate with the prefix.
105: *
106: * @return true if the prefix was legal, false otherwise
107: *
108: * @see #getURI
109: * @see #getDeclaredPrefixAt
110: */
111: public boolean declarePrefix(String prefix, String uri);
112:
113: /**
114: * Look up a prefix and get the currently-mapped Namespace URI.
115: * <p>
116: * This method looks up the prefix in the current context. If no mapping
117: * is found, this methods will continue lookup in the parent context(s).
118: * Use the empty string ("") for the default Namespace.
119: *
120: * @param prefix The prefix to look up.
121: *
122: * @return The associated Namespace URI, or null if the prefix
123: * is undeclared in this context.
124: */
125: public String getURI(String prefix);
126:
127: /**
128: * Look up a namespace URI and get one of the mapped prefix.
129: * <p>
130: * This method looks up the namespace URI in the current context.
131: * If more than one prefix is currently mapped to the same URI,
132: * this method will make an arbitrary selection
133: * If no mapping is found, this methods will continue lookup in the
134: * parent context(s).
135: *
136: * @param uri The namespace URI to look up.
137: *
138: * @return One of the associated prefixes, or null if the uri
139: * does not map to any prefix.
140: *
141: * @see #getPrefix
142: */
143: public String getPrefix(String uri);
144:
145: /**
146: * Return a count of locally declared prefixes, including
147: * the default prefix if bound.
148: */
149: public int getDeclaredPrefixCount();
150:
151: /**
152: * Returns the prefix at the specified index in the current context.
153: */
154: public String getDeclaredPrefixAt(int index);
155:
156: /**
157: * Return an enumeration of all prefixes whose declarations are active
158: * in the current context. This includes declarations from parent contexts
159: * that have not been overridden.
160: * @return Enumeration
161: */
162: public Enumeration getAllPrefixes();
163:
164: /**
165: * Reset this Namespace support object for reuse.
166: *
167: * <p>It is necessary to invoke this method before reusing the
168: * Namespace support object for a new session.</p>
169: *
170: * <p>Note that implementations of this method need to ensure that
171: * the declaration of the prefixes "xmlns" and "xml" are available.</p>
172: */
173: public void reset();
174:
175: } // interface NamespaceContext
|