325N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 325N/A * This code is free software; you can redistribute it and/or modify it 325N/A * under the terms of the GNU General Public License version 2 only, as 325N/A * published by the Free Software Foundation. Oracle designates this 325N/A * particular file as subject to the "Classpath" exception as provided 325N/A * by Oracle in the LICENSE file that accompanied this code. 325N/A * This code is distributed in the hope that it will be useful, but WITHOUT 325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 325N/A * version 2 for more details (a copy is included in the LICENSE file that 325N/A * accompanied this code). 325N/A * You should have received a copy of the GNU General Public License version 325N/A * 2 along with this work; if not, write to the Free Software Foundation, 325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 325N/A * or visit www.oracle.com if you need additional information or have any 325N/A * A helper class for managing the declaration of namespaces. 325N/A * A namespace is declared on a namespace context. 325N/A * Namespace contexts are pushed on and popped off the namespace context stack. 325N/A * A declared namespace will be in scope iff the context that it was declared on 325N/A * has not been popped off the stack. 325N/A * When instantiated the namespace stack consists of the root namespace context, 325N/A * which contains, by default, the "xml" and "xmlns" declarations. 325N/A * Namespaces may be declarations may be declared on the root context. 325N/A * The root context cannot be popped but can be reset to contain just the 325N/A * "xml" and "xmlns" declarations. 325N/A * Implementation note: determining the prefix from a namespace URI 325N/A * (or vice versa) is efficient when there are few namespace 325N/A * declarations i.e. what is considered to be the case for namespace 325N/A * declarations in 'average' XML documents. The look up of a namespace URI 325N/A * given a prefix is performed in O(n) time. The look up of a prefix given 325N/A * a namespace URI is performed in O(2n) time. 325N/A * The implementation does not scale when there are many namespace 325N/A * declarations. TODO: Use a hash map when there are many namespace 325N/A * @author Paul.Sandoz@Sun.Com 325N/A // The prefixes of the namespace declarations 325N/A // The URIs of the namespace declarations 325N/A // Current position to store the next namespace declaration 325N/A // The namespace contexts 325N/A // Current position to store the next namespace context 325N/A // The current namespace context 325N/A * Create a new NamespaceContexHelper. 325N/A // The default namespace declarations that are always in scope 325N/A // NamespaceContext interface 325N/A // Check if prefix is out of scope 325N/A // Check if prefix is out of scope 325N/A // NamespaceContextEx interface 325N/A // Check if prefix is out of scope 325N/A * Declare a default namespace. 325N/A * @param namespaceURI the namespace URI to declare, may be null. 325N/A * The namespace will be declared on the current namespace context. 325N/A * The namespace can be removed by popping the current namespace 325N/A * context, or, if the declaration occured in the root context, by 325N/A * reseting the namespace context. 325N/A * A default namespace can be declared by passing <code>""</code> as 325N/A * the value of the prefix parameter. 325N/A * A namespace may be undeclared by passing <code>null</code> as the 325N/A * value of the namespaceURI parameter. 325N/A * @param prefix the namespace prefix to declare, may not be null. 325N/A * @param namespaceURI the namespace URI to declare, may be null. 325N/A * @throws IllegalArgumentException, if the prefix is null. 325N/A // Ignore the "xml" or "xmlns" declarations 325N/A // Check for undeclaration 325N/A * Push a namespace context on the stack. 325N/A * Pop the namespace context off the stack. 325N/A * Namespaces declared within the context (to be popped) 325N/A * will be removed and no longer be in scope. 325N/A * Reset namespace contexts. 325N/A * Pop all namespace contexts and reset the root context.