~ubuntu-branches/ubuntu/karmic/libxerces2-java/karmic

« back to all changes in this revision

Viewing changes to src/org/apache/xerces/util/JAXPNamespaceContextWrapper.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-12-04 17:37:55 UTC
  • mfrom: (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20061204173755-hb6ybrrrk097zhx7
Tags: 2.8.1-1ubuntu1
* Merge with Debian unstable; remaining changes:
  - Build -gcj package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2006 The Apache Software Foundation.
 
3
 * 
 
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
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
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.
 
15
 */
 
16
 
 
17
package org.apache.xerces.util;
 
18
 
 
19
import java.util.Enumeration;
 
20
import java.util.List;
 
21
 
 
22
import javax.xml.XMLConstants;
 
23
 
 
24
import org.apache.xerces.xni.NamespaceContext;
 
25
 
 
26
/**
 
27
 * <p>A read-only XNI wrapper around a JAXP NamespaceContext.</p>
 
28
 * 
 
29
 * @author Michael Glavassevich, IBM
 
30
 * 
 
31
 * @version $Id: JAXPNamespaceContextWrapper.java 379351 2006-02-21 05:36:35Z mrglavas $
 
32
 */
 
33
public final class JAXPNamespaceContextWrapper implements NamespaceContext {
 
34
    
 
35
    private javax.xml.namespace.NamespaceContext fNamespaceContext;
 
36
    private SymbolTable fSymbolTable;
 
37
    private List fPrefixes;
 
38
 
 
39
    public JAXPNamespaceContextWrapper(SymbolTable symbolTable) {
 
40
        setSymbolTable(symbolTable);
 
41
    }
 
42
    
 
43
    public void setNamespaceContext(javax.xml.namespace.NamespaceContext context) {
 
44
        fNamespaceContext = context;
 
45
    }
 
46
    
 
47
    public javax.xml.namespace.NamespaceContext getNamespaceContext() {
 
48
        return fNamespaceContext;
 
49
    }
 
50
    
 
51
    public void setSymbolTable(SymbolTable symbolTable) {
 
52
        fSymbolTable = symbolTable;
 
53
    }
 
54
    
 
55
    public SymbolTable getSymbolTable() {
 
56
        return fSymbolTable;
 
57
    }
 
58
    
 
59
    public void setDeclaredPrefixes(List prefixes) {
 
60
        fPrefixes = prefixes;
 
61
    }
 
62
    
 
63
    public List getDeclaredPrefixes() {
 
64
        return fPrefixes;
 
65
    }
 
66
    
 
67
    /*
 
68
     * NamespaceContext methods
 
69
     */
 
70
    
 
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();
 
76
            }
 
77
        }
 
78
        return null;
 
79
    }
 
80
 
 
81
    public String getPrefix(String uri) {
 
82
        if (fNamespaceContext != null) {
 
83
            if (uri == null) {
 
84
                uri = XMLConstants.NULL_NS_URI;
 
85
            }
 
86
            String prefix = fNamespaceContext.getPrefix(uri);
 
87
            if (prefix == null) {
 
88
                prefix = XMLConstants.DEFAULT_NS_PREFIX;
 
89
            }
 
90
            return (fSymbolTable != null) ? fSymbolTable.addSymbol(prefix) : prefix.intern();
 
91
        }
 
92
        return null;
 
93
    }
 
94
    
 
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() {
 
100
                return false;
 
101
            }
 
102
            public Object nextElement() {
 
103
                return null;
 
104
            }
 
105
        };
 
106
    }
 
107
 
 
108
    public void pushContext() {}
 
109
 
 
110
    public void popContext() {}
 
111
 
 
112
    public boolean declarePrefix(String prefix, String uri) {
 
113
        return true;
 
114
    }
 
115
 
 
116
    public int getDeclaredPrefixCount() {
 
117
        return (fPrefixes != null) ? fPrefixes.size() : 0;
 
118
    }
 
119
 
 
120
    public String getDeclaredPrefixAt(int index) {
 
121
        return (String) fPrefixes.get(index);
 
122
    }
 
123
 
 
124
    public void reset() {}
 
125
 
 
126
} // JAXPNamespaceContextWrapper