src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/framework/TWSDLParserContextImpl.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  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.internal.ws.wsdl.framework;
    28 import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
    29 import com.sun.tools.internal.ws.wsdl.parser.DOMForest;
    30 import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
    31 import com.sun.tools.internal.ws.resources.WsdlMessages;
    32 import com.sun.xml.internal.ws.util.NamespaceSupport;
    33 import com.sun.xml.internal.ws.util.xml.XmlUtil;
    34 import org.w3c.dom.Attr;
    35 import org.w3c.dom.Element;
    36 import org.xml.sax.Locator;
    38 import javax.xml.namespace.QName;
    39 import java.util.ArrayList;
    40 import java.util.Iterator;
    41 import java.util.List;
    43 /**
    44  * The context used by parser classes.
    45  *
    46  * @author WS Development Team
    47  */
    48 public class TWSDLParserContextImpl implements TWSDLParserContext {
    50     private final static String PREFIX_XMLNS = "xmlns";
    51     private boolean _followImports;
    52     private final AbstractDocument _document;
    53     private final NamespaceSupport _nsSupport;
    54     private final ArrayList<ParserListener> _listeners;
    55     private final WSDLLocation _wsdlLocation;
    56     private final DOMForest forest;
    57     private final ErrorReceiver errorReceiver;
    59     public TWSDLParserContextImpl(DOMForest forest, AbstractDocument doc, ArrayList<ParserListener> listeners, ErrorReceiver errReceiver) {
    60         this._document = doc;
    61         this._listeners = listeners;
    62         this._nsSupport = new NamespaceSupport();
    63         this._wsdlLocation = new WSDLLocation();
    64         this.forest = forest;
    65         this.errorReceiver = errReceiver;
    66     }
    68     public AbstractDocument getDocument() {
    69         return _document;
    70     }
    72     public boolean getFollowImports() {
    73         return _followImports;
    74     }
    76     public void setFollowImports(boolean b) {
    77         _followImports = b;
    78     }
    80     public void push() {
    81         _nsSupport.pushContext();
    82     }
    84     public void pop() {
    85         _nsSupport.popContext();
    86     }
    88     public String getNamespaceURI(String prefix) {
    89         return _nsSupport.getURI(prefix);
    90     }
    92     public Iterable<String> getPrefixes() {
    93         return _nsSupport.getPrefixes();
    94     }
    96     public String getDefaultNamespaceURI() {
    97         return getNamespaceURI("");
    98     }
   100     public void registerNamespaces(Element e) {
   101         for (Iterator iter = XmlUtil.getAllAttributes(e); iter.hasNext();) {
   102             Attr a = (Attr) iter.next();
   103             if (a.getName().equals(PREFIX_XMLNS)) {
   104                 // default namespace declaration
   105                 _nsSupport.declarePrefix("", a.getValue());
   106             } else {
   107                 String prefix = XmlUtil.getPrefix(a.getName());
   108                 if (prefix != null && prefix.equals(PREFIX_XMLNS)) {
   109                     String nsPrefix = XmlUtil.getLocalPart(a.getName());
   110                     String uri = a.getValue();
   111                     _nsSupport.declarePrefix(nsPrefix, uri);
   112                 }
   113             }
   114         }
   115     }
   117     public Locator getLocation(Element e) {
   118         return forest.locatorTable.getStartLocation(e);
   119     }
   121     public QName translateQualifiedName(Locator locator, String s) {
   122         if (s == null)
   123             return null;
   125         String prefix = XmlUtil.getPrefix(s);
   126         String uri = null;
   128         if (prefix == null) {
   129             uri = getDefaultNamespaceURI();
   130         } else {
   131             uri = getNamespaceURI(prefix);
   132             if (uri == null) {
   133                 errorReceiver.error(locator, WsdlMessages.PARSING_UNKNOWN_NAMESPACE_PREFIX(prefix));
   134             }
   135         }
   137         return new QName(uri, XmlUtil.getLocalPart(s));
   138     }
   140     public void fireIgnoringExtension(Element e, Entity entity) {
   141         QName name = new QName(e.getNamespaceURI(), e.getLocalName());
   142         QName parent = entity.getElementName();
   143         List _targets = null;
   145         synchronized (this) {
   146             if (_listeners != null) {
   147                 _targets = (List) _listeners.clone();
   148             }
   149         }
   151         if (_targets != null) {
   152             for (Iterator iter = _targets.iterator(); iter.hasNext();) {
   153                 ParserListener l = (ParserListener) iter.next();
   154                 l.ignoringExtension(entity, name, parent);
   155             }
   156         }
   157     }
   159     public void fireDoneParsingEntity(QName element, Entity entity) {
   160         List _targets = null;
   162         synchronized (this) {
   163             if (_listeners != null) {
   164                 _targets = (List) _listeners.clone();
   165             }
   166         }
   168         if (_targets != null) {
   169             for (Iterator iter = _targets.iterator(); iter.hasNext();) {
   170                 ParserListener l = (ParserListener) iter.next();
   171                 l.doneParsingEntity(element, entity);
   172             }
   173         }
   174     }
   176     //bug fix: 4856674, WSDLLocation context maintainence
   177     //and utility funcitons
   178     public void pushWSDLLocation() {
   179         _wsdlLocation.push();
   180     }
   182     public void popWSDLLocation() {
   183         _wsdlLocation.pop();
   184     }
   186     public void setWSDLLocation(String loc) {
   187         _wsdlLocation.setLocation(loc);
   188     }
   190     public String getWSDLLocation() {
   191         return _wsdlLocation.getLocation();
   192     }
   193 }

mercurial