01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.geronimo.axis2.util;
19:
20: import java.io.IOException;
21:
22: import javax.wsdl.xml.WSDLLocator;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26: import org.xml.sax.InputSource;
27:
28: public class SimpleWSDLLocator implements WSDLLocator {
29:
30: private static final Log LOG = LogFactory
31: .getLog(SimpleWSDLLocator.class);
32:
33: private String baseURI;
34: private String lastImportLocation;
35: private SimpleURIResolver resolver;
36:
37: public SimpleWSDLLocator(String baseURI) {
38: this .baseURI = baseURI;
39: this .resolver = new SimpleURIResolver();
40: }
41:
42: public InputSource getBaseInputSource() {
43: return resolve("", this .baseURI);
44: }
45:
46: public String getBaseURI() {
47: return this .baseURI;
48: }
49:
50: public InputSource getImportInputSource(String parentLocation,
51: String importLocation) {
52: return resolve(parentLocation, importLocation);
53: }
54:
55: protected InputSource resolve(String parentLocation,
56: String importLocation) {
57: if (LOG.isDebugEnabled()) {
58: LOG.debug("Resolving '" + importLocation
59: + "' relative to '" + parentLocation + "'");
60: }
61: try {
62: this .resolver.resolve(parentLocation, importLocation);
63: if (this .resolver.isResolved()) {
64: this .lastImportLocation = this .resolver.getURI()
65: .toString();
66: if (LOG.isDebugEnabled()) {
67: LOG.debug("Resolved location '"
68: + this .lastImportLocation + "'");
69: }
70: return new InputSource(this .resolver.getInputStream());
71: }
72: } catch (IOException e) {
73: // ignore
74: }
75: return null;
76: }
77:
78: public String getLatestImportURI() {
79: return this .lastImportLocation;
80: }
81:
82: public void close() {
83: }
84:
85: }
|