src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/DOMBuilder.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     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/parser/DOMBuilder.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,125 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, 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.parser;
    1.30 +
    1.31 +import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants;
    1.32 +import com.sun.tools.internal.xjc.reader.internalizer.LocatorTable;
    1.33 +import com.sun.xml.internal.bind.marshaller.SAX2DOMEx;
    1.34 +import org.w3c.dom.Comment;
    1.35 +import org.w3c.dom.Document;
    1.36 +import org.w3c.dom.Element;
    1.37 +import org.w3c.dom.Node;
    1.38 +import org.xml.sax.Attributes;
    1.39 +import org.xml.sax.Locator;
    1.40 +import org.xml.sax.SAXException;
    1.41 +import org.xml.sax.ext.LexicalHandler;
    1.42 +
    1.43 +import java.util.Set;
    1.44 +
    1.45 +/**
    1.46 + * Builds DOM while keeping the location information.
    1.47 + *
    1.48 + * <p>
    1.49 + * This class also looks for outer most &lt;jaxws:bindings>
    1.50 + * customizations.
    1.51 + *
    1.52 + * @author
    1.53 + *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
    1.54 + *     Vivek Pandey
    1.55 + */
    1.56 +class DOMBuilder extends SAX2DOMEx implements LexicalHandler {
    1.57 +    /**
    1.58 +     * Grows a DOM tree under the given document, and
    1.59 +     * stores location information to the given table.
    1.60 +     *
    1.61 +     * @param outerMostBindings
    1.62 +     *      This set will receive newly found outermost
    1.63 +     *      jaxb:bindings customizations.
    1.64 +     */
    1.65 +    public DOMBuilder( Document dom, LocatorTable ltable, Set outerMostBindings ) {
    1.66 +        super( dom );
    1.67 +        this.locatorTable = ltable;
    1.68 +        this.outerMostBindings = outerMostBindings;
    1.69 +    }
    1.70 +
    1.71 +    /** Location information will be stored into this object. */
    1.72 +    private final LocatorTable locatorTable;
    1.73 +
    1.74 +    private final Set outerMostBindings;
    1.75 +
    1.76 +    private Locator locator;
    1.77 +
    1.78 +    public void setDocumentLocator(Locator locator) {
    1.79 +        this.locator = locator;
    1.80 +        super.setDocumentLocator(locator);
    1.81 +    }
    1.82 +
    1.83 +
    1.84 +    public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
    1.85 +        super.startElement(namespaceURI, localName, qName, atts);
    1.86 +
    1.87 +        Element e = getCurrentElement();
    1.88 +        locatorTable.storeStartLocation( e, locator );
    1.89 +
    1.90 +        // check if this element is an outer-most <jaxb:bindings>
    1.91 +        if( JAXWSBindingsConstants.JAXWS_BINDINGS.getNamespaceURI().equals(e.getNamespaceURI())
    1.92 +        &&  "bindings".equals(e.getLocalName()) ) {
    1.93 +
    1.94 +            // if this is the root node (meaning that this file is an
    1.95 +            // external binding file) or if the parent is XML Schema element
    1.96 +            // (meaning that this is an "inlined" external binding)
    1.97 +            Node p = e.getParentNode();
    1.98 +            if( p instanceof Document) {
    1.99 +                outerMostBindings.add(e);   // remember this value
   1.100 +            }
   1.101 +        }
   1.102 +    }
   1.103 +
   1.104 +    public void endElement(String namespaceURI, String localName, String qName) {
   1.105 +        locatorTable.storeEndLocation( getCurrentElement(), locator );
   1.106 +        super.endElement(namespaceURI, localName, qName);
   1.107 +    }
   1.108 +
   1.109 +    public void startDTD(String name, String publicId, String systemId) throws SAXException {}
   1.110 +
   1.111 +    public void endDTD() throws SAXException {}
   1.112 +
   1.113 +    public void startEntity(String name) throws SAXException {}
   1.114 +
   1.115 +    public void endEntity(String name) throws SAXException {}
   1.116 +
   1.117 +    public void startCDATA() throws SAXException {}
   1.118 +
   1.119 +    public void endCDATA() throws SAXException {}
   1.120 +
   1.121 +    public void comment(char[] ch, int start, int length) throws SAXException {
   1.122 +        //Element e = getCurrentElement(); // does not work as the comments at the top of the document would return Document Node
   1.123 +        // instead of Element
   1.124 +        Node parent = nodeStack.peek();
   1.125 +        Comment comment = document.createComment(new String(ch,start,length));
   1.126 +        parent.appendChild(comment);
   1.127 +    }
   1.128 +}

mercurial