2
* Copyright 2006 The Apache Software Foundation.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
package org.apache.xerces.util;
19
import java.util.Enumeration;
20
import java.util.List;
22
import javax.xml.XMLConstants;
24
import org.apache.xerces.xni.NamespaceContext;
27
* <p>A read-only XNI wrapper around a JAXP NamespaceContext.</p>
29
* @author Michael Glavassevich, IBM
31
* @version $Id: JAXPNamespaceContextWrapper.java 379351 2006-02-21 05:36:35Z mrglavas $
33
public final class JAXPNamespaceContextWrapper implements NamespaceContext {
35
private javax.xml.namespace.NamespaceContext fNamespaceContext;
36
private SymbolTable fSymbolTable;
37
private List fPrefixes;
39
public JAXPNamespaceContextWrapper(SymbolTable symbolTable) {
40
setSymbolTable(symbolTable);
43
public void setNamespaceContext(javax.xml.namespace.NamespaceContext context) {
44
fNamespaceContext = context;
47
public javax.xml.namespace.NamespaceContext getNamespaceContext() {
48
return fNamespaceContext;
51
public void setSymbolTable(SymbolTable symbolTable) {
52
fSymbolTable = symbolTable;
55
public SymbolTable getSymbolTable() {
59
public void setDeclaredPrefixes(List prefixes) {
63
public List getDeclaredPrefixes() {
68
* NamespaceContext methods
71
public String getURI(String prefix) {
72
if (fNamespaceContext != null) {
73
String uri = fNamespaceContext.getNamespaceURI(prefix);
74
if (uri != null && !XMLConstants.NULL_NS_URI.equals(uri)) {
75
return (fSymbolTable != null) ? fSymbolTable.addSymbol(uri) : uri.intern();
81
public String getPrefix(String uri) {
82
if (fNamespaceContext != null) {
84
uri = XMLConstants.NULL_NS_URI;
86
String prefix = fNamespaceContext.getPrefix(uri);
88
prefix = XMLConstants.DEFAULT_NS_PREFIX;
90
return (fSymbolTable != null) ? fSymbolTable.addSymbol(prefix) : prefix.intern();
95
public Enumeration getAllPrefixes() {
96
// It's not possible to get the list of all prefixes from the NamespaceContext
97
// so the best we can do is return an empty enumeration.
98
return new Enumeration () {
99
public boolean hasMoreElements() {
102
public Object nextElement() {
108
public void pushContext() {}
110
public void popContext() {}
112
public boolean declarePrefix(String prefix, String uri) {
116
public int getDeclaredPrefixCount() {
117
return (fPrefixes != null) ? fPrefixes.size() : 0;
120
public String getDeclaredPrefixAt(int index) {
121
return (String) fPrefixes.get(index);
124
public void reset() {}
126
} // JAXPNamespaceContextWrapper