01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.helpers;
19:
20: import java.util.HashMap;
21: import java.util.Iterator;
22: import java.util.Map;
23: import javax.xml.namespace.NamespaceContext;
24: import org.w3c.dom.Node;
25:
26: public final class MapNamespaceContext implements NamespaceContext {
27: private Map<String, String> namespaces = new HashMap<String, String>();
28: private Node targetNode;
29:
30: public MapNamespaceContext() {
31: super ();
32: }
33:
34: public MapNamespaceContext(final Map<String, String> ns) {
35: this ();
36: this .namespaces = ns;
37: }
38:
39: public MapNamespaceContext(final Node node) {
40: this ();
41: this .targetNode = node;
42: }
43:
44: public void setTargetNode(final Node node) {
45: this .targetNode = node;
46: }
47:
48: public void addNamespace(final String prefix,
49: final String namespaceURI) {
50: this .namespaces.put(prefix, namespaceURI);
51: }
52:
53: public void addNamespaces(final Map<String, String> ns) {
54: this .namespaces.putAll(ns);
55: }
56:
57: public String getNamespaceURI(String prefix) {
58: if (targetNode != null) {
59: String s = targetNode.lookupNamespaceURI(prefix);
60: if (prefix != null && s != null) {
61: namespaces.put(prefix, s);
62: }
63: }
64: return namespaces.get(prefix);
65: }
66:
67: public String getPrefix(String namespaceURI) {
68: for (Map.Entry<String, String> e : namespaces.entrySet()) {
69: if (e.getValue().equals(namespaceURI)) {
70: return e.getKey();
71: }
72: }
73: return null;
74: }
75:
76: public Iterator getPrefixes(String namespaceURI) {
77: return null;
78: }
79:
80: public Map<String, String> getUsedNamespaces() {
81: return namespaces;
82: }
83: }
|