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: */
19: package org.apache.axis2.deployment.resolver;
20:
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23: import org.apache.ws.commons.schema.resolver.DefaultURIResolver;
24: import org.xml.sax.InputSource;
25:
26: import javax.wsdl.xml.WSDLLocator;
27: import java.io.InputStream;
28: import java.net.URI;
29:
30: public class WarBasedWSDLLocator extends DefaultURIResolver implements
31: WSDLLocator {
32: protected static final Log log = LogFactory
33: .getLog(WarBasedWSDLLocator.class);
34:
35: private InputStream baseInputStream;
36: private URI lastImportLocation;
37: private String baseURI;
38: private ClassLoader classLoader;
39:
40: public WarBasedWSDLLocator(String baseURI, ClassLoader classLoader,
41: InputStream baseInputStream) {
42: this .baseURI = baseURI;
43: this .baseInputStream = baseInputStream;
44: this .classLoader = classLoader;
45: }
46:
47: public InputSource getBaseInputSource() {
48: return new InputSource(baseInputStream);
49: }
50:
51: /**
52: * @param parentLocation
53: * @param importLocation
54: */
55: public InputSource getImportInputSource(String parentLocation,
56: String importLocation) {
57: lastImportLocation = URI.create(parentLocation).resolve(
58: importLocation);
59:
60: if (isAbsolute(importLocation)) {
61: return super .resolveEntity(null, importLocation,
62: parentLocation);
63: } else {
64: String searchingStr = lastImportLocation.toString();
65: return new InputSource(classLoader
66: .getResourceAsStream(searchingStr));
67: }
68: }
69:
70: /**
71: * As for the zip there is no point in returning
72: * a base URI
73: */
74: public String getBaseURI() {
75: // we don't care
76: return baseURI;
77: }
78:
79: /**
80: * returns the latest import
81: */
82: public String getLatestImportURI() {
83: //we don't care about this either
84: return lastImportLocation.toString();
85: }
86:
87: public void close() {
88: //TODO: FIXME:
89: }
90: }
|