aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.internal.ws.wsdl.framework; aoqi@0: aoqi@0: import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext; aoqi@0: import com.sun.tools.internal.ws.wsdl.parser.DOMForest; aoqi@0: import com.sun.tools.internal.ws.wscompile.ErrorReceiver; aoqi@0: import com.sun.tools.internal.ws.resources.WsdlMessages; aoqi@0: import com.sun.xml.internal.ws.util.NamespaceSupport; aoqi@0: import com.sun.xml.internal.ws.util.xml.XmlUtil; aoqi@0: import org.w3c.dom.Attr; aoqi@0: import org.w3c.dom.Element; aoqi@0: import org.xml.sax.Locator; aoqi@0: aoqi@0: import javax.xml.namespace.QName; aoqi@0: import java.util.ArrayList; aoqi@0: import java.util.Iterator; aoqi@0: import java.util.List; aoqi@0: aoqi@0: /** aoqi@0: * The context used by parser classes. aoqi@0: * aoqi@0: * @author WS Development Team aoqi@0: */ aoqi@0: public class TWSDLParserContextImpl implements TWSDLParserContext { aoqi@0: aoqi@0: private final static String PREFIX_XMLNS = "xmlns"; aoqi@0: private boolean _followImports; aoqi@0: private final AbstractDocument _document; aoqi@0: private final NamespaceSupport _nsSupport; aoqi@0: private final ArrayList _listeners; aoqi@0: private final WSDLLocation _wsdlLocation; aoqi@0: private final DOMForest forest; aoqi@0: private final ErrorReceiver errorReceiver; aoqi@0: aoqi@0: public TWSDLParserContextImpl(DOMForest forest, AbstractDocument doc, ArrayList listeners, ErrorReceiver errReceiver) { aoqi@0: this._document = doc; aoqi@0: this._listeners = listeners; aoqi@0: this._nsSupport = new NamespaceSupport(); aoqi@0: this._wsdlLocation = new WSDLLocation(); aoqi@0: this.forest = forest; aoqi@0: this.errorReceiver = errReceiver; aoqi@0: } aoqi@0: aoqi@0: public AbstractDocument getDocument() { aoqi@0: return _document; aoqi@0: } aoqi@0: aoqi@0: public boolean getFollowImports() { aoqi@0: return _followImports; aoqi@0: } aoqi@0: aoqi@0: public void setFollowImports(boolean b) { aoqi@0: _followImports = b; aoqi@0: } aoqi@0: aoqi@0: public void push() { aoqi@0: _nsSupport.pushContext(); aoqi@0: } aoqi@0: aoqi@0: public void pop() { aoqi@0: _nsSupport.popContext(); aoqi@0: } aoqi@0: aoqi@0: public String getNamespaceURI(String prefix) { aoqi@0: return _nsSupport.getURI(prefix); aoqi@0: } aoqi@0: aoqi@0: public Iterable getPrefixes() { aoqi@0: return _nsSupport.getPrefixes(); aoqi@0: } aoqi@0: aoqi@0: public String getDefaultNamespaceURI() { aoqi@0: return getNamespaceURI(""); aoqi@0: } aoqi@0: aoqi@0: public void registerNamespaces(Element e) { aoqi@0: for (Iterator iter = XmlUtil.getAllAttributes(e); iter.hasNext();) { aoqi@0: Attr a = (Attr) iter.next(); aoqi@0: if (a.getName().equals(PREFIX_XMLNS)) { aoqi@0: // default namespace declaration aoqi@0: _nsSupport.declarePrefix("", a.getValue()); aoqi@0: } else { aoqi@0: String prefix = XmlUtil.getPrefix(a.getName()); aoqi@0: if (prefix != null && prefix.equals(PREFIX_XMLNS)) { aoqi@0: String nsPrefix = XmlUtil.getLocalPart(a.getName()); aoqi@0: String uri = a.getValue(); aoqi@0: _nsSupport.declarePrefix(nsPrefix, uri); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public Locator getLocation(Element e) { aoqi@0: return forest.locatorTable.getStartLocation(e); aoqi@0: } aoqi@0: aoqi@0: public QName translateQualifiedName(Locator locator, String s) { aoqi@0: if (s == null) aoqi@0: return null; aoqi@0: aoqi@0: String prefix = XmlUtil.getPrefix(s); aoqi@0: String uri = null; aoqi@0: aoqi@0: if (prefix == null) { aoqi@0: uri = getDefaultNamespaceURI(); aoqi@0: } else { aoqi@0: uri = getNamespaceURI(prefix); aoqi@0: if (uri == null) { aoqi@0: errorReceiver.error(locator, WsdlMessages.PARSING_UNKNOWN_NAMESPACE_PREFIX(prefix)); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: return new QName(uri, XmlUtil.getLocalPart(s)); aoqi@0: } aoqi@0: aoqi@0: public void fireIgnoringExtension(Element e, Entity entity) { aoqi@0: QName name = new QName(e.getNamespaceURI(), e.getLocalName()); aoqi@0: QName parent = entity.getElementName(); aoqi@0: List _targets = null; aoqi@0: aoqi@0: synchronized (this) { aoqi@0: if (_listeners != null) { aoqi@0: _targets = (List) _listeners.clone(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (_targets != null) { aoqi@0: for (Iterator iter = _targets.iterator(); iter.hasNext();) { aoqi@0: ParserListener l = (ParserListener) iter.next(); aoqi@0: l.ignoringExtension(entity, name, parent); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public void fireDoneParsingEntity(QName element, Entity entity) { aoqi@0: List _targets = null; aoqi@0: aoqi@0: synchronized (this) { aoqi@0: if (_listeners != null) { aoqi@0: _targets = (List) _listeners.clone(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (_targets != null) { aoqi@0: for (Iterator iter = _targets.iterator(); iter.hasNext();) { aoqi@0: ParserListener l = (ParserListener) iter.next(); aoqi@0: l.doneParsingEntity(element, entity); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: //bug fix: 4856674, WSDLLocation context maintainence aoqi@0: //and utility funcitons aoqi@0: public void pushWSDLLocation() { aoqi@0: _wsdlLocation.push(); aoqi@0: } aoqi@0: aoqi@0: public void popWSDLLocation() { aoqi@0: _wsdlLocation.pop(); aoqi@0: } aoqi@0: aoqi@0: public void setWSDLLocation(String loc) { aoqi@0: _wsdlLocation.setLocation(loc); aoqi@0: } aoqi@0: aoqi@0: public String getWSDLLocation() { aoqi@0: return _wsdlLocation.getLocation(); aoqi@0: } aoqi@0: }