View Javadoc

1   /*
2    * $Id$
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.xml.stax;
12  
13  import java.util.HashMap;
14  import java.util.Iterator;
15  import java.util.Map;
16  
17  import javax.xml.namespace.NamespaceContext;
18  
19  import org.w3c.dom.Node;
20  
21  public final class MapNamespaceContext implements NamespaceContext
22  {
23      private Map namespaces = new HashMap();
24  
25      public MapNamespaceContext()
26      {
27          super();
28      }
29  
30      public MapNamespaceContext(final Map ns)
31      {
32          this();
33          this.namespaces = ns;
34      }
35  
36      public void addNamespace(final String prefix, final String namespaceURI)
37      {
38          this.namespaces.put(prefix, namespaceURI);
39      }
40  
41      public void addNamespaces(final Map ns)
42      {
43          this.namespaces.putAll(ns);
44      }
45  
46      public String getNamespaceURI(String prefix)
47      {
48          return (String) namespaces.get(prefix);
49      }
50  
51      public String getPrefix(String namespaceURI)
52      {
53          for (Iterator itr = namespaces.entrySet().iterator(); itr.hasNext();)
54          {
55              Map.Entry e = (Map.Entry) itr.next();
56              if (e.getValue().equals(namespaceURI))
57              {
58                  return (String) e.getKey();
59              }
60          }
61          return null;
62      }
63  
64      public Iterator getPrefixes(String namespaceURI)
65      {
66          return null;
67      }
68  
69      public Map getUsedNamespaces()
70      {
71          return namespaces;
72      }
73  }