001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: *
025: * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
026: */
027: package com.sun.tools.internal.ws.wsdl.parser;
028:
029: import java.util.Iterator;
030:
031: import javax.xml.namespace.NamespaceContext;
032:
033: import org.w3c.dom.Element;
034: import org.w3c.dom.NamedNodeMap;
035: import org.w3c.dom.Node;
036:
037: import com.sun.xml.internal.bind.v2.WellKnownNamespace;
038:
039: public class NamespaceContextImpl implements NamespaceContext {
040:
041: private final Element e;
042:
043: public NamespaceContextImpl(Element e) {
044: this .e = e;
045: }
046:
047: /*
048: * Copyright 1999-2004 The Apache Software Foundation.
049: * */
050: public String getNamespaceURI(String prefix) {
051: Node parent = e;
052: String namespace = null;
053:
054: if (prefix.equals("xml")) {
055: namespace = WellKnownNamespace.XML_NAMESPACE_URI;
056: } else {
057: int type;
058:
059: while ((null != parent)
060: && (null == namespace)
061: && (((type = parent.getNodeType()) == Node.ELEMENT_NODE) || (type == Node.ENTITY_REFERENCE_NODE))) {
062: if (type == Node.ELEMENT_NODE) {
063: if (parent.getNodeName().indexOf(prefix + ':') == 0)
064: return parent.getNamespaceURI();
065: NamedNodeMap nnm = parent.getAttributes();
066:
067: for (int i = 0; i < nnm.getLength(); i++) {
068: Node attr = nnm.item(i);
069: String aname = attr.getNodeName();
070: boolean isPrefix = aname.startsWith("xmlns:");
071:
072: if (isPrefix || aname.equals("xmlns")) {
073: int index = aname.indexOf(':');
074: String p = isPrefix ? aname
075: .substring(index + 1) : "";
076:
077: if (p.equals(prefix)) {
078: namespace = attr.getNodeValue();
079:
080: break;
081: }
082: }
083: }
084: }
085:
086: parent = parent.getParentNode();
087: }
088: }
089:
090: return namespace;
091: }
092:
093: public String getPrefix(String namespaceURI) {
094: throw new UnsupportedOperationException();
095: }
096:
097: public Iterator getPrefixes(String namespaceURI) {
098: throw new UnsupportedOperationException();
099: }
100: }
|