01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.sail.memory;
07:
08: import java.util.Iterator;
09: import java.util.LinkedHashMap;
10: import java.util.Map;
11:
12: import org.openrdf.model.impl.NamespaceImpl;
13:
14: /**
15: * An in-memory store for namespace prefix information.
16: *
17: * @author Arjohn Kampman
18: */
19: class MemNamespaceStore implements Iterable<NamespaceImpl> {
20:
21: /*-----------*
22: * Variables *
23: *-----------*/
24:
25: /**
26: * Map storing namespace information by their prefix.
27: */
28: private Map<String, NamespaceImpl> namespacesMap;
29:
30: /*--------------*
31: * Constructors *
32: *--------------*/
33:
34: public MemNamespaceStore() {
35: namespacesMap = new LinkedHashMap<String, NamespaceImpl>(16);
36: }
37:
38: /*---------*
39: * Methods *
40: *---------*/
41:
42: public String getNamespace(String prefix) {
43: String result = null;
44: NamespaceImpl namespace = namespacesMap.get(prefix);
45: if (namespace != null) {
46: result = namespace.getName();
47: }
48: return result;
49: }
50:
51: public void setNamespace(String prefix, String name) {
52: NamespaceImpl ns = namespacesMap.get(prefix);
53:
54: if (ns != null) {
55: ns.setName(name);
56: } else {
57: namespacesMap.put(prefix, new NamespaceImpl(prefix, name));
58: }
59: }
60:
61: public void removeNamespace(String prefix) {
62: namespacesMap.remove(prefix);
63: }
64:
65: public Iterator<NamespaceImpl> iterator() {
66: return namespacesMap.values().iterator();
67: }
68:
69: public void clear() {
70: namespacesMap.clear();
71: }
72: }
|