001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2001, 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package com.sun.xml.stream.xerces.xni;
059:
060: import java.util.Enumeration;
061: import java.util.Iterator;
062: import java.util.Vector;
063:
064: /**
065: * Represents an interface to query namespace information.
066: * <p>
067: * The prefix and namespace must be identical references for equal strings, thus
068: * each string should be internalized (@see String.intern())
069: * or added to the <code>SymbolTable</code>
070: *
071: * @see <a href="../../../../../xerces2/com/sun/xml/stream/xerces/util/SymbolTable.html">
072: * com.sun.xml.stream.xerces.util.SymbolTable</a>
073: *
074: * @author Andy Clark, IBM
075: *
076: * @version $Id: NamespaceContext.java,v 1.2 2006/04/01 06:01:45 jeffsuttor Exp $
077: */
078: public interface NamespaceContext {
079:
080: //
081: // Constants
082: //
083:
084: /**
085: * The XML Namespace ("http://www.w3.org/XML/1998/namespace"). This is
086: * the Namespace URI that is automatically mapped to the "xml" prefix.
087: */
088: public final static String XML_URI = "http://www.w3.org/XML/1998/namespace"
089: .intern();
090:
091: /**
092: * XML Information Set REC
093: * all namespace attributes (including those named xmlns,
094: * whose [prefix] property has no value) have a namespace URI of http://www.w3.org/2000/xmlns/
095: */
096: public final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/"
097: .intern();
098:
099: //
100: // NamespaceContext methods
101: //
102:
103: /**
104: * Start a new Namespace context.
105: * <p>
106: * A new context should be pushed at the beginning
107: * of each XML element: the new context will automatically inherit
108: * the declarations of its parent context, but it will also keep
109: * track of which declarations were made within this context.
110: * <p>
111: *
112: * @see #popContext
113: */
114: public void pushContext();
115:
116: /**
117: * Revert to the previous Namespace context.
118: * <p>
119: * The context should be popped at the end of each
120: * XML element. After popping the context, all Namespace prefix
121: * mappings that were previously in force are restored.
122: * <p>
123: * Users must not attempt to declare additional Namespace
124: * prefixes after popping a context, unless you push another
125: * context first.
126: *
127: * @see #pushContext
128: */
129: public void popContext();
130:
131: /**
132: * Declare a Namespace prefix.
133: * <p>
134: * This method declares a prefix in the current Namespace
135: * context; the prefix will remain in force until this context
136: * is popped, unless it is shadowed in a descendant context.
137: * <p>
138: * Note that to declare a default Namespace, use the empty string.
139: * The prefixes "xml" and "xmlns" can't be rebound.
140: * <p>
141: * Note that you must <em>not</em> declare a prefix after
142: * you've pushed and popped another Namespace.
143: *
144: * @param prefix The prefix to declare, or null for the empty
145: * string.
146: * @param uri The Namespace URI to associate with the prefix.
147: *
148: * @return true if the prefix was legal, false otherwise
149: *
150: * @see #getURI
151: * @see #getDeclaredPrefixAt
152: */
153: public boolean declarePrefix(String prefix, String uri);
154:
155: /**
156: * Look up a prefix and get the currently-mapped Namespace URI.
157: * <p>
158: * This method looks up the prefix in the current context. If no mapping
159: * is found, this methods will continue lookup in the parent context(s).
160: * Use the empty string ("") for the default Namespace.
161: *
162: * @param prefix The prefix to look up.
163: *
164: * @return The associated Namespace URI, or null if the prefix
165: * is undeclared in this context.
166: */
167: public String getURI(String prefix);
168:
169: /**
170: * Look up a namespace URI and get one of the mapped prefix.
171: * <p>
172: * This method looks up the namespace URI in the current context.
173: * If more than one prefix is currently mapped to the same URI,
174: * this method will make an arbitrary selection
175: * If no mapping is found, this methods will continue lookup in the
176: * parent context(s).
177: *
178: * @param uri The namespace URI to look up.
179: *
180: * @return One of the associated prefixes, or null if the uri
181: * does not map to any prefix.
182: *
183: * @see #getPrefix
184: */
185: public String getPrefix(String uri);
186:
187: /**
188: * Return a count of locally declared prefixes, including
189: * the default prefix if bound.
190: */
191: public int getDeclaredPrefixCount();
192:
193: /**
194: * Returns the prefix at the specified index in the current context.
195: */
196: public String getDeclaredPrefixAt(int index);
197:
198: /**
199: * Return an enumeration of all prefixes whose declarations are active
200: * in the current context. This includes declarations from parent contexts
201: * that have not been overridden.
202: * @return Enumeration
203: */
204: public Enumeration getAllPrefixes();
205:
206: public Vector getPrefixes(String uri);
207:
208: /**
209: * Reset this Namespace support object for reuse.
210: *
211: * <p>It is necessary to invoke this method before reusing the
212: * Namespace support object for a new session.</p>
213: *
214: * <p>Note that implementations of this method need to ensure that
215: * the declaration of the prefixes "xmlns" and "xml" are available.</p>
216: */
217: public void reset();
218:
219: } // interface NamespaceContext
|