View Javadoc

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