src/share/jaxws_classes/com/sun/xml/internal/ws/api/server/SDDocumentSource.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/server/SDDocumentSource.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,132 @@
     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.xml.internal.ws.api.server;
    1.30 +
    1.31 +import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
    1.32 +import com.sun.xml.internal.ws.streaming.TidyXMLStreamReader;
    1.33 +import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
    1.34 +
    1.35 +import javax.xml.stream.XMLInputFactory;
    1.36 +import javax.xml.stream.XMLStreamException;
    1.37 +import javax.xml.stream.XMLStreamReader;
    1.38 +import java.io.IOException;
    1.39 +import java.io.InputStream;
    1.40 +import java.net.URL;
    1.41 +
    1.42 +/**
    1.43 + * SPI that provides the source of {@link SDDocument}.
    1.44 + *
    1.45 + * <p>
    1.46 + * This abstract class could be implemented by appliations, or one of the
    1.47 + * {@link #create} methods can be used.
    1.48 + *
    1.49 + * @author Kohsuke Kawaguchi
    1.50 + */
    1.51 +public abstract class SDDocumentSource {
    1.52 +    /**
    1.53 +     * Returns the {@link XMLStreamReader} that reads the document.
    1.54 +     *
    1.55 +     * <p>
    1.56 +     * This method maybe invoked multiple times concurrently.
    1.57 +     *
    1.58 +     * @param xif
    1.59 +     *      The implementation may choose to use this object when it wants to
    1.60 +     *      create a new parser (or it can just ignore this parameter completely.)
    1.61 +     * @return
    1.62 +     *      The caller is responsible for closing the reader to avoid resource leak.
    1.63 +     *
    1.64 +     * @throws XMLStreamException
    1.65 +     *      if something goes wrong while creating a parser.
    1.66 +     * @throws IOException
    1.67 +     *      if something goes wrong trying to read the document.
    1.68 +     */
    1.69 +    public abstract XMLStreamReader read(XMLInputFactory xif) throws IOException, XMLStreamException;
    1.70 +
    1.71 +    /**
    1.72 +     * Returns the {@link XMLStreamReader} that reads the document.
    1.73 +     *
    1.74 +     * <p>
    1.75 +     * This method maybe invoked multiple times concurrently.
    1.76 +     *
    1.77 +     * @return
    1.78 +     *      The caller is responsible for closing the reader to avoid resource leak.
    1.79 +     *
    1.80 +     * @throws XMLStreamException
    1.81 +     *      if something goes wrong while creating a parser.
    1.82 +     * @throws IOException
    1.83 +     *      if something goes wrong trying to read the document.
    1.84 +     */
    1.85 +    public abstract XMLStreamReader read() throws IOException, XMLStreamException;
    1.86 +
    1.87 +    /**
    1.88 +     * System ID of this document.
    1.89 +     */
    1.90 +    public abstract URL getSystemId();
    1.91 +
    1.92 +    /**
    1.93 +     * Creates {@link SDDocumentSource} from an URL.
    1.94 +     */
    1.95 +    public static SDDocumentSource create(final URL url) {
    1.96 +        return new SDDocumentSource() {
    1.97 +            private final URL systemId = url;
    1.98 +
    1.99 +            public XMLStreamReader read(XMLInputFactory xif) throws IOException, XMLStreamException {
   1.100 +                InputStream is = url.openStream();
   1.101 +                return new TidyXMLStreamReader(
   1.102 +                    xif.createXMLStreamReader(systemId.toExternalForm(),is), is);
   1.103 +            }
   1.104 +
   1.105 +            public XMLStreamReader read() throws IOException, XMLStreamException {
   1.106 +                InputStream is = url.openStream();
   1.107 +                return new TidyXMLStreamReader(
   1.108 +                   XMLStreamReaderFactory.create(systemId.toExternalForm(),is,false), is);
   1.109 +            }
   1.110 +
   1.111 +            public URL getSystemId() {
   1.112 +                return systemId;
   1.113 +            }
   1.114 +        };
   1.115 +    }
   1.116 +
   1.117 +    /**
   1.118 +     * Creates a {@link SDDocumentSource} from {@link XMLStreamBuffer}.
   1.119 +     */
   1.120 +    public static SDDocumentSource create(final URL systemId, final XMLStreamBuffer xsb) {
   1.121 +        return new SDDocumentSource() {
   1.122 +            public XMLStreamReader read(XMLInputFactory xif) throws XMLStreamException {
   1.123 +                return xsb.readAsXMLStreamReader();
   1.124 +            }
   1.125 +
   1.126 +            public XMLStreamReader read() throws XMLStreamException {
   1.127 +                return xsb.readAsXMLStreamReader();
   1.128 +            }
   1.129 +
   1.130 +            public URL getSystemId() {
   1.131 +                return systemId;
   1.132 +            }
   1.133 +        };
   1.134 +    }
   1.135 +}

mercurial