View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 eviware.com
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.support.wsdl;
14  
15  import javax.wsdl.Definition;
16  import javax.wsdl.factory.WSDLFactory;
17  import javax.wsdl.xml.WSDLReader;
18  
19  import org.apache.log4j.Logger;
20  
21  import com.eviware.soapui.impl.support.definition.support.XmlSchemaBasedInterfaceDefinition;
22  import com.eviware.soapui.impl.wsdl.WsdlInterface;
23  
24  public class WsdlInterfaceDefinition extends XmlSchemaBasedInterfaceDefinition<WsdlInterface>
25  {
26  	private Definition definition;
27  
28  	private static WSDLFactory factory;
29  	private static WSDLReader wsdlReader;
30  	private Logger log = Logger.getLogger( WsdlInterfaceDefinition.class );
31  
32  	public WsdlInterfaceDefinition( WsdlInterface iface )
33  	{
34  		super( iface );
35  	}
36  
37  	public WsdlInterfaceDefinition load( WsdlDefinitionLoader loader ) throws Exception
38  	{
39  		if( factory == null )
40  		{
41  			factory = WSDLFactory.newInstance();
42  			wsdlReader = factory.newWSDLReader();
43  			wsdlReader.setFeature( "javax.wsdl.verbose", true );
44  			wsdlReader.setFeature( "javax.wsdl.importDocuments", true );
45  		}
46  
47  		definition = wsdlReader.readWSDL( loader );
48  		log.debug( "Loaded WSDL: " + ( definition != null ? "ok" : "null" ) );
49  
50  		if( !loader.isAborted() )
51  		{
52  			super.loadSchemaTypes( loader );
53  		}
54  		else
55  			throw new Exception( "Loading of WSDL from [" + loader.getBaseURI() + "] was aborted" );
56  
57  		return this;
58  	}
59  
60  	public String getTargetNamespace()
61  	{
62  		return definition.getTargetNamespace();
63  	}
64  
65  	public Definition getWsdlDefinition()
66  	{
67  		return definition;
68  	}
69  }