1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.iface.tools.axis1;
14
15 import java.io.File;
16
17 import com.eviware.soapui.SoapUI;
18 import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.AbstractToolsAction;
19 import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ArgumentBuilder;
20 import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ProcessToolRunner;
21 import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ToolHost;
22 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
23 import com.eviware.soapui.model.iface.Interface;
24 import com.eviware.soapui.settings.ToolsSettings;
25 import com.eviware.soapui.support.Tools;
26 import com.eviware.soapui.support.UISupport;
27 import com.eviware.soapui.support.types.StringToStringMap;
28 import com.eviware.x.form.XForm;
29 import com.eviware.x.form.XFormDialog;
30 import com.eviware.x.form.XFormDialogBuilder;
31 import com.eviware.x.form.XFormFactory;
32
33 /***
34 * Invokes axis 1.X WSDL2Java
35 *
36 * @author Ole.Matzura
37 */
38
39 public class Axis1XWSDL2JavaAction extends AbstractToolsAction<Interface>
40 {
41 private static final String NAMESPACE_MAPPING = "namespace mapping";
42 private static final String FACTORY = "factory";
43 private static final String OUTPUT = "output directory";
44 private static final String PACKAGE = "target package";
45 private static final String TYPE_MAPPING_VERSION = "typeMappingVersion";
46 private static final String DEPLOY_SCOPE = "deployScope";
47 private static final String SKELETON_DEPLOY = "skeletonDeploy";
48 private static final String WRAP_ARRAYS = "wrapArrays";
49 private static final String HELPER_GEN = "helperGen";
50 private static final String ALL = "all";
51 private static final String TEST_CASE = "testCase";
52 private static final String SERVER_SIDE = "server-side";
53 private static final String NO_WRAPPED = "noWrapped";
54 private static final String NO_IMPORTS = "noImports";
55
56 private static final String IMPLCLASS = "implementationClassName";
57 private static final String USERNAME = "user";
58 private static final String PASSWORD = "password";
59
60 public Axis1XWSDL2JavaAction( Interface iface )
61 {
62 super( iface, "Axis 1.X Artifacts", "Generates Axis 1.X artifacts using WSDL2Java" );
63 }
64
65 protected StringToStringMap initValues()
66 {
67 StringToStringMap values = super.initValues();
68
69 values.putIfMissing( SKELETON_DEPLOY, "none" );
70 values.putIfMissing( DEPLOY_SCOPE, "none" );
71 values.putIfMissing( TYPE_MAPPING_VERSION, "1.2" );
72
73 return values;
74 }
75
76 protected XFormDialog buildDialog()
77 {
78 XFormDialogBuilder builder = XFormFactory.createDialogBuilder( "Axis 1.X WSDL2Java" );
79
80 XForm mainForm = builder.createForm( "Basic" );
81 addWSDLFields(mainForm);
82
83 mainForm.addTextField( OUTPUT, "The root directory for all emitted files.", XForm.FieldType.PROJECT_FOLDER );
84 mainForm.addCheckBox( SERVER_SIDE, "(emit server-side bindings for web service)" );
85 mainForm.addCheckBox( ALL, "(generate code for all elements, even unreferenced ones)" );
86
87 mainForm.addComboBox( DEPLOY_SCOPE, new String[] { "none", "Application", "Session", "Request"},
88 "add scope to deploy.wsdd");
89
90 mainForm.addComboBox( SKELETON_DEPLOY, new String[] { "none", "true", "false"},
91 "deploy skeleton (true) or implementation (false) in deploy.wsdd");
92
93 mainForm.addCheckBox( NO_IMPORTS, "(only generate code for immediate WSDL document)" );
94 mainForm.addCheckBox( NO_WRAPPED, "(turn off support for \"wrapped\" document/literal)" );
95 mainForm.addCheckBox( TEST_CASE, "(emit junit testcase class for web service)" );
96 mainForm.addCheckBox( HELPER_GEN, "(emits separate Helper classes for meta data)" );
97 mainForm.addCheckBox( WRAP_ARRAYS, "(Prefer generating JavaBean classes for certain schema array patterns)" );
98
99 XForm advForm = builder.createForm( "Advanced" );
100 advForm.addComboBox( TYPE_MAPPING_VERSION, new String[] { "1.2", "1.1"},
101 "typeMapping version to use");
102
103 advForm.addTextField( IMPLCLASS, "use this as the implementation class", XForm.FieldType.JAVA_CLASS );
104 advForm.addTextField( FACTORY, "the name of a class which extends JavaWriterFactory", XForm.FieldType.JAVA_CLASS );
105
106 advForm.addTextField( PACKAGE, "maps all namespaces in a WSDL document to the same Java package name", XForm.FieldType.JAVA_PACKAGE );
107 advForm.addNameSpaceTable( NAMESPACE_MAPPING, modelItem );
108
109 advForm.addTextField( USERNAME, "username to access the WSDL-URI", XForm.FieldType.TEXT );
110 advForm.addTextField( PASSWORD, "password to access the WSDL-URI", XForm.FieldType.TEXT );
111
112 XForm argsForm = buildArgsForm( builder, true, "WSDL2Java" );
113
114 return builder.buildDialog( buildDefaultActions( HelpUrls.AXIS1X_HELP_URL ),
115 "Specify arguments for Axis 1.X Wsdl2Java", UISupport.TOOL_ICON );
116 }
117
118
119 protected void generate(StringToStringMap values, ToolHost toolHost) throws Exception
120 {
121 String axisDir = SoapUI.getSettings().getString( ToolsSettings.AXIS_1_X_LOCATION, null );
122 if( Tools.isEmpty( axisDir ))
123 {
124 UISupport.showErrorMessage( "Axis 1.X location must be set in global preferences" );
125 return;
126 }
127
128 File axisLibDir = new File( axisDir + File.separatorChar + "lib" );
129 if( !axisLibDir.exists() )
130 {
131 UISupport.showErrorMessage( "Could not find Axis 1.X lib directory [" + axisLibDir + "]" );
132 return;
133 }
134
135 String classpath = buildClasspath(axisLibDir);
136
137 ProcessBuilder builder = new ProcessBuilder();
138 ArgumentBuilder args = buildArgs(classpath, values);
139
140 builder.command( args.getArgs() );
141 builder.directory(axisLibDir);
142
143 toolHost.run( new ProcessToolRunner( builder, "Axis 1.x wsdl2java", modelItem ));
144 }
145
146 private ArgumentBuilder buildArgs(String classpath, StringToStringMap values)
147 {
148 ArgumentBuilder builder = new ArgumentBuilder( values );
149 builder.addArgs( "java" );
150
151 addJavaArgs( values, builder );
152
153 builder.addArgs( "-cp", classpath, "org.apache.axis.wsdl.WSDL2Java", "-v" );
154
155 builder.addBoolean( NO_IMPORTS, "-n" );
156 builder.addBoolean( NO_WRAPPED, "-W" );
157 builder.addBoolean( SERVER_SIDE, "-s" );
158 builder.addBoolean( TEST_CASE, "-t" );
159 builder.addBoolean( ALL, "-a" );
160 builder.addBoolean( HELPER_GEN, "-H" );
161 builder.addBoolean( WRAP_ARRAYS, "-w" );
162
163 if( !values.get( SKELETON_DEPLOY ).equals( "none" ))
164 builder.addString( SKELETON_DEPLOY, "-S" );
165
166 if( !values.get( DEPLOY_SCOPE ).equals( "none" ))
167 builder.addString( DEPLOY_SCOPE, "-d" );
168
169 values.put( OUTPUT, Tools.ensureDir( values.get( OUTPUT )));
170
171 builder.addString( TYPE_MAPPING_VERSION, "-T" );
172 builder.addString( PACKAGE, "-p" );
173 builder.addString( OUTPUT, "-o" );
174 builder.addString( FACTORY, "-F" );
175 builder.addString( IMPLCLASS, "-c" );
176 builder.addString( USERNAME, "-U" );
177 builder.addString( PASSWORD, "-P" );
178
179 try
180 {
181 StringToStringMap nsMappings = StringToStringMap.fromXml(values.get(NAMESPACE_MAPPING));
182 for (String namespace : nsMappings.keySet())
183 {
184 builder.addArgs( "-N" + namespace + "=" + nsMappings.get(namespace));
185 }
186 }
187 catch (Exception e)
188 {
189 e.printStackTrace();
190 }
191
192 addToolArgs( values, builder );
193
194 builder.addArgs( getWsdlUrl( values ) );
195 return builder;
196 }
197 }