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

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/NamespaceContextImpl.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,99 @@
     1.4 +/*
     1.5 + * reserved comment block
     1.6 + * DO NOT REMOVE OR ALTER!
     1.7 + */
     1.8 + /*
     1.9 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
    1.10 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    1.11 + *
    1.12 + * This code is free software; you can redistribute it and/or modify it
    1.13 + * under the terms of the GNU General Public License version 2 only, as
    1.14 + * published by the Free Software Foundation.  Oracle designates this
    1.15 + * particular file as subject to the "Classpath" exception as provided
    1.16 + * by Oracle in the LICENSE file that accompanied this code.
    1.17 + *
    1.18 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.19 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.20 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.21 + * version 2 for more details (a copy is included in the LICENSE file that
    1.22 + * accompanied this code).
    1.23 + *
    1.24 + * You should have received a copy of the GNU General Public License version
    1.25 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.26 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.27 + *
    1.28 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.29 + * or visit www.oracle.com if you need additional information or have any
    1.30 + * questions.
    1.31 + *
    1.32 + * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
    1.33 + */
    1.34 +
    1.35 +package com.sun.tools.internal.ws.wsdl.parser;
    1.36 +
    1.37 +import com.sun.xml.internal.bind.v2.WellKnownNamespace;
    1.38 +import org.w3c.dom.Element;
    1.39 +import org.w3c.dom.NamedNodeMap;
    1.40 +import org.w3c.dom.Node;
    1.41 +
    1.42 +import javax.xml.namespace.NamespaceContext;
    1.43 +import java.util.Iterator;
    1.44 +
    1.45 +public class NamespaceContextImpl implements NamespaceContext {
    1.46 +
    1.47 +    private final Element e;
    1.48 +
    1.49 +    public NamespaceContextImpl(Element e) {
    1.50 +        this.e = e;
    1.51 +    }
    1.52 +
    1.53 +    public String getNamespaceURI(String prefix) {
    1.54 +        Node parent = e;
    1.55 +        String namespace = null;
    1.56 +
    1.57 +        if (prefix.equals("xml")) {
    1.58 +            namespace = WellKnownNamespace.XML_NAMESPACE_URI;
    1.59 +        } else {
    1.60 +            int type;
    1.61 +
    1.62 +            while ((null != parent) && (null == namespace)
    1.63 +                    && (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
    1.64 +                    || (type == Node.ENTITY_REFERENCE_NODE))) {
    1.65 +                if (type == Node.ELEMENT_NODE) {
    1.66 +                    if (parent.getNodeName().indexOf(prefix + ':') == 0)
    1.67 +                        return parent.getNamespaceURI();
    1.68 +                    NamedNodeMap nnm = parent.getAttributes();
    1.69 +
    1.70 +                    for (int i = 0; i < nnm.getLength(); i++) {
    1.71 +                        Node attr = nnm.item(i);
    1.72 +                        String aname = attr.getNodeName();
    1.73 +                        boolean isPrefix = aname.startsWith("xmlns:");
    1.74 +
    1.75 +                        if (isPrefix || aname.equals("xmlns")) {
    1.76 +                            int index = aname.indexOf(':');
    1.77 +                            String p = isPrefix ? aname.substring(index + 1) : "";
    1.78 +
    1.79 +                            if (p.equals(prefix)) {
    1.80 +                                namespace = attr.getNodeValue();
    1.81 +
    1.82 +                                break;
    1.83 +                            }
    1.84 +                        }
    1.85 +                    }
    1.86 +                }
    1.87 +
    1.88 +                parent = parent.getParentNode();
    1.89 +            }
    1.90 +        }
    1.91 +
    1.92 +        return namespace;
    1.93 +    }
    1.94 +
    1.95 +    public String getPrefix(String namespaceURI) {
    1.96 +        throw new UnsupportedOperationException();
    1.97 +    }
    1.98 +
    1.99 +    public Iterator getPrefixes(String namespaceURI) {
   1.100 +        throw new UnsupportedOperationException();
   1.101 +    }
   1.102 +}

mercurial