KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ant > jaxws > WSDLGenerator


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Emil Ong
27  */

28
29 package com.caucho.ant.jaxws;
30
31 import java.io.*;
32 import java.util.*;
33
34 import com.caucho.soap.reflect.WebServiceIntrospector;
35 import com.caucho.server.util.CauchoSystem;
36
37 /**
38  * Command-line tool and ant task to generate WSDLs from WebService
39  * annotated classes.
40  */

41 public class WSDLGenerator extends org.apache.tools.ant.Task {
42   private String JavaDoc _sei;
43   private String JavaDoc _destDir;
44   private String JavaDoc _classpath;
45   private String JavaDoc _resourceDestDir;
46   private String JavaDoc _sourceDestDir;
47   private boolean _keep;
48   private boolean _verbose;
49   private boolean _genWsdl;
50   private boolean _extension;
51   private boolean _debug; // undocumented in TCK
52
private boolean _fork;// undocumented in TCK
53
private String JavaDoc _protocol;
54   private String JavaDoc _serviceName;
55   private String JavaDoc _portName;
56
57   private static void error(String JavaDoc msg)
58   {
59     System.err.print(msg);
60     System.exit(1);
61   }
62
63   private static void error(String JavaDoc msg, Exception JavaDoc e)
64   {
65     System.err.print(msg + ":" );
66     e.printStackTrace();
67     System.exit(1);
68   }
69
70   public void setSei(String JavaDoc sei)
71   {
72     _sei = sei;
73   }
74
75   public void setDestdir(String JavaDoc destDir)
76   {
77     _destDir = destDir;
78   }
79
80   public void setClasspath(String JavaDoc classpath)
81   {
82     _classpath = classpath;
83   }
84
85   public void setCp(String JavaDoc classpath)
86   {
87     setClasspath(classpath);
88   }
89
90   public void addClasspath(ClassPath classPath)
91   {
92     _classpath = classPath.getPath();
93   }
94
95   public void setResourcedestdir(String JavaDoc resourceDestDir)
96   {
97     _resourceDestDir = resourceDestDir;
98   }
99
100   public void setSourcedestdir(String JavaDoc sourceDestDir)
101   {
102     _sourceDestDir = sourceDestDir;
103   }
104
105   public void setKeep(boolean keep)
106   {
107     _keep = keep;
108   }
109
110   public void setVerbose(boolean verbose)
111   {
112     _verbose = verbose;
113   }
114
115   public void setGenwsdl(boolean genWsdl)
116   {
117     _genWsdl = genWsdl;
118   }
119
120   public void setDebug(boolean debug)
121   {
122     _debug = debug;
123   }
124
125   public void setFork(boolean fork)
126   {
127     _fork = fork;
128   }
129
130   public void setProtocol(String JavaDoc protocol)
131   {
132     _protocol = protocol;
133   }
134
135   public void setServicename(String JavaDoc serviceName)
136   {
137     _serviceName = serviceName;
138   }
139
140   public void setPortname(String JavaDoc portName)
141   {
142     _portName = portName;
143   }
144   
145   public void setExtension(boolean extension)
146   {
147     _extension = extension;
148   }
149
150   /**
151    * Executes the ant task.
152    **/

153   public void execute()
154     throws org.apache.tools.ant.BuildException
155   {
156     Class JavaDoc seiClass = null;
157
158     try {
159       seiClass = CauchoSystem.loadClass(_sei);
160     }
161     catch (ClassNotFoundException JavaDoc e) {
162       throw new org.apache.tools.ant.BuildException(e);
163     }
164
165     WebServiceIntrospector introspector = new WebServiceIntrospector();
166     
167     try {
168       if (_resourceDestDir != null && ! "".equals(_resourceDestDir))
169         introspector.introspect(seiClass, "").dumpWSDL(_resourceDestDir);
170       else
171         introspector.introspect(seiClass, "").dumpWSDL(System.out);
172     }
173     catch (Exception JavaDoc e) {
174       throw new org.apache.tools.ant.BuildException(e);
175     }
176   }
177
178   public static void main(String JavaDoc[] args)
179   {
180     if (args.length < 1)
181       error("usage: wsdl-gen <SEI>");
182
183     WSDLGenerator generator = new WSDLGenerator();
184
185     generator.setSei(args[0]);
186
187     try {
188       generator.execute();
189     }
190     catch (org.apache.tools.ant.BuildException e) {
191       error("Unable to load SEI (" + args[0] + ")", e);
192     }
193   }
194
195   public static class ClassPath {
196     private List<PathElement> _pathElements = new ArrayList<PathElement>();
197     private String JavaDoc _path;
198
199     public String JavaDoc getPath()
200     {
201       return _path;
202     }
203
204     public void setPath(String JavaDoc path)
205     {
206       _path = path;
207     }
208
209     public List<PathElement> getPathElements()
210     {
211       return _pathElements;
212     }
213
214     public void addPathelement(PathElement pathElement)
215     {
216       _pathElements.add(pathElement);
217     }
218
219     public static class PathElement {
220       private String JavaDoc _path;
221
222       public String JavaDoc getPath()
223       {
224         return _path;
225       }
226
227       public void setPath(String JavaDoc path)
228       {
229         _path = path;
230       }
231     }
232   }
233 }
234
235
236
Popular Tags