View Javadoc
1   package org.codehaus.mojo.axistools.java2wsdl;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.project.MavenProject;
23  import org.apache.maven.project.MavenProjectHelper;
24  import org.codehaus.mojo.axistools.axis.AbstractAxisPlugin;
25  import org.codehaus.mojo.axistools.axis.AxisPluginException;
26  
27  import java.io.File;
28  import java.util.ArrayList;
29  import java.util.Collections;
30  import java.util.Iterator;
31  
32  /**
33   * @author jesse
34   */
35  public class DefaultJava2WSDLPlugin
36      extends AbstractAxisPlugin
37      implements Java2WSDLPlugin
38  {
39  
40      /**
41       * @parameter expression="${project.build.directory}/generated-sources/axistools/java2wsdl"
42       */
43      private File outputDirectory;
44  
45      /**
46       * @parameter expression="${fileName}"
47       * @required
48       */
49      private String filename;
50  
51      /**
52       * @parameter expression="${classOfPortType}"
53       */
54      private String classOfPortType;
55  
56      /**
57       * @parameter expression="${input}"
58       */
59      private String input;
60  
61      /**
62       * @parameter expression="${location}"
63       */
64      private String location;
65  
66      /**
67       * @parameter expression="${portTypeName}"
68       */
69      private String portTypeName;
70  
71      /**
72       * @parameter expression="${bindingName}"
73       */
74      private String bindingName;
75  
76      /**
77       * @parameter expression="${serviceElementName}"
78       */
79      private String serviceElementName;
80  
81      /**
82       * @parameter expression="${servicePortName}"
83       */
84      private String servicePortName;
85  
86      /**
87       * @parameter expression="${namespace}"
88       */
89      private String namespace;
90  
91      /**
92       * @parameter expression="${packageToNamespace}"
93       */
94      private String packageToNamespace;
95  
96      /**
97       * @parameter expression="${methods}"
98       */
99      private ArrayList methods;
100 
101     /**
102      * @parameter expression="false"
103      */
104     private boolean all;
105 
106     /**
107      * @parameter expression="${outputWSDLMode}"
108      */
109     private String outputWSDLMode;
110 
111     /**
112      * @parameter expression="${locationImport}"
113      */
114     private String locationImport;
115 
116     /**
117      * @parameter expression="${namespaceImpl}"
118      */
119     private String namespaceImpl;
120 
121     /**
122      * @parameter expression="${outputImpl}"
123      */
124     private String outputImpl;
125 
126     /**
127      * @parameter expression="${implClass}"
128      */
129     private String implClass;
130 
131     /**
132      * @parameter expression="${exclude}"
133      */
134     private ArrayList excludes;
135 
136     /**
137      * @parameter expression="${stopClasses}"
138      */
139     private ArrayList stopClasses;
140 
141     /**
142      * @parameter expression="${typeMappingVersion}"
143      */
144     private String typeMappingVersion;
145 
146     /**
147      * @parameter expression="${soapAction}"
148      */
149     private String soapAction;
150 
151     /**
152      * @parameter expression="${style}"
153      */
154     private String style;
155 
156     /**
157      * @parameter expression="${use}"
158      */
159     private String use;
160 
161     /**
162      * @parameter expression="${extraClasses}"
163      */
164     private ArrayList extraClasses;
165 
166     /**
167      * @parameter expression="${importSchema}"
168      */
169     private String importSchema;
170 
171     /**
172      * @parameter expression="${project}"
173      * @required
174      */
175     private MavenProject project;
176 
177     /**
178      * @component
179      */
180     private MavenProjectHelper projectHelper;
181     
182     /**
183      * Compile classpath for axis
184      */
185     private String classpath;
186 
187     public void execute()
188         throws AxisPluginException
189     {
190         if ( !outputDirectory.exists() )
191         {
192             outputDirectory.mkdirs();
193         }
194         try
195         {
196             Java2WSDLWrapper wrapper = new Java2WSDLWrapper();
197             wrapper.execute( generateArgumentList() );
198         }
199         catch ( Throwable t )
200         {
201             throw new AxisPluginException( "Java2WSDL execution failed", t );
202         }
203 
204         projectHelper.addResource( project, outputDirectory.getAbsolutePath(), Collections.singletonList( "**/*.wsdl" ),
205                                    Collections.EMPTY_LIST );
206     }
207 
208     /**
209      * generate the parameter String[] to be passed into the main method
210      *
211      * @return argument array for the invocation of {@link Java2WSDLWrapper}
212      */
213     private String[] generateArgumentList()
214         throws AxisPluginException
215     {
216         ArrayList argsList = new ArrayList();
217         argsList.add( "-o" );
218         argsList.add( outputDirectory.getAbsolutePath() + File.separator + filename );
219 
220         if ( input != null )
221         {
222             argsList.add( "-I" );
223             argsList.add( input );
224         }
225 
226         if ( location != null )
227         {
228             argsList.add( "-l" );
229             argsList.add( location );
230         }
231 
232         if ( portTypeName != null )
233         {
234             argsList.add( "-P" );
235             argsList.add( portTypeName );
236         }
237 
238         if ( bindingName != null )
239         {
240             argsList.add( "-b" );
241             argsList.add( bindingName );
242         }
243 
244         if ( serviceElementName != null )
245         {
246             argsList.add( "-S" );
247             argsList.add( serviceElementName );
248         }
249 
250         if ( servicePortName != null )
251         {
252             argsList.add( "-s" );
253             argsList.add( servicePortName );
254         }
255 
256         if ( namespace != null )
257         {
258             argsList.add( "-n" );
259             argsList.add( namespace );
260         }
261 
262         if ( packageToNamespace != null )
263         {
264             argsList.add( "-p" );
265             argsList.add( packageToNamespace );
266         }
267 
268         if ( methods != null && methods.size() > 0 )
269         {
270             argsList.add( "-m" );
271 
272             String methodList = "";
273             for ( Iterator i = methods.iterator(); i.hasNext(); )
274             {
275                 methodList += i.next() + " ";
276             }
277 
278             argsList.add( methodList );
279         }
280 
281         if ( all )
282         {
283             argsList.add( "-a" );
284         }
285 
286         if ( outputWSDLMode != null )
287         {
288             if ( "All".equalsIgnoreCase( outputWSDLMode ) || "Interface".equalsIgnoreCase( outputWSDLMode )
289                 || "Implementation".equalsIgnoreCase( outputWSDLMode ) )
290             {
291                 argsList.add( "-w" );
292                 argsList.add( outputWSDLMode );
293             }
294             else
295             {
296                 throw new AxisPluginException( "invalid outputWSDLMode setting" );
297             }
298         }
299 
300         if ( locationImport != null )
301         {
302             argsList.add( "-L" );
303             argsList.add( locationImport );
304         }
305 
306         if ( namespaceImpl != null )
307         {
308             argsList.add( "-N" );
309             argsList.add( namespaceImpl );
310         }
311 
312         if ( outputImpl != null )
313         {
314             argsList.add( "-O" );
315             argsList.add( outputImpl );
316         }
317 
318         if ( implClass != null )
319         {
320             argsList.add( "-i" );
321             argsList.add( implClass );
322         }
323 
324         if ( excludes != null && excludes.size() > 0 )
325         {
326             argsList.add( "-x" );
327 
328             for ( Iterator i = excludes.iterator(); i.hasNext(); )
329             {
330                 argsList.add( i.next() );
331             }
332         }
333 
334         if ( stopClasses != null && stopClasses.size() > 0 )
335         {
336             argsList.add( "-c" );
337 
338             for ( Iterator i = stopClasses.iterator(); i.hasNext(); )
339             {
340                 argsList.add( i.next() );
341             }
342         }
343 
344         if ( typeMappingVersion != null )
345         {
346             if ( "1.1".equals( typeMappingVersion ) || "1.2".equals( typeMappingVersion ) )
347             {
348                 argsList.add( "-T" );
349                 argsList.add( typeMappingVersion );
350             }
351             else
352             {
353                 throw new AxisPluginException( "invalid typeMappingVersion (1.1 or 1.2)" );
354             }
355         }
356 
357         if ( soapAction != null )
358         {
359             if ( "DEFAULT".equalsIgnoreCase( soapAction ) || "OPERATION".equalsIgnoreCase( soapAction )
360                 || "NONE".equalsIgnoreCase( soapAction ) )
361             {
362                 argsList.add( "-A" );
363                 argsList.add( soapAction.toUpperCase() );
364             }
365         }
366 
367         if ( style != null )
368         {
369             if ( "RPC".equalsIgnoreCase( style ) || "DOCUMENT".equalsIgnoreCase( style )
370                 || "WRAPPED".equalsIgnoreCase( style ) )
371             {
372                 argsList.add( "-y" );
373                 argsList.add( style.toUpperCase() );
374             }
375         }
376 
377         if ( use != null )
378         {
379             if ( "LITERAL".equalsIgnoreCase( use ) || "ENCODED".equalsIgnoreCase( use ) )
380             {
381                 argsList.add( "-u" );
382                 argsList.add( use.toUpperCase() );
383             }
384         }
385 
386         if ( extraClasses != null && extraClasses.size() > 0 )
387         {
388             for ( Iterator i = extraClasses.iterator(); i.hasNext(); )
389             {
390                 argsList.add( "-e" );
391                 argsList.add( i.next() );
392             }
393         }
394 
395         if ( importSchema != null )
396         {
397             argsList.add( "-C" );
398             argsList.add( importSchema );
399         }
400 
401         argsList.add( "--classpath" );
402         argsList.add( classpath );
403 
404         if ( classOfPortType != null )
405         {
406             if ( portTypeName == null )
407             {
408                 argsList.add( classOfPortType );
409             }
410             else
411             {
412                 throw new AxisPluginException(
413                     "invalid parameters, can not use portTypeName and classOfPortType together" );
414             }
415         }
416 
417         getLog().debug( "argslist: " + argsList.toString() );
418 
419         return (String[]) argsList.toArray( new String[argsList.size()] );
420     }
421 
422     public void setOutputDirectory( File outputDirectory )
423     {
424         this.outputDirectory = outputDirectory;
425     }
426 
427     public void setFilename( String filename )
428     {
429         this.filename = filename;
430     }
431 
432     public void setClassOfPortType( String classOfPortType )
433     {
434         this.classOfPortType = classOfPortType;
435     }
436 
437     public void setInput( String input )
438     {
439         this.input = input;
440     }
441 
442     public void setLocation( String location )
443     {
444         this.location = location;
445     }
446 
447     public void setPortTypeName( String portTypeName )
448     {
449         this.portTypeName = portTypeName;
450     }
451 
452     public void setBindingName( String bindingName )
453     {
454         this.bindingName = bindingName;
455     }
456 
457     public void setServiceElementName( String serviceElementName )
458     {
459         this.serviceElementName = serviceElementName;
460     }
461 
462     public void setServicePortName( String servicePortName )
463     {
464         this.servicePortName = servicePortName;
465     }
466 
467     public void setNamespace( String namespace )
468     {
469         this.namespace = namespace;
470     }
471 
472     public void setPackageToNamespace( String packageToNamespace )
473     {
474         this.packageToNamespace = packageToNamespace;
475     }
476 
477     public void setMethods( ArrayList methods )
478     {
479         this.methods = methods;
480     }
481 
482     public void setAll( boolean all )
483     {
484         this.all = all;
485     }
486 
487     public void setOutputWSDLMode( String outputWSDLMode )
488     {
489         this.outputWSDLMode = outputWSDLMode;
490     }
491 
492     public void setLocationImport( String locationImport )
493     {
494         this.locationImport = locationImport;
495     }
496 
497     public void setNamespaceImpl( String namespaceImpl )
498     {
499         this.namespaceImpl = namespaceImpl;
500     }
501 
502     public void setOutputImpl( String outputImpl )
503     {
504         this.outputImpl = outputImpl;
505     }
506 
507     public void setImplClass( String implClass )
508     {
509         this.implClass = implClass;
510     }
511 
512     public void setExcludes( ArrayList excludes )
513     {
514         this.excludes = excludes;
515     }
516 
517     public void setStopClasses( ArrayList stopClasses )
518     {
519         this.stopClasses = stopClasses;
520     }
521 
522     public void setTypeMappingVersion( String typeMappingVersion )
523     {
524         this.typeMappingVersion = typeMappingVersion;
525     }
526 
527     public void setSoapAction( String soapAction )
528     {
529         this.soapAction = soapAction;
530     }
531 
532     public void setStyle( String style )
533     {
534         this.style = style;
535     }
536 
537     public void setUse( String use )
538     {
539         this.use = use;
540     }
541 
542     public void setExtraClasses( ArrayList extraClasses )
543     {
544         this.extraClasses = extraClasses;
545     }
546 
547     public void setImportSchema( String importSchema )
548     {
549         this.importSchema = importSchema;
550     }
551 
552     public void setProject( MavenProject project )
553     {
554         this.project = project;
555     }
556 
557     public void setProjectHelper( MavenProjectHelper projectHelper )
558     {
559         this.projectHelper = projectHelper;
560     }
561     
562     public void setClasspath( String classpath )
563     {
564         this.classpath = classpath;
565     }
566 }