src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/NamespaceContextImpl.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
equal deleted inserted replaced
284:88b85470e72c 286:f50545b5e2f1
1 /*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5 /*
6 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 *
9 * This code is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 only, as
11 * published by the Free Software Foundation. Oracle designates this
12 * particular file as subject to the "Classpath" exception as provided
13 * by Oracle in the LICENSE file that accompanied this code.
14 *
15 * This code is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * version 2 for more details (a copy is included in the LICENSE file that
19 * accompanied this code).
20 *
21 * You should have received a copy of the GNU General Public License version
22 * 2 along with this work; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24 *
25 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
26 * or visit www.oracle.com if you need additional information or have any
27 * questions.
28 *
29 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
30 */
31
32 package com.sun.tools.internal.ws.wsdl.parser;
33
34 import com.sun.xml.internal.bind.v2.WellKnownNamespace;
35 import org.w3c.dom.Element;
36 import org.w3c.dom.NamedNodeMap;
37 import org.w3c.dom.Node;
38
39 import javax.xml.namespace.NamespaceContext;
40 import java.util.Iterator;
41
42 public class NamespaceContextImpl implements NamespaceContext {
43
44 private final Element e;
45
46 public NamespaceContextImpl(Element e) {
47 this.e = e;
48 }
49
50 public String getNamespaceURI(String prefix) {
51 Node parent = e;
52 String namespace = null;
53
54 if (prefix.equals("xml")) {
55 namespace = WellKnownNamespace.XML_NAMESPACE_URI;
56 } else {
57 int type;
58
59 while ((null != parent) && (null == namespace)
60 && (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
61 || (type == Node.ENTITY_REFERENCE_NODE))) {
62 if (type == Node.ELEMENT_NODE) {
63 if (parent.getNodeName().indexOf(prefix + ':') == 0)
64 return parent.getNamespaceURI();
65 NamedNodeMap nnm = parent.getAttributes();
66
67 for (int i = 0; i < nnm.getLength(); i++) {
68 Node attr = nnm.item(i);
69 String aname = attr.getNodeName();
70 boolean isPrefix = aname.startsWith("xmlns:");
71
72 if (isPrefix || aname.equals("xmlns")) {
73 int index = aname.indexOf(':');
74 String p = isPrefix ? aname.substring(index + 1) : "";
75
76 if (p.equals(prefix)) {
77 namespace = attr.getNodeValue();
78
79 break;
80 }
81 }
82 }
83 }
84
85 parent = parent.getParentNode();
86 }
87 }
88
89 return namespace;
90 }
91
92 public String getPrefix(String namespaceURI) {
93 throw new UnsupportedOperationException();
94 }
95
96 public Iterator getPrefixes(String namespaceURI) {
97 throw new UnsupportedOperationException();
98 }
99 }

mercurial