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.support.XmlSchemaBasedInterfaceDefinition;
16  import com.eviware.soapui.impl.wsdl.WsdlInterface;
17  import org.apache.log4j.Logger;
18  
19  import javax.wsdl.Definition;
20  import javax.wsdl.factory.WSDLFactory;
21  import javax.wsdl.xml.WSDLReader;
22  
23  public class WsdlInterfaceDefinition extends XmlSchemaBasedInterfaceDefinition<WsdlInterface>
24  {
25     private Definition definition;
26  
27     private static WSDLFactory factory;
28     private static WSDLReader wsdlReader;
29     private Logger log = Logger.getLogger(WsdlInterfaceDefinition.class);
30  
31     public WsdlInterfaceDefinition(WsdlInterface iface)
32     {
33        super(iface);
34     }
35  
36     public WsdlInterfaceDefinition load(WsdlDefinitionLoader loader) throws Exception
37     {
38        if (factory == null)
39        {
40           factory = WSDLFactory.newInstance();
41           wsdlReader = factory.newWSDLReader();
42           wsdlReader.setFeature("javax.wsdl.verbose", true);
43           wsdlReader.setFeature("javax.wsdl.importDocuments", true);
44        }
45  
46        definition = wsdlReader.readWSDL(loader);
47        log.debug("Loaded WSDL: " + (definition != null ? "ok" : "null"));
48  
49        if (!loader.isAborted())
50        {
51           super.loadSchemaTypes(loader);
52        }
53        else
54           throw new Exception("Loading of WSDL from [" + loader.getBaseURI() + "] was aborted");
55  
56        return this;
57     }
58  
59     public String getTargetNamespace()
60     {
61        return definition.getTargetNamespace();
62     }
63  
64     public Definition getWsdlDefinition()
65     {
66        return definition;
67     }
68  }