View Javadoc

1   package org.codehaus.mojo.weblogic;
2   
3   /*
4    * Copyright 2008 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.apache.maven.plugin.MojoExecutionException;
20  import org.apache.tools.ant.Project;
21  import org.apache.tools.ant.types.Path;
22  import org.codehaus.mojo.weblogic.util.WeblogicMojoUtilities;
23  import weblogic.wsee.tools.anttasks.ClientGenTask;
24  
25  import java.io.File;
26  
27  /**
28   * Runs Client Gen on a given WSDL. This client gen uses the BEA refactored client gen tool
29   * first appearing in weblogic 9. This is the preferred client gen tool for Weblogic 9.0 and
30   * newer.
31   *
32   * @author <a href="mailto:josborn@belltracy.com">Jon Osborn</a>
33   * @version $Id: ClientGen9Mojo.java 7025 2008-05-21 01:50:58Z jonnio $
34   * @description This mojo will run client gen on a given WSDL. This client gen uses the BEA refactored client gen tool
35   * first appearing in weblogic 9. This is the preferred client gen tool for Weblogic 9.0 and newer.
36   * @goal clientgen9
37   * @requiresDependencyResolution compile
38   */
39  public class ClientGen9Mojo
40      extends AbstractWeblogicMojo
41  {
42  
43      /**
44       * The filename of the war file to find the services. The file path is
45       * extracted from the artifact list.
46       *
47       * @parameter
48       */
49      private String warFileName;
50  
51      /**
52       * The wsdl to client gen from. If warFileName is specified, this parameter
53       * is the root relative file to use when creating the URI for the wsdl.
54       *
55       * @parameter
56       */
57      private String inputWSDL;
58  
59      /**
60       * The directory to output the generated code to.
61       *
62       * @parameter default-value="${basedir}/src/main/java"
63       */
64      private String outputDir;
65  
66      /**
67       * The package name of the output code.
68       *
69       * @parameter default-value="com.test.webservice"
70       */
71      private String packageName;
72  
73      /**
74       * The name of the service.
75       *
76       * @parameter
77       */
78      private String serviceName;
79  
80      /**
81       * Output verbose messages
82       *
83       * @parameter default-value="false"
84       */
85      private boolean verbose;
86  
87      /**
88       * Whether or not to use server types from the ear file in the client jar.
89       *
90       * @parameter default-value="false"
91       */
92      private boolean useServerTypes;
93  
94      /**
95       * Sets whether or not to create the type conversions for a web service in
96       * the client.
97       *
98       * @parameter default-value="true"
99       */
100     private boolean autotype;
101 
102     /**
103      * Sets whether or not to use the jaxRPCWrappedArrayStyle
104      *
105      * @parameter default-value="true"
106      */
107     private boolean jaxRPCWrappedArrayStyle;
108 
109     /**
110      * This method will run client gen on the given WSDL.
111      *
112      * @throws MojoExecutionException Thrown if we fail to obtain the WSDL.
113      */
114     public void execute()
115         throws MojoExecutionException
116     {
117         super.execute();
118 
119         if ( getLog().isInfoEnabled() )
120         {
121             getLog().info( "Weblogic client gen beginning " );
122         }
123         if ( getLog().isInfoEnabled() )
124         {
125             getLog().info( " Detailed client gen settings information " + this.toString() );
126         }
127 
128         try
129         {
130             final ClientGenTask clientGen = new ClientGenTask();
131             // Set the classpath
132             final Project project = new Project();
133             project.setName( "clientgen" );
134             final Path path = new Path( project, WeblogicMojoUtilities
135                 .getDependencies( this.getArtifacts(), this.getPluginArtifacts() ) );
136             clientGen.setProject( project );
137             clientGen.setClasspath( path );
138             clientGen.setOverwrite( true );
139             clientGen.setVerbose( this.verbose );
140             clientGen.setDestdir( new File( this.outputDir ) );
141             clientGen.setPackageName( this.packageName );
142             clientGen.setIncludeGlobalTypes( this.useServerTypes );
143             clientGen.setJaxRPCWrappedArrayStyle( this.jaxRPCWrappedArrayStyle );
144             String wsdlUri;
145             if ( this.warFileName != null )
146             {
147                 if ( getLog().isInfoEnabled() )
148                 {
149                     getLog().info(
150                         " calculating wsdl URI from warFileName " + this.warFileName + " with wsdl " + this.inputWSDL );
151                 }
152                 wsdlUri = "jar:file:" + WeblogicMojoUtilities.getWarFileName( this.getArtifacts(), this.warFileName ) +
153                     "!" + this.inputWSDL;
154                 new File( this.inputWSDL ).toURI().toString();
155                 if ( getLog().isInfoEnabled() )
156                 {
157                     getLog().info( " using " + wsdlUri + " for clientgen." );
158                 }
159             }
160             else if ( this.inputWSDL.startsWith( "http" ) )
161             {
162                 if ( getLog().isInfoEnabled() )
163                 {
164                     getLog().info( " using " + this.inputWSDL + " for clientgen." );
165                 }
166                 wsdlUri = this.inputWSDL;
167             }
168             else
169             {
170                 wsdlUri = new File( this.inputWSDL ).toURI().toString();
171                 if ( getLog().isInfoEnabled() )
172                 {
173                     getLog().info( " using " + wsdlUri + " for clientgen." );
174                 }
175             }
176             clientGen.setWsdl( wsdlUri );
177             // set the service name if it is specified
178             if ( this.serviceName != null )
179             {
180                 if ( getLog().isInfoEnabled() )
181                 {
182                     getLog().info( " generating client for service '" + this.serviceName + "'." );
183                 }
184                 clientGen.setServiceName( this.serviceName );
185             }
186             clientGen.execute();
187         }
188         catch ( Exception ex )
189         {
190             getLog().error( "Exception encountered during client gen", ex );
191             throw new MojoExecutionException( "Exception encountered during listapps", ex );
192         }
193 
194         if ( getLog().isInfoEnabled() )
195         {
196             getLog().info( "Weblogic client gen successful " );
197         }
198     }
199 
200     /**
201      * Getter for property input WSDL.
202      *
203      * @return The value of input WSDL.
204      */
205     public String getInputWSDL()
206     {
207         return this.inputWSDL;
208     }
209 
210     /**
211      * Setter for the input WSDL.
212      *
213      * @param inInputWSDL The value of input WSDL.
214      */
215     public void setInputWSDL( final String inInputWSDL )
216     {
217         this.inputWSDL = inInputWSDL;
218     }
219 
220     /**
221      * Getter for property output dir.
222      *
223      * @return The value of output dir.
224      */
225     public String getOutputDir()
226     {
227         return this.outputDir;
228     }
229 
230     /**
231      * Setter for the output dir.
232      *
233      * @param inOutputDir The value of output dir.
234      */
235     public void setOutputDir( final String inOutputDir )
236     {
237         this.outputDir = inOutputDir;
238     }
239 
240     /**
241      * Getter for property package name.
242      *
243      * @return The value of package name.
244      */
245     public String getPackageName()
246     {
247         return this.packageName;
248     }
249 
250     /**
251      * Setter for the package name.
252      *
253      * @param inPackageName The value of package name.
254      */
255     public void setPackageName( String inPackageName )
256     {
257         this.packageName = inPackageName;
258     }
259 
260     /**
261      * Getter for property service name.
262      *
263      * @return The value of service name.
264      */
265     public String getServiceName()
266     {
267         return this.serviceName;
268     }
269 
270     /**
271      * Setter for the service name.
272      *
273      * @param inServiceName The value of service name.
274      */
275     public void setServiceName( final String inServiceName )
276     {
277         this.serviceName = inServiceName;
278     }
279 
280     /**
281      * toString method: creates a String representation of the object
282      *
283      * @return the String representation
284      */
285     public String toString()
286     {
287         StringBuffer buffer = new StringBuffer();
288         buffer.append( "ClientGen9Mojo[" );
289         buffer.append( "inputWSDL = " ).append( inputWSDL );
290         buffer.append( ", outputDir = " ).append( outputDir );
291         buffer.append( ", packageName = " ).append( packageName );
292         buffer.append( ", serviceName = " ).append( serviceName );
293         buffer.append( ", useServerTypes = " ).append( useServerTypes );
294         buffer.append( ", autotype = " ).append( autotype );
295         buffer.append( "]" );
296         return buffer.toString();
297     }
298 
299     /**
300      * Getter for server types
301      *
302      * @return true if the client gen should use server type information
303      */
304     public boolean isUseServerTypes()
305     {
306         return useServerTypes;
307     }
308 
309     /**
310      * Setter for server types
311      *
312      * @param useServerTypes - true if the client gen should use server types
313      */
314     public void setUseServerTypes( boolean useServerTypes )
315     {
316         this.useServerTypes = useServerTypes;
317     }
318 
319     /**
320      * Getter for verbose messages
321      *
322      * @return true if the client gen should use verbose output
323      */
324     public boolean isVerbose()
325     {
326         return this.verbose;
327     }
328 
329     /**
330      * Setter for verbose messages
331      *
332      * @param verbose - true of the clientgen should use verbose output
333      */
334     public void setVerbose( boolean verbose )
335     {
336         this.verbose = verbose;
337     }
338 
339 
340     /**
341      * Getter for autoType
342      *
343      * @return true if clientgen shoud autotype from the wsdl
344      */
345     public boolean isAutotype()
346     {
347         return this.autotype;
348     }
349 
350     /**
351      * Setter for autoType
352      *
353      * @param autotype - true if the client should autotype
354      */
355     public void setAutotype( boolean autotype )
356     {
357         this.autotype = autotype;
358     }
359 
360     /**
361      * Getter for warFileName
362      *
363      * @return the warFileName
364      */
365     public String getWarFileName()
366     {
367         return this.warFileName;
368     }
369 
370     /**
371      * Setter for warFileName
372      *
373      * @param warFileName - the warFileName to set
374      */
375     public void setWarFileName( String warFileName )
376     {
377         this.warFileName = warFileName;
378     }
379 
380     /**
381      * Getter for jaxRPCWrappedArrayStyle
382      *
383      * @return the jaxRPCWrappedArrayStyle
384      */
385     public boolean isJaxRPCWrappedArrayStyle()
386     {
387         return jaxRPCWrappedArrayStyle;
388     }
389 
390     /**
391      * Setter for jaxRPCWrappedArrayStyle
392      *
393      * @param jaxRPCWrappedArrayStyle the jaxRPCWrappedArrayStyle to set
394      */
395     public void setJaxRPCWrappedArrayStyle( boolean jaxRPCWrappedArrayStyle )
396     {
397         this.jaxRPCWrappedArrayStyle = jaxRPCWrappedArrayStyle;
398     }
399 }