1
/* Copyright 2002-2005 Elliotte Rusty Harold
3
This library is free software; you can redistribute it and/or modify
4
it under the terms of version 2.1 of the GNU Lesser General Public
5
License as published by the Free Software Foundation.
7
This library is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU Lesser General Public License for more details.
12
You should have received a copy of the GNU Lesser General Public
13
License along with this library; if not, write to the
14
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
15
Boston, MA 02111-1307 USA
17
You can contact Elliotte Rusty Harold by sending e-mail to
18
elharo@metalab.unc.edu. Please include the word "XOM" in the
19
subject line. The XOM home page is located at http://www.xom.nu/
24
import java.util.ArrayList;
25
import java.util.HashMap;
29
* The <code>Namespaces</code> container is a read-only list
30
* used to hold the additional namespace declarations of an
31
* element. It provides indexed access for convenience,
32
* but the order is neither predictable nor reproducible,
36
* @author Elliotte Rusty Harold
41
private HashMap namespaces = new HashMap(1);
42
private ArrayList prefixes = new ArrayList(1);
45
void put(String prefix, String URI) {
46
namespaces.put(prefix, URI);
47
prefixes.remove(prefix);
52
void remove(String prefix) {
53
if (prefix == null) prefix = "";
54
namespaces.remove(prefix);
55
prefixes.remove(prefix);
61
* Return the URI associated with a prefix, as determined
62
* by the namespaces stored in this list. This method
63
* returns null if the prefix is not found in the list.
66
* @param prefix the prefix whose URI is desired
68
* @return the namespace URI for this prefix, or null if this
69
* prefix is not not mapped to a URI by these namespace
72
String getURI(String prefix) {
73
return (String) (namespaces.get(prefix));
77
// This violates encapsulation. Don't change the
79
ArrayList getPrefixes() {
86
Namespaces result = new Namespaces();
87
// shallow copies work here because these collections only
88
// contain immutable strings
89
result.namespaces = (HashMap) this.namespaces.clone();
90
result.prefixes = (ArrayList) this.prefixes.clone();
97
return prefixes.size();
101
String getPrefix(int i) {
102
return (String) prefixes.get(i);
b'\\ No newline at end of file'