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.openejb.server.axis2.util;
19:
20: import org.apache.openejb.util.Logger;
21: import org.apache.openejb.util.LogCategory;
22: import org.xml.sax.InputSource;
23:
24: import javax.wsdl.xml.WSDLLocator;
25: import java.io.IOException;
26:
27: public class SimpleWsdlLocator implements WSDLLocator {
28: private static final Logger logger = Logger.getInstance(
29: LogCategory.AXIS2, SimpleWsdlLocator.class);
30:
31: private String baseURI;
32: private String lastImportLocation;
33: private SimpleUriResolver resolver;
34:
35: public SimpleWsdlLocator(String baseURI) {
36: this .baseURI = baseURI;
37: this .resolver = new SimpleUriResolver();
38: }
39:
40: public InputSource getBaseInputSource() {
41: return resolve("", this .baseURI);
42: }
43:
44: public String getBaseURI() {
45: return this .baseURI;
46: }
47:
48: public InputSource getImportInputSource(String parentLocation,
49: String importLocation) {
50: return resolve(parentLocation, importLocation);
51: }
52:
53: protected InputSource resolve(String parentLocation,
54: String importLocation) {
55: if (logger.isDebugEnabled()) {
56: logger.debug("Resolving '" + importLocation
57: + "' relative to '" + parentLocation + "'");
58: }
59: try {
60: this .resolver.resolve(parentLocation, importLocation);
61: if (this .resolver.isResolved()) {
62: this .lastImportLocation = this .resolver.getURI()
63: .toString();
64: if (logger.isDebugEnabled()) {
65: logger.debug("Resolved location '"
66: + this .lastImportLocation + "'");
67: }
68: return new InputSource(this .resolver.getInputStream());
69: }
70: } catch (IOException e) {
71: // ignore
72: }
73: return null;
74: }
75:
76: public String getLatestImportURI() {
77: return this .lastImportLocation;
78: }
79:
80: public void close() {
81: }
82: }
|