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/framework/TWSDLParserContextImpl.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,193 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.internal.ws.wsdl.framework; 1.30 + 1.31 +import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext; 1.32 +import com.sun.tools.internal.ws.wsdl.parser.DOMForest; 1.33 +import com.sun.tools.internal.ws.wscompile.ErrorReceiver; 1.34 +import com.sun.tools.internal.ws.resources.WsdlMessages; 1.35 +import com.sun.xml.internal.ws.util.NamespaceSupport; 1.36 +import com.sun.xml.internal.ws.util.xml.XmlUtil; 1.37 +import org.w3c.dom.Attr; 1.38 +import org.w3c.dom.Element; 1.39 +import org.xml.sax.Locator; 1.40 + 1.41 +import javax.xml.namespace.QName; 1.42 +import java.util.ArrayList; 1.43 +import java.util.Iterator; 1.44 +import java.util.List; 1.45 + 1.46 +/** 1.47 + * The context used by parser classes. 1.48 + * 1.49 + * @author WS Development Team 1.50 + */ 1.51 +public class TWSDLParserContextImpl implements TWSDLParserContext { 1.52 + 1.53 + private final static String PREFIX_XMLNS = "xmlns"; 1.54 + private boolean _followImports; 1.55 + private final AbstractDocument _document; 1.56 + private final NamespaceSupport _nsSupport; 1.57 + private final ArrayList<ParserListener> _listeners; 1.58 + private final WSDLLocation _wsdlLocation; 1.59 + private final DOMForest forest; 1.60 + private final ErrorReceiver errorReceiver; 1.61 + 1.62 + public TWSDLParserContextImpl(DOMForest forest, AbstractDocument doc, ArrayList<ParserListener> listeners, ErrorReceiver errReceiver) { 1.63 + this._document = doc; 1.64 + this._listeners = listeners; 1.65 + this._nsSupport = new NamespaceSupport(); 1.66 + this._wsdlLocation = new WSDLLocation(); 1.67 + this.forest = forest; 1.68 + this.errorReceiver = errReceiver; 1.69 + } 1.70 + 1.71 + public AbstractDocument getDocument() { 1.72 + return _document; 1.73 + } 1.74 + 1.75 + public boolean getFollowImports() { 1.76 + return _followImports; 1.77 + } 1.78 + 1.79 + public void setFollowImports(boolean b) { 1.80 + _followImports = b; 1.81 + } 1.82 + 1.83 + public void push() { 1.84 + _nsSupport.pushContext(); 1.85 + } 1.86 + 1.87 + public void pop() { 1.88 + _nsSupport.popContext(); 1.89 + } 1.90 + 1.91 + public String getNamespaceURI(String prefix) { 1.92 + return _nsSupport.getURI(prefix); 1.93 + } 1.94 + 1.95 + public Iterable<String> getPrefixes() { 1.96 + return _nsSupport.getPrefixes(); 1.97 + } 1.98 + 1.99 + public String getDefaultNamespaceURI() { 1.100 + return getNamespaceURI(""); 1.101 + } 1.102 + 1.103 + public void registerNamespaces(Element e) { 1.104 + for (Iterator iter = XmlUtil.getAllAttributes(e); iter.hasNext();) { 1.105 + Attr a = (Attr) iter.next(); 1.106 + if (a.getName().equals(PREFIX_XMLNS)) { 1.107 + // default namespace declaration 1.108 + _nsSupport.declarePrefix("", a.getValue()); 1.109 + } else { 1.110 + String prefix = XmlUtil.getPrefix(a.getName()); 1.111 + if (prefix != null && prefix.equals(PREFIX_XMLNS)) { 1.112 + String nsPrefix = XmlUtil.getLocalPart(a.getName()); 1.113 + String uri = a.getValue(); 1.114 + _nsSupport.declarePrefix(nsPrefix, uri); 1.115 + } 1.116 + } 1.117 + } 1.118 + } 1.119 + 1.120 + public Locator getLocation(Element e) { 1.121 + return forest.locatorTable.getStartLocation(e); 1.122 + } 1.123 + 1.124 + public QName translateQualifiedName(Locator locator, String s) { 1.125 + if (s == null) 1.126 + return null; 1.127 + 1.128 + String prefix = XmlUtil.getPrefix(s); 1.129 + String uri = null; 1.130 + 1.131 + if (prefix == null) { 1.132 + uri = getDefaultNamespaceURI(); 1.133 + } else { 1.134 + uri = getNamespaceURI(prefix); 1.135 + if (uri == null) { 1.136 + errorReceiver.error(locator, WsdlMessages.PARSING_UNKNOWN_NAMESPACE_PREFIX(prefix)); 1.137 + } 1.138 + } 1.139 + 1.140 + return new QName(uri, XmlUtil.getLocalPart(s)); 1.141 + } 1.142 + 1.143 + public void fireIgnoringExtension(Element e, Entity entity) { 1.144 + QName name = new QName(e.getNamespaceURI(), e.getLocalName()); 1.145 + QName parent = entity.getElementName(); 1.146 + List _targets = null; 1.147 + 1.148 + synchronized (this) { 1.149 + if (_listeners != null) { 1.150 + _targets = (List) _listeners.clone(); 1.151 + } 1.152 + } 1.153 + 1.154 + if (_targets != null) { 1.155 + for (Iterator iter = _targets.iterator(); iter.hasNext();) { 1.156 + ParserListener l = (ParserListener) iter.next(); 1.157 + l.ignoringExtension(entity, name, parent); 1.158 + } 1.159 + } 1.160 + } 1.161 + 1.162 + public void fireDoneParsingEntity(QName element, Entity entity) { 1.163 + List _targets = null; 1.164 + 1.165 + synchronized (this) { 1.166 + if (_listeners != null) { 1.167 + _targets = (List) _listeners.clone(); 1.168 + } 1.169 + } 1.170 + 1.171 + if (_targets != null) { 1.172 + for (Iterator iter = _targets.iterator(); iter.hasNext();) { 1.173 + ParserListener l = (ParserListener) iter.next(); 1.174 + l.doneParsingEntity(element, entity); 1.175 + } 1.176 + } 1.177 + } 1.178 + 1.179 + //bug fix: 4856674, WSDLLocation context maintainence 1.180 + //and utility funcitons 1.181 + public void pushWSDLLocation() { 1.182 + _wsdlLocation.push(); 1.183 + } 1.184 + 1.185 + public void popWSDLLocation() { 1.186 + _wsdlLocation.pop(); 1.187 + } 1.188 + 1.189 + public void setWSDLLocation(String loc) { 1.190 + _wsdlLocation.setLocation(loc); 1.191 + } 1.192 + 1.193 + public String getWSDLLocation() { 1.194 + return _wsdlLocation.getLocation(); 1.195 + } 1.196 +}