18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.xml.internal.ws.api.server;
27
28 import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
29 import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
30 import com.sun.xml.internal.ws.server.ServerRtException;
31 import com.sun.xml.internal.ws.streaming.TidyXMLStreamReader;
32
33 import javax.xml.stream.XMLInputFactory;
34 import javax.xml.stream.XMLStreamException;
35 import javax.xml.stream.XMLStreamReader;
36 import java.io.IOException;
37 import java.io.InputStream;
38 import java.net.MalformedURLException;
39 import java.net.URL;
40
41 /**
42 * SPI that provides the source of {@link SDDocument}.
43 *
44 * <p>
45 * This abstract class could be implemented by applications, or one of the
46 * {@link #create} methods can be used.
47 *
48 * @author Kohsuke Kawaguchi
49 */
50 public abstract class SDDocumentSource {
51 /**
52 * Returns the {@link XMLStreamReader} that reads the document.
53 *
54 * <p>
55 * This method maybe invoked multiple times concurrently.
56 *
57 * @param xif
72 *
73 * <p>
74 * This method maybe invoked multiple times concurrently.
75 *
76 * @return
77 * The caller is responsible for closing the reader to avoid resource leak.
78 *
79 * @throws XMLStreamException
80 * if something goes wrong while creating a parser.
81 * @throws IOException
82 * if something goes wrong trying to read the document.
83 */
84 public abstract XMLStreamReader read() throws IOException, XMLStreamException;
85
86 /**
87 * System ID of this document.
88 * @return
89 */
90 public abstract URL getSystemId();
91
92 public static SDDocumentSource create(final Class<?> implClass, final String url) {
93 return create(url, implClass);
94 }
95
96 /**
97 * Creates {@link SDDocumentSource} from an URL.
98 * @param url
99 * @return
100 */
101 public static SDDocumentSource create(final URL url) {
102 return new SDDocumentSource() {
103 private final URL systemId = url;
104
105 @Override
106 public XMLStreamReader read(XMLInputFactory xif) throws IOException, XMLStreamException {
107 InputStream is = url.openStream();
108 return new TidyXMLStreamReader(
109 xif.createXMLStreamReader(systemId.toExternalForm(),is), is);
110 }
111
112 @Override
113 public XMLStreamReader read() throws IOException, XMLStreamException {
|
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.xml.internal.ws.api.server;
27
28 import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
29 import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
30 import com.sun.xml.internal.ws.server.ServerRtException;
31 import com.sun.xml.internal.ws.streaming.TidyXMLStreamReader;
32
33 import javax.xml.stream.XMLInputFactory;
34 import javax.xml.stream.XMLStreamException;
35 import javax.xml.stream.XMLStreamReader;
36 import java.io.IOException;
37 import java.io.InputStream;
38 import java.lang.reflect.Method;
39 import java.net.MalformedURLException;
40 import java.net.URL;
41
42 /**
43 * SPI that provides the source of {@link SDDocument}.
44 *
45 * <p>
46 * This abstract class could be implemented by applications, or one of the
47 * {@link #create} methods can be used.
48 *
49 * @author Kohsuke Kawaguchi
50 */
51 public abstract class SDDocumentSource {
52 /**
53 * Returns the {@link XMLStreamReader} that reads the document.
54 *
55 * <p>
56 * This method maybe invoked multiple times concurrently.
57 *
58 * @param xif
73 *
74 * <p>
75 * This method maybe invoked multiple times concurrently.
76 *
77 * @return
78 * The caller is responsible for closing the reader to avoid resource leak.
79 *
80 * @throws XMLStreamException
81 * if something goes wrong while creating a parser.
82 * @throws IOException
83 * if something goes wrong trying to read the document.
84 */
85 public abstract XMLStreamReader read() throws IOException, XMLStreamException;
86
87 /**
88 * System ID of this document.
89 * @return
90 */
91 public abstract URL getSystemId();
92
93 public static SDDocumentSource create(final Class<?> implClass, final String wsdlLocation) {
94 ClassLoader cl = implClass.getClassLoader();
95 URL url = cl.getResource(wsdlLocation);
96 if (url != null) {
97 return create(url);
98 } else {
99 return create(wsdlLocation, implClass);
100 }
101 }
102
103 /**
104 * Creates {@link SDDocumentSource} from an URL.
105 * @param url
106 * @return
107 */
108 public static SDDocumentSource create(final URL url) {
109 return new SDDocumentSource() {
110 private final URL systemId = url;
111
112 @Override
113 public XMLStreamReader read(XMLInputFactory xif) throws IOException, XMLStreamException {
114 InputStream is = url.openStream();
115 return new TidyXMLStreamReader(
116 xif.createXMLStreamReader(systemId.toExternalForm(),is), is);
117 }
118
119 @Override
120 public XMLStreamReader read() throws IOException, XMLStreamException {
|