001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.core.webservices;
018:
019: import org.xml.sax.InputSource;
020:
021: import javax.wsdl.xml.WSDLLocator;
022: import java.net.URL;
023: import java.net.URLConnection;
024: import java.net.MalformedURLException;
025: import java.net.URISyntaxException;
026: import java.io.File;
027: import java.io.IOException;
028:
029: public class WsdlResolver implements WSDLLocator {
030: private String baseUri;
031: private String importedUri;
032: private InputSource inputSource;
033:
034: public WsdlResolver(String baseURI, InputSource is) {
035: this .baseUri = baseURI;
036: inputSource = is;
037: }
038:
039: public InputSource getBaseInputSource() {
040: return inputSource;
041: }
042:
043: public String getBaseURI() {
044: return baseUri;
045: }
046:
047: public String getLatestImportURI() {
048: return importedUri;
049: }
050:
051: public InputSource getImportInputSource(String parent,
052: String importLocation) {
053: this .baseUri = parent;
054: URL parentUrl;
055: try {
056: parentUrl = new URL(parent);
057: URL importUrl = new URL(parentUrl, importLocation);
058: if (importUrl != null
059: && !importUrl.getProtocol().startsWith("file")) {
060: URLConnection con = importUrl.openConnection();
061: con.setUseCaches(false);
062: inputSource = new InputSource(con.getInputStream());
063: } else {
064: File file = new File(importUrl.toURI());
065: if (file.exists()) {
066: UriResolver resolver = new UriResolver(parent
067: .toString(), importLocation);
068: inputSource = new InputSource(resolver
069: .getInputStream());
070: } else {
071: UriResolver resolver = new UriResolver(
072: importLocation);
073: if (resolver.isResolved()) {
074: inputSource = new InputSource(resolver
075: .getInputStream());
076: }
077: }
078: }
079: importedUri = importUrl.toURI().toString();
080:
081: } catch (MalformedURLException e) {
082: //
083: } catch (URISyntaxException e) {
084: //
085: } catch (IOException e) {
086: //
087:
088: }
089: return inputSource;
090:
091: }
092:
093: public void close() {
094: if (inputSource.getByteStream() != null) {
095: try {
096: inputSource.getByteStream().close();
097: } catch (IOException e) {
098: //
099: }
100: }
101:
102: }
103: }
|