Save This Page
Home » openejb-3.1.2-src » org.apache » openejb » core » webservices » [javadoc | source]
    1   /**
    2    *
    3    * Licensed to the Apache Software Foundation (ASF) under one or more
    4    * contributor license agreements.  See the NOTICE file distributed with
    5    * this work for additional information regarding copyright ownership.
    6    * The ASF licenses this file to You under the Apache License, Version 2.0
    7    * (the "License"); you may not use this file except in compliance with
    8    * the License.  You may obtain a copy of the License at
    9    *
   10    *     http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing, software
   13    *  distributed under the License is distributed on an "AS IS" BASIS,
   14    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15    *  See the License for the specific language governing permissions and
   16    *  limitations under the License.
   17    */
   18   package org.apache.openejb.core.webservices;
   19   
   20   import org.xml.sax.InputSource;
   21   
   22   import javax.wsdl.xml.WSDLLocator;
   23   import java.net.URL;
   24   import java.net.URLConnection;
   25   import java.net.MalformedURLException;
   26   import java.net.URISyntaxException;
   27   import java.io.File;
   28   import java.io.IOException;
   29   
   30   public class WsdlResolver implements WSDLLocator {
   31       private String baseUri;
   32       private String importedUri;
   33       private InputSource inputSource;
   34   
   35       public WsdlResolver(String baseURI, InputSource is) {
   36           this.baseUri = baseURI;
   37           inputSource = is;
   38       }
   39   
   40       public InputSource getBaseInputSource() {
   41           return inputSource;
   42       }
   43   
   44       public String getBaseURI() {
   45           return baseUri;
   46       }
   47   
   48       public String getLatestImportURI() {
   49           return importedUri;
   50       }
   51   
   52       public InputSource getImportInputSource(String parent, String importLocation) {
   53           this.baseUri = parent;
   54           URL parentUrl;
   55           try {
   56               parentUrl = new URL(parent);
   57               URL importUrl = new URL(parentUrl, importLocation);
   58               if (importUrl != null && !importUrl.getProtocol().startsWith("file")) {
   59                   URLConnection con = importUrl.openConnection();
   60                   con.setUseCaches(false);
   61                   inputSource = new InputSource(con.getInputStream());
   62               } else {
   63                   File file = new File(importUrl.toURI());
   64                   if (file.exists()) {
   65                       UriResolver resolver = new UriResolver(parent.toString(), importLocation);
   66                       inputSource = new InputSource(resolver.getInputStream());
   67                   } else {
   68                       UriResolver resolver = new UriResolver(importLocation);
   69                       if (resolver.isResolved()) {
   70                           inputSource = new InputSource(resolver.getInputStream());
   71                       }
   72                   }
   73               }
   74               importedUri = importUrl.toURI().toString();
   75   
   76           } catch (MalformedURLException e) {
   77               //
   78           } catch (URISyntaxException e) {
   79               //
   80           } catch (IOException e) {
   81               //
   82   
   83           }
   84           return inputSource;
   85   
   86       }
   87   
   88       public void close() {
   89           if (inputSource.getByteStream() != null) {
   90               try {
   91                   inputSource.getByteStream().close();
   92               } catch (IOException e) {
   93                   //
   94               }
   95           }
   96   
   97       }
   98   }

Save This Page
Home » openejb-3.1.2-src » org.apache » openejb » core » webservices » [javadoc | source]