001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with 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, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 package org.apache.geronimo.axis2.util; 021 022 import java.io.IOException; 023 024 import javax.wsdl.xml.WSDLLocator; 025 026 import org.apache.commons.logging.Log; 027 import org.apache.commons.logging.LogFactory; 028 import org.xml.sax.InputSource; 029 030 public class SimpleWSDLLocator implements WSDLLocator { 031 032 private static final Log LOG = LogFactory.getLog(SimpleWSDLLocator.class); 033 034 private String baseURI; 035 private String lastImportLocation; 036 private SimpleURIResolver resolver; 037 038 public SimpleWSDLLocator(String baseURI) { 039 this.baseURI = baseURI; 040 this.resolver = new SimpleURIResolver(); 041 } 042 043 public InputSource getBaseInputSource() { 044 return resolve("", this.baseURI); 045 } 046 047 public String getBaseURI() { 048 return this.baseURI; 049 } 050 051 public InputSource getImportInputSource(String parentLocation, String importLocation) { 052 return resolve(parentLocation, importLocation); 053 } 054 055 protected InputSource resolve(String parentLocation, String importLocation) { 056 if (LOG.isDebugEnabled()) { 057 LOG.debug("Resolving '" + importLocation + "' relative to '" + parentLocation + "'"); 058 } 059 try { 060 this.resolver.resolve(parentLocation, importLocation); 061 if (this.resolver.isResolved()) { 062 this.lastImportLocation = this.resolver.getURI().toString(); 063 if (LOG.isDebugEnabled()) { 064 LOG.debug("Resolved location '" + this.lastImportLocation + "'"); 065 } 066 return new InputSource(this.resolver.getInputStream()); 067 } 068 } catch (IOException e) { 069 // ignore 070 } 071 return null; 072 } 073 074 public String getLatestImportURI() { 075 return this.lastImportLocation; 076 } 077 078 public void close() { 079 } 080 081 082 }