KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > webservice > monitoring > NamespaceContextImpl


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 in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.webservice.monitoring;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.Vector JavaDoc;
28 import javax.xml.namespace.NamespaceContext JavaDoc;
29 import javax.xml.XMLConstants JavaDoc;
30
31 import org.w3c.dom.Document JavaDoc;
32 import org.w3c.dom.NamedNodeMap JavaDoc;
33 import org.w3c.dom.Node JavaDoc;
34 /**
35  * This class is a name space resolver for the XPath expressions.
36  *
37  * @author Jerome Dochez
38  */

39 public class NamespaceContextImpl implements NamespaceContext JavaDoc {
40     
41     /** Creates a new instance of NamespaceContextImpl */
42     public NamespaceContextImpl(Document JavaDoc wsdlDoc) {
43         // get all the namespaces declarations
44
NamedNodeMap JavaDoc attributes = wsdlDoc.getAttributes();
45        if (attributes==null)
46            return;
47        for (int i=0;i<attributes.getLength();i++) {
48            Node JavaDoc attribute = attributes.item(i);
49            System.out.println("attribute " + attribute.getNodeName() + " value " + attribute.getNodeValue());
50        }
51     }
52     
53     /**
54      * <p>
55      * Get Namespace URI bound to a prefix in the current scope
56      * </p>
57      * @param prefix to look up
58      * @return Namespace URI
59      */

60     public String JavaDoc getNamespaceURI(String JavaDoc prefix) {
61         if (prefix==null) {
62             throw new IllegalArgumentException JavaDoc("prefix is null");
63         }
64         if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
65             return "http://schemas.xmlsoap.org/wsdl/";
66         }
67         if (XMLConstants.XML_NS_PREFIX.equals(prefix)) {
68             return XMLConstants.XML_NS_URI;
69         }
70         if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) {
71             return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
72         }
73         if ("soap".equals(prefix)) {
74             return "http://schemas.xmlsoap.org/wsdl/soap/";
75         }
76         if ("soap12".equals(prefix)) {
77             return "http://schemas.xmlsoap.org/wsdl/soap12/";
78         }
79         return XMLConstants.NULL_NS_URI;
80     }
81     
82     /**
83      * <p>
84      * Get Prefix bound to Namespace URI in the current scope
85      * </p>
86      * @param URI of Namespace to look up
87      * @return bound prefix
88      */

89     public String JavaDoc getPrefix(String JavaDoc namespace) {
90         if (namespace==null) {
91             throw new IllegalArgumentException JavaDoc("namespace is null");
92         }
93         if ("http://schemas.xmlsoap.org/wsdl/".equals(namespace)) {
94             return XMLConstants.DEFAULT_NS_PREFIX;
95         }
96         if (XMLConstants.XML_NS_URI.equals(namespace)) {
97             return XMLConstants.XML_NS_PREFIX;
98         }
99         if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespace)) {
100             return XMLConstants.XMLNS_ATTRIBUTE;
101         }
102         if ("http://schemas.xmlsoap.org/wsdl/soap/".equals(namespace)) {
103             return "soap";
104         }
105         if(("http://schemas.xmlsoap.org/wsdl/soap12/").equals(namespace)) {
106             return "soap12";
107         }
108         return null;
109     }
110      
111     /**
112      * <p>
113      * Get all prefixes bound to a Namespace URI in the current scope
114      * </p>
115      * @param Namespace URI to look up
116      * @return Iterator on all the prefixes
117      */

118     public Iterator JavaDoc getPrefixes(String JavaDoc namespaceURI) {
119         Vector JavaDoc v = new Vector JavaDoc();
120         String JavaDoc prefix = getPrefix(namespaceURI);
121         if (prefix!=null) {
122             v.add(prefix);
123         }
124         return v.iterator();
125     }
126 }
127
Popular Tags