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

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * reserved comment block
     3  * DO NOT REMOVE OR ALTER!
     4  */
     5  /*
     6  * Copyright (c) 2012, 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  */
    32 package com.sun.tools.internal.ws.wsdl.parser;
    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;
    39 import javax.xml.namespace.NamespaceContext;
    40 import java.util.Iterator;
    42 public class NamespaceContextImpl implements NamespaceContext {
    44     private final Element e;
    46     public NamespaceContextImpl(Element e) {
    47         this.e = e;
    48     }
    50     public String getNamespaceURI(String prefix) {
    51         Node parent = e;
    52         String namespace = null;
    54         if (prefix.equals("xml")) {
    55             namespace = WellKnownNamespace.XML_NAMESPACE_URI;
    56         } else {
    57             int type;
    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();
    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:");
    72                         if (isPrefix || aname.equals("xmlns")) {
    73                             int index = aname.indexOf(':');
    74                             String p = isPrefix ? aname.substring(index + 1) : "";
    76                             if (p.equals(prefix)) {
    77                                 namespace = attr.getNodeValue();
    79                                 break;
    80                             }
    81                         }
    82                     }
    83                 }
    85                 parent = parent.getParentNode();
    86             }
    87         }
    89         return namespace;
    90     }
    92     public String getPrefix(String namespaceURI) {
    93         throw new UnsupportedOperationException();
    94     }
    96     public Iterator getPrefixes(String namespaceURI) {
    97         throw new UnsupportedOperationException();
    98     }
    99 }

mercurial