View Javadoc

1   /*
2    * Copyright 2004,2007 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.ws.commons.schema.utils;
17  
18  import java.util.*;
19  
20  public class NamespaceMap extends HashMap implements NamespacePrefixList {
21      
22      public NamespaceMap() {
23      }
24      
25      public NamespaceMap(Map map) {
26          super(map);
27      }
28  
29      public void add(String prefix, String namespaceURI) {
30          put(prefix, namespaceURI);
31      }
32  
33      public String[] getDeclaredPrefixes() {
34          Set keys = keySet();
35          return (String[]) keys.toArray(new String[keys.size()]);
36      }
37  
38      public String getNamespaceURI(String prefix) {
39          return get(prefix).toString();
40      }
41  
42      public String getPrefix(String namespaceURI) {
43          Iterator iterator = entrySet().iterator();
44          while (iterator.hasNext()) {
45              Map.Entry entry = (Map.Entry) iterator.next();
46              if (entry.getValue().toString().equals(namespaceURI)) {
47                  return (String) entry.getKey();
48              }
49          }
50          return null;
51      }
52  
53      public Iterator getPrefixes(String namespaceURI) {
54          ArrayList list = new ArrayList();
55          Iterator iterator = entrySet().iterator();
56          while (iterator.hasNext()) {
57              Map.Entry entry = (Map.Entry) iterator.next();
58              if (entry.getValue().toString().equals(namespaceURI)) {
59                  list.add(entry.getKey());
60              }
61          }
62          return list.iterator();
63      }
64  }