KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > util > NamespaceContextWrapper


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://jaxp.dev.java.net/CDDLv1.0.html.
9  * See the License for the specific language governing
10  * permissions and limitations under the License.
11  *
12  * When distributing Covered Code, include this CDDL
13  * HEADER in each file and include the License file at
14  * https://jaxp.dev.java.net/CDDLv1.0.html
15  * If applicable add the following below this CDDL HEADER
16  * with the fields enclosed by brackets "[]" replaced with
17  * your own identifying information: Portions Copyright
18  * [year] [name of copyright owner]
19  */

20
21 /*
22  * $Id: NamespaceContextWrapper.java,v 1.4 2005/11/03 17:54:06 jeffsuttor Exp $
23  * @(#)NamespaceContextWrapper.java 1.7 06/05/03
24  *
25  * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package com.sun.org.apache.xerces.internal.util;
29
30 import java.util.Enumeration JavaDoc;
31 import java.util.Vector JavaDoc;
32 import javax.xml.namespace.NamespaceContext JavaDoc;
33
34 /**
35  * Writing a wrapper to re-use most of the namespace functionality
36  * already provided by NamespaceSupport, which implements NamespaceContext
37  * from XNI. It would be good if we can change the XNI NamespaceContext
38  * interface to implement the JAXP NamespaceContext interface.
39  *
40  * Note that NamespaceSupport assumes the use of symbols. Since this class
41  * can be exposed to the application, we must intern all Strings before
42  * calling NamespaceSupport methods.
43  *
44  * @author Neeraj Bajaj, Sun Microsystems, inc.
45  * @author Santiago.PericasGeertsen@sun.com
46  *
47  */

48 public class NamespaceContextWrapper implements NamespaceContext JavaDoc {
49     
50     private com.sun.org.apache.xerces.internal.xni.NamespaceContext fNamespaceContext;
51     
52     public NamespaceContextWrapper(NamespaceSupport namespaceContext) {
53         fNamespaceContext = namespaceContext ;
54     }
55     
56     public String JavaDoc getNamespaceURI(String JavaDoc prefix) {
57         if (prefix == null) {
58             throw new IllegalArgumentException JavaDoc("Prefix can't be null");
59         }
60         return fNamespaceContext.getURI(prefix.intern());
61     }
62     
63     public String JavaDoc getPrefix(String JavaDoc namespaceURI) {
64         if (namespaceURI == null || namespaceURI.trim().length() == 0) {
65             throw new IllegalArgumentException JavaDoc("URI can't be null or empty String");
66         }
67         return fNamespaceContext.getPrefix(namespaceURI.intern());
68     }
69     
70     /**
71      * TODO: Namespace doesn't give information giving multiple prefixes for
72      * the same namespaceURI.
73      */

74     public java.util.Iterator JavaDoc getPrefixes(String JavaDoc namespaceURI) {
75         if (namespaceURI == null || namespaceURI.trim().length() == 0) {
76             throw new IllegalArgumentException JavaDoc("URI can't be null or empty String");
77         }
78         else {
79             Vector JavaDoc vector =
80                 ((NamespaceSupport) fNamespaceContext).getPrefixes(namespaceURI.intern());
81             return vector.iterator();
82         }
83     }
84     
85     /**
86      * This method supports all functions in the NamespaceContext utility class
87      */

88     public com.sun.org.apache.xerces.internal.xni.NamespaceContext getNamespaceContext() {
89         return fNamespaceContext;
90     }
91
92 }
93
Popular Tags