jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/api/server/SDDocumentSource.java
changeset 36523 116e5d5cdade
parent 25871 b80b84e87032
child 43852 93a527059d8a
equal deleted inserted replaced
36522:0017f3cf1657 36523:116e5d5cdade
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    24  */
    24  */
    25 
    25 
    26 package com.sun.xml.internal.ws.api.server;
    26 package com.sun.xml.internal.ws.api.server;
    27 
    27 
    28 import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
    28 import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
       
    29 import com.sun.xml.internal.ws.server.ServerRtException;
    29 import com.sun.xml.internal.ws.streaming.TidyXMLStreamReader;
    30 import com.sun.xml.internal.ws.streaming.TidyXMLStreamReader;
    30 import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
    31 import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
    31 
    32 
    32 import javax.xml.stream.XMLInputFactory;
    33 import javax.xml.stream.XMLInputFactory;
    33 import javax.xml.stream.XMLStreamException;
    34 import javax.xml.stream.XMLStreamException;
    34 import javax.xml.stream.XMLStreamReader;
    35 import javax.xml.stream.XMLStreamReader;
    35 import java.io.IOException;
    36 import java.io.IOException;
    36 import java.io.InputStream;
    37 import java.io.InputStream;
       
    38 import java.net.MalformedURLException;
    37 import java.net.URL;
    39 import java.net.URL;
    38 
    40 
    39 /**
    41 /**
    40  * SPI that provides the source of {@link SDDocument}.
    42  * SPI that provides the source of {@link SDDocument}.
    41  *
    43  *
   110             }
   112             }
   111         };
   113         };
   112     }
   114     }
   113 
   115 
   114     /**
   116     /**
       
   117      * Creates {@link SDDocumentSource} from resource path using resolvingClass to read the resource.
       
   118      * Required for Jigsaw runtime.
       
   119      *
       
   120      * @param resolvingClass class used to read resource
       
   121      * @param path resource path
       
   122      */
       
   123     public static SDDocumentSource create(final Class resolvingClass, final String path) {
       
   124         return new SDDocumentSource() {
       
   125 
       
   126             public XMLStreamReader read(XMLInputFactory xif) throws IOException, XMLStreamException {
       
   127                 InputStream is = inputStream();
       
   128                 return new TidyXMLStreamReader(xif.createXMLStreamReader(path,is), is);
       
   129             }
       
   130 
       
   131             public XMLStreamReader read() throws IOException, XMLStreamException {
       
   132                 InputStream is = inputStream();
       
   133                 return new TidyXMLStreamReader(XMLStreamReaderFactory.create(path,is,false), is);
       
   134             }
       
   135 
       
   136             public URL getSystemId() {
       
   137                 try {
       
   138                     return new URL("file://" + path);
       
   139                 } catch (MalformedURLException e) {
       
   140                     return null;
       
   141                 }
       
   142             }
       
   143 
       
   144             private InputStream inputStream() throws IOException {
       
   145                 java.lang.reflect.Module module = resolvingClass.getModule();
       
   146                 if (module != null) {
       
   147                     InputStream stream = module.getResourceAsStream(path);
       
   148                     if (stream != null) {
       
   149                         return stream;
       
   150                     }
       
   151                 }
       
   152                 throw new ServerRtException("cannot.load.wsdl", path);
       
   153             }
       
   154 
       
   155         };
       
   156     }
       
   157 
       
   158     /**
   115      * Creates a {@link SDDocumentSource} from {@link XMLStreamBuffer}.
   159      * Creates a {@link SDDocumentSource} from {@link XMLStreamBuffer}.
   116      */
   160      */
   117     public static SDDocumentSource create(final URL systemId, final XMLStreamBuffer xsb) {
   161     public static SDDocumentSource create(final URL systemId, final XMLStreamBuffer xsb) {
   118         return new SDDocumentSource() {
   162         return new SDDocumentSource() {
   119             public XMLStreamReader read(XMLInputFactory xif) throws XMLStreamException {
   163             public XMLStreamReader read(XMLInputFactory xif) throws XMLStreamException {