1 /* 2 * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.org.apache.xerces.internal.util; 27 28 import java.util.Iterator; 29 import java.util.List; 30 import javax.xml.namespace.NamespaceContext; 31 32 /** 33 * Writing a wrapper to re-use most of the namespace functionality 34 * already provided by NamespaceSupport, which implements NamespaceContext 35 * from XNI. It would be good if we can change the XNI NamespaceContext 36 * interface to implement the JAXP NamespaceContext interface. 37 * 38 * Note that NamespaceSupport assumes the use of symbols. Since this class 39 * can be exposed to the application, we must intern all Strings before 40 * calling NamespaceSupport methods. 41 * 42 * @author Neeraj Bajaj 43 * @author Santiago PericasGeertsen 44 * 45 */ 46 public class NamespaceContextWrapper implements NamespaceContext { 47 48 private com.sun.org.apache.xerces.internal.xni.NamespaceContext fNamespaceContext; 49 NamespaceContextWrapper(NamespaceSupport namespaceContext)50 public NamespaceContextWrapper(NamespaceSupport namespaceContext) { 51 fNamespaceContext = namespaceContext ; 52 } 53 getNamespaceURI(String prefix)54 public String getNamespaceURI(String prefix) { 55 if (prefix == null) { 56 throw new IllegalArgumentException("Prefix can't be null"); 57 } 58 return fNamespaceContext.getURI(prefix.intern()); 59 } 60 getPrefix(String namespaceURI)61 public String getPrefix(String namespaceURI) { 62 if (namespaceURI == null) { 63 throw new IllegalArgumentException("URI can't be null."); 64 } 65 return fNamespaceContext.getPrefix(namespaceURI.intern()); 66 } 67 68 /** 69 * TODO: Namespace doesn't give information giving multiple prefixes for 70 * the same namespaceURI. 71 */ getPrefixes(String namespaceURI)72 public Iterator<String> getPrefixes(String namespaceURI) { 73 if (namespaceURI == null) { 74 throw new IllegalArgumentException("URI can't be null."); 75 } 76 else { 77 List<String> vector = 78 ((NamespaceSupport) fNamespaceContext).getPrefixes(namespaceURI.intern()); 79 return vector.iterator(); 80 } 81 } 82 83 /** 84 * This method supports all functions in the NamespaceContext utility class 85 */ getNamespaceContext()86 public com.sun.org.apache.xerces.internal.xni.NamespaceContext getNamespaceContext() { 87 return fNamespaceContext; 88 } 89 90 } 91