286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Licensed to the Apache Software Foundation (ASF) under one or more
286N/A * contributor license agreements. See the NOTICE file distributed with
286N/A * this work for additional information regarding copyright ownership.
286N/A * The ASF licenses this file to You under the Apache License, Version 2.0
286N/A * (the "License"); you may not use this file except in compliance with
286N/A * the License. You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xerces.internal.util;
286N/A
286N/A
286N/Aimport java.util.Collections;
286N/Aimport java.util.Enumeration;
286N/Aimport java.util.List;
286N/Aimport java.util.TreeSet;
286N/Aimport java.util.Vector;
286N/A
286N/Aimport javax.xml.XMLConstants;
286N/A
286N/Aimport com.sun.org.apache.xerces.internal.xni.NamespaceContext;
286N/A
286N/A/**
286N/A * <p>A read-only XNI wrapper around a JAXP NamespaceContext.</p>
286N/A *
286N/A * @author Michael Glavassevich, IBM
286N/A *
286N/A * @version $Id: JAXPNamespaceContextWrapper.java,v 1.2 2010-10-26 23:01:13 joehw Exp $
286N/A */
286N/Apublic final class JAXPNamespaceContextWrapper implements NamespaceContext {
286N/A
286N/A private javax.xml.namespace.NamespaceContext fNamespaceContext;
286N/A private SymbolTable fSymbolTable;
286N/A private List fPrefixes;
286N/A private final Vector fAllPrefixes = new Vector();
286N/A
286N/A private int[] fContext = new int[8];
286N/A private int fCurrentContext;
286N/A
286N/A public JAXPNamespaceContextWrapper(SymbolTable symbolTable) {
286N/A setSymbolTable(symbolTable);
286N/A }
286N/A
286N/A public void setNamespaceContext(javax.xml.namespace.NamespaceContext context) {
286N/A fNamespaceContext = context;
286N/A }
286N/A
286N/A public javax.xml.namespace.NamespaceContext getNamespaceContext() {
286N/A return fNamespaceContext;
286N/A }
286N/A
286N/A public void setSymbolTable(SymbolTable symbolTable) {
286N/A fSymbolTable = symbolTable;
286N/A }
286N/A
286N/A public SymbolTable getSymbolTable() {
286N/A return fSymbolTable;
286N/A }
286N/A
286N/A public void setDeclaredPrefixes(List prefixes) {
286N/A fPrefixes = prefixes;
286N/A }
286N/A
286N/A public List getDeclaredPrefixes() {
286N/A return fPrefixes;
286N/A }
286N/A
286N/A /*
286N/A * NamespaceContext methods
286N/A */
286N/A
286N/A public String getURI(String prefix) {
286N/A if (fNamespaceContext != null) {
286N/A String uri = fNamespaceContext.getNamespaceURI(prefix);
286N/A if (uri != null && !XMLConstants.NULL_NS_URI.equals(uri)) {
286N/A return (fSymbolTable != null) ? fSymbolTable.addSymbol(uri) : uri.intern();
286N/A }
286N/A }
286N/A return null;
286N/A }
286N/A
286N/A public String getPrefix(String uri) {
286N/A if (fNamespaceContext != null) {
286N/A if (uri == null) {
286N/A uri = XMLConstants.NULL_NS_URI;
286N/A }
286N/A String prefix = fNamespaceContext.getPrefix(uri);
286N/A if (prefix == null) {
286N/A prefix = XMLConstants.DEFAULT_NS_PREFIX;
286N/A }
286N/A return (fSymbolTable != null) ? fSymbolTable.addSymbol(prefix) : prefix.intern();
286N/A }
286N/A return null;
286N/A }
286N/A
286N/A public Enumeration getAllPrefixes() {
286N/A // There may be duplicate prefixes in the list so we
286N/A // first transfer them to a set to ensure uniqueness.
286N/A return Collections.enumeration(new TreeSet(fAllPrefixes));
286N/A }
286N/A
286N/A public void pushContext() {
286N/A // extend the array, if necessary
286N/A if (fCurrentContext + 1 == fContext.length) {
286N/A int[] contextarray = new int[fContext.length * 2];
286N/A System.arraycopy(fContext, 0, contextarray, 0, fContext.length);
286N/A fContext = contextarray;
286N/A }
286N/A // push context
286N/A fContext[++fCurrentContext] = fAllPrefixes.size();
286N/A if (fPrefixes != null) {
286N/A fAllPrefixes.addAll(fPrefixes);
286N/A }
286N/A }
286N/A
286N/A public void popContext() {
286N/A fAllPrefixes.setSize(fContext[fCurrentContext--]);
286N/A }
286N/A
286N/A public boolean declarePrefix(String prefix, String uri) {
286N/A return true;
286N/A }
286N/A
286N/A public int getDeclaredPrefixCount() {
286N/A return (fPrefixes != null) ? fPrefixes.size() : 0;
286N/A }
286N/A
286N/A public String getDeclaredPrefixAt(int index) {
286N/A return (String) fPrefixes.get(index);
286N/A }
286N/A
286N/A public void reset() {
286N/A fCurrentContext = 0;
286N/A fContext[fCurrentContext] = 0;
286N/A fAllPrefixes.clear();
286N/A }
286N/A
286N/A} // JAXPNamespaceContextWrapper