1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.support;
14
15 import javax.wsdl.Definition;
16 import javax.wsdl.factory.WSDLFactory;
17 import javax.wsdl.xml.WSDLReader;
18 import javax.xml.namespace.QName;
19
20 import org.apache.xmlbeans.SchemaType;
21 import org.apache.xmlbeans.SchemaTypeLoader;
22
23 import com.eviware.soapui.SoapUI;
24 import com.eviware.soapui.support.ProgressDialog;
25 import com.eviware.soapui.support.SwingWorker;
26
27 /***
28 * Holder for WSDL4J Definitions and related SchemaTypeLoader types
29 *
30 * @author Ole.Matzura
31 */
32
33 public class WsdlContext
34 {
35 private String url;
36 private Definition definition;
37 private SchemaTypeLoader schemaTypes;
38 private boolean loaded;
39
40 public WsdlContext( String url )
41 {
42 this.url = url;
43 }
44
45 public Definition getDefinition() throws Exception
46 {
47 if( !loaded )
48 load();
49
50 return definition;
51 }
52
53 public void setDefinition( String url )
54 {
55 this.url = url;
56 loaded = false;
57 }
58
59 public void load() throws Exception
60 {
61 ProgressDialog progressDialog = SoapUI.getInstance() == null ? null :
62 new ProgressDialog( "Progress", "Loading WSDL", 1, "Loading definition..", null );
63
64 Loader loader = new Loader( progressDialog );
65 loader.start();
66 if( progressDialog != null )
67 {
68 progressDialog.setVisible( true );
69 }
70
71 if( loader.get() != null )
72 {
73 throw (Exception)loader.get();
74 }
75 else loaded = true;
76 }
77
78 public SchemaTypeLoader getSchemaTypes() throws Exception
79 {
80 if( !loaded )
81 load();
82
83 return schemaTypes;
84 }
85
86 private class Loader extends SwingWorker
87 {
88 private ProgressDialog progressDialog;
89
90 public Loader( ProgressDialog progressDialog )
91 {
92 this.progressDialog = progressDialog;
93 }
94
95 public Object construct()
96 {
97 try
98 {
99 WSDLFactory factory = WSDLFactory.newInstance();
100 WSDLReader wsdlReader = factory.newWSDLReader();
101 wsdlReader.setFeature("javax.wsdl.verbose", true);
102 wsdlReader.setFeature("javax.wsdl.importDocuments", true);
103
104 if( progressDialog != null )
105 progressDialog.setProgress( 1, "Loading wsdl.." );
106 definition = wsdlReader.readWSDL(url);
107 if( progressDialog != null )
108 progressDialog.setProgress( 1, "Loading schema types" );
109
110 schemaTypes = SchemaUtils.loadSchemaTypes(url);
111 return null;
112 }
113 catch (Exception e)
114 {
115 return e;
116 }
117 }
118
119 public void finished()
120 {
121 if( progressDialog != null )
122 progressDialog.setVisible( false );
123 }
124 }
125
126 public boolean hasSchemaTypes() throws Exception
127 {
128 if( !loaded )
129 load();
130
131 return schemaTypes != null;
132 }
133
134 public SchemaType findType(QName typeName) throws Exception
135 {
136 if( !loaded )
137 load();
138
139 return schemaTypes == null ? null : schemaTypes.findType( typeName );
140 }
141
142 public String getUrl()
143 {
144 return url;
145 }
146 }