src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/framework/TWSDLParserContextImpl.java

Wed, 27 Apr 2016 01:27:09 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:27:09 +0800
changeset 0
373ffda63c9a
child 637
9c07ef4934dd
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17

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

mercurial