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