View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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  
17  import com.eviware.soapui.impl.support.definition.DefinitionCache;
18  import com.eviware.soapui.impl.support.definition.export.WsdlDefinitionExporter;
19  import com.eviware.soapui.impl.support.definition.support.AbstractDefinitionContext;
20  import com.eviware.soapui.impl.support.definition.support.InterfaceCacheDefinitionLoader;
21  import com.eviware.soapui.impl.wsdl.WsdlInterface;
22  import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
23  
24  /***
25   * Holder for WSDL4J Definitions and related SchemaTypeLoader types
26   * 
27   * @author Ole.Matzura
28   */
29  
30  public class WsdlContext extends
31  		AbstractDefinitionContext<WsdlInterface, WsdlDefinitionLoader, WsdlInterfaceDefinition>
32  {
33  	private SoapVersion soapVersion = SoapVersion.Soap11;
34  
35  	public WsdlContext( String url, WsdlInterface iface )
36  	{
37  		super( url, iface );
38  	}
39  
40  	public WsdlContext( String wsdlUrl )
41  	{
42  		this( wsdlUrl, ( WsdlInterface )null );
43  	}
44  
45  	public WsdlContext( String wsdlUrl, SoapVersion soapVersion )
46  	{
47  		this( wsdlUrl );
48  		if( soapVersion != null )
49  		{
50  			this.soapVersion = soapVersion;
51  		}
52  	}
53  
54  	protected WsdlDefinitionLoader createDefinitionLoader( DefinitionCache wsdlInterfaceDefinitionCache )
55  	{
56  		return new InterfaceCacheDefinitionLoader( wsdlInterfaceDefinitionCache );
57  	}
58  
59  	protected WsdlDefinitionLoader createDefinitionLoader( String url )
60  	{
61  		return new UrlWsdlLoader( url, getInterface() );
62  	}
63  
64  	protected WsdlInterfaceDefinition loadDefinition( WsdlDefinitionLoader loader ) throws Exception
65  	{
66  		return new WsdlInterfaceDefinition( getInterface() ).load( loader );
67  	}
68  
69  	public Definition getDefinition() throws Exception
70  	{
71  		return getInterfaceDefinition().getWsdlDefinition();
72  	}
73  
74  	public SoapVersion getSoapVersion()
75  	{
76  		return getInterface() == null ? soapVersion : getInterface().getSoapVersion();
77  	}
78  
79  	public String export( String path ) throws Exception
80  	{
81  		return new WsdlDefinitionExporter( getInterface() ).export( path );
82  	}
83  }