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.cxf.wsdl11;
19:
20: import javax.wsdl.xml.WSDLLocator;
21:
22: import org.xml.sax.InputSource;
23:
24: import org.apache.cxf.resource.ExtendedURIResolver;
25: import org.apache.xml.resolver.Catalog;
26:
27: public class WSDLLocatorImpl implements WSDLLocator {
28:
29: private String wsdlUrl;
30: private ExtendedURIResolver resolver;
31:
32: private String baseUri;
33: private String importedUri;
34:
35: private Catalog catalogResolver;
36:
37: public WSDLLocatorImpl(String wsdlUrl) {
38: this .wsdlUrl = wsdlUrl;
39: this .baseUri = this .wsdlUrl;
40: resolver = new ExtendedURIResolver();
41: }
42:
43: public void setCatalogResolver(final Catalog cr) {
44: this .catalogResolver = cr;
45: }
46:
47: private InputSource resolve(final String target, final String base) {
48: try {
49: String resolvedLocation = null;
50: if (catalogResolver != null) {
51: resolvedLocation = catalogResolver
52: .resolveSystem(target);
53: }
54: if (resolvedLocation == null) {
55: return this .resolver.resolve(target, base);
56: } else {
57: return this .resolver.resolve(resolvedLocation, base);
58: }
59: } catch (Exception e) {
60: throw new RuntimeException("Catalog resolve failed: ", e);
61: }
62: }
63:
64: public InputSource getBaseInputSource() {
65: InputSource result = resolve(baseUri, null);
66: baseUri = resolver.getURI();
67: return result;
68: }
69:
70: public String getBaseURI() {
71: return baseUri;
72: }
73:
74: public String getLatestImportURI() {
75: return resolver.getLatestImportURI();
76: }
77:
78: public InputSource getImportInputSource(String parent,
79: String importLocation) {
80: this .baseUri = parent;
81: this .importedUri = importLocation;
82: return resolve(this .importedUri, this .baseUri);
83: }
84:
85: public void close() {
86: resolver.close();
87: }
88: }
|