View Javadoc

1   /*
2    * $Id: MapNamespaceContext.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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  public final class MapNamespaceContext implements NamespaceContext
20  {
21      private Map namespaces = new HashMap();
22  
23      public MapNamespaceContext()
24      {
25          super();
26      }
27  
28      public MapNamespaceContext(final Map ns)
29      {
30          this();
31          this.namespaces = ns;
32      }
33  
34      public void addNamespace(final String prefix, final String namespaceURI)
35      {
36          this.namespaces.put(prefix, namespaceURI);
37      }
38  
39      public void addNamespaces(final Map ns)
40      {
41          this.namespaces.putAll(ns);
42      }
43  
44      public String getNamespaceURI(String prefix)
45      {
46          return (String) namespaces.get(prefix);
47      }
48  
49      public String getPrefix(String namespaceURI)
50      {
51          for (Iterator itr = namespaces.entrySet().iterator(); itr.hasNext();)
52          {
53              Map.Entry e = (Map.Entry) itr.next();
54              if (e.getValue().equals(namespaceURI))
55              {
56                  return (String) e.getKey();
57              }
58          }
59          return null;
60      }
61  
62      public Iterator getPrefixes(String namespaceURI)
63      {
64          return null;
65      }
66  
67      public Map getUsedNamespaces()
68      {
69          return namespaces;
70      }
71  }