001 /*
002 * To change this template, choose Tools | Templates
003 * and open the template in the editor.
004 */
005
006 package net.rootdev.javardfa.literal;
007
008 import java.util.Collection;
009 import java.util.HashMap;
010 import java.util.Iterator;
011 import java.util.LinkedList;
012 import java.util.Map;
013 import java.util.Map.Entry;
014 import javax.xml.namespace.NamespaceContext;
015
016 /**
017 *
018 * @author pldms
019 */
020 public class NamespaceContextImpl implements NamespaceContext {
021
022 Map<String, String> nsMap = new HashMap<String, String>();
023
024 public void setNamespaceURI(String prefix, String uri) {
025 nsMap.put(prefix, uri);
026 }
027
028 public String getNamespaceURI(String prefix) {
029 System.err.println("getNamespaceURI " + prefix);
030 System.err.println("Return: " + nsMap.get(prefix));
031 return nsMap.get(prefix);
032 }
033
034 public String getPrefix(String namespaceURI) {
035 System.err.println("getPrefix '" + namespaceURI + "'");
036 for (Entry<String, String> e: nsMap.entrySet()) {
037 if (e.getValue().equals(namespaceURI)) {
038 System.err.println("Return: " + e.getKey());
039 return e.getKey();
040 }
041 }
042 return null;
043 }
044
045 public Iterator getPrefixes(String namespaceURI) {
046 System.err.println("getPrefixes " + namespaceURI);
047 Collection<String> prefixes = new LinkedList<String>();
048 for (Entry<String, String> e: nsMap.entrySet()) {
049 if (e.getValue().equals(namespaceURI)) prefixes.add(e.getKey());
050 }
051 System.err.println("Return: " + prefixes);
052 return prefixes.iterator();
053 }
054
055 }