KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > jaxrpc > WSCompileArguments


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.registry.jaxrpc;
21
22 import java.io.*;
23 import java.util.*;
24
25 import org.openide.util.NbBundle;
26
27 public class WSCompileArguments {
28     protected String JavaDoc additionalClasspath;
29     private List features = new ArrayList(); // List<String>
30

31     /** Holds value of property classpath. */
32     private String JavaDoc classpath;
33
34     /** Holds value of property outputDirectory. */
35     private String JavaDoc outputDirectory;
36
37     /** What sort of thing to generate: "client", "server", "both". */
38     private String JavaDoc gen;
39
40     /** Holds value of property keep. */
41     private boolean keep = true;
42     
43     /** Holds value of property nonclassOutputDirectory. */
44     private String JavaDoc nonclassOutputDirectory;
45     
46     /** Holds value of property sourceOutputDirectory. */
47     private String JavaDoc sourceOutputDirectory;
48     
49     /** Holds value of property define. */
50     private boolean define;
51     
52     /** Holds value of property importGen. */
53     private boolean importGen;
54     
55     /** Holds value of property verbose. */
56     private boolean verbose;
57
58     private String JavaDoc mappingFile;
59     
60     /** Holds value of property configuration. */
61     private Configuration configuration;
62
63     private List extraArguments = new LinkedList();
64
65     // The argument type needs no parameters.
66
public final static int TYPE_NEED_NO_PARAM = 0;
67     // The argument type needs parameters.
68
public final static int TYPE_NEED_PARAM = 1;
69     // The argument type is uncommon.
70
public final static int TYPE_INTERNAL = 0x010;
71     // The argument type will cause things to not compile.
72
public final static int TYPE_NON_COMPILE = 0x100;
73
74     /**
75      * The direct calling of this constructor is discouraged. Use
76      * JAXRPCFactory.getWSCompileArguments instead.
77      */

78     public WSCompileArguments() {
79     }
80
81     /**
82      * The direct calling of this constructor is discouraged. Use
83      * JAXRPCFactory.getWSCompileArguments instead.
84      */

85     public WSCompileArguments(String JavaDoc additionalClasspath) {
86         this.additionalClasspath = additionalClasspath;
87     }
88
89     public void addArgument(String JavaDoc arg) {
90         addArgument(arg, null);
91     }
92
93     /**
94      * Add an argument to the command line.
95      * @param arg the argument
96      * @param param any additional parameter to arg.
97      */

98     public void addArgument(String JavaDoc arg, String JavaDoc param) {
99         arg = arg.intern();
100         if (arg == "-gen")
101             setGen("");
102         else if (arg.startsWith("-gen:"))
103             setGen(arg.substring(5, arg.length()));
104         else if (arg == "-define")
105             setDefine(true);
106         else if (arg == "-import")
107             setImportGen(true);
108         else if (arg == "-classpath")
109             setClasspath(param);
110         else if (arg == "-d")
111             setOutputDirectory(param);
112         else if (arg == "-nd")
113             setNonclassOutputDirectory(param);
114         else if (arg == "-s")
115             setSourceOutputDirectory(param);
116         else if (arg == "-keep")
117             setKeep(true);
118         else if (arg == "-verbose")
119             setVerbose(true);
120         else if (arg == "-mapping")
121             setMapping(param);
122         else {
123             if (param == null)
124                 extraArguments.add(arg);
125             else
126                 extraArguments.add(arg+" "+param);
127         }
128     }
129     
130     public void addFeature(String JavaDoc feature) {
131         // Deal with mutually exclusive features by removing the old one.
132
if ("documentliteral".equals(feature)) {
133             features.remove("rpcliteral");
134         } else if ("rpcliteral".equals(feature)) {
135             features.remove("documentliteral");
136         } else if ("unwrap".equals(feature)) {
137             features.remove("donotunwrap");
138         } else if ("donotunwrap".equals(feature)) {
139             features.remove("unwrap");
140         }
141         features.add(feature);
142     }
143
144     public void removeFeature(String JavaDoc feature) {
145         features.remove(feature);
146     }
147
148     public boolean hasFeature(String JavaDoc feature) {
149         return features.contains(feature);
150     }
151     
152     public void setSearchSchemaForSubtypes() {
153         features.add("searchschema");
154     }
155     
156     public void setUseDataHandlerOnly() {
157         features.add("datahandleronly");
158     }
159     
160     public String JavaDoc[] toArgs() {
161         List args = new LinkedList();
162         
163         if (gen != null) {
164             if (define || importGen)
165                 throw new IllegalStateException JavaDoc(NbBundle.getMessage(WSCompileArguments.class, "MSG_MutuallyExclusiveGenDefineImport"));
166             if (gen.equals(""))
167                 args.add("-gen");
168             else {
169                 args.add("-gen:"+gen);
170             }
171         }
172         if (define) {
173             if (gen != null || importGen)
174                 throw new IllegalStateException JavaDoc(NbBundle.getMessage(WSCompileArguments.class, "MSG_MutuallyExclusiveGenDefineImport"));
175             args.add("-define");
176         }
177         if (importGen) {
178             if (gen != null || define)
179                 throw new IllegalStateException JavaDoc(NbBundle.getMessage(WSCompileArguments.class, "MSG_MutuallyExclusiveGenDefineImport"));
180             args.add("-import");
181         }
182         if (classpath != null) {
183             args.add("-classpath");
184             args.add(classpath);
185         }
186         if (mappingFile != null) {
187             args.add("-mapping");
188             args.add(mappingFile);
189         }
190         if (outputDirectory != null) {
191             args.add("-d");
192             args.add(outputDirectory);
193         }
194         if (nonclassOutputDirectory != null) {
195             args.add("-nd");
196             args.add(nonclassOutputDirectory);
197         }
198         if (sourceOutputDirectory != null) {
199             args.add("-s");
200             args.add(sourceOutputDirectory);
201         }
202         if (keep)
203             args.add("-keep");
204         if (verbose)
205             args.add("-verbose");
206         if (features.size() > 0) {
207             String JavaDoc featureArg = "-f:";
208             boolean first = true;
209             for (Iterator it = features.iterator(); it.hasNext(); ) {
210                 if (first)
211                     first = false;
212                 else
213                     featureArg += ",";
214                 featureArg += (String JavaDoc) it.next();
215             }
216             args.add(featureArg);
217         }
218         
219         if (configuration != null) {
220             try {
221                 File cf = File.createTempFile("jaxrpcconfigfile", ".xml");
222                 cf.deleteOnExit();
223                 OutputStream out = new FileOutputStream(cf);
224                 configuration.write(out);
225                 out.close();
226                 args.add(cf.getAbsolutePath());
227             } catch (IOException e) {
228                 throw new RuntimeException JavaDoc(e);
229             }
230         }
231         
232         String JavaDoc[] result = new String JavaDoc[args.size()];
233         return (String JavaDoc[]) args.toArray(result);
234     }
235     
236     /** Getter for property classpath.
237      * @return Value of property classpath.
238      *
239      */

240     public String JavaDoc getClasspath() {
241         return this.classpath;
242     }
243     
244     /** Setter for property classpath.
245      * @param classpath New value of property classpath.
246      *
247      */

248     public void setClasspath(String JavaDoc classpath) {
249         if (additionalClasspath == null)
250             this.classpath = classpath;
251         else
252             this.classpath = classpath + File.pathSeparator + additionalClasspath;
253     }
254
255     public String JavaDoc getMapping() {
256         return mappingFile;
257     }
258
259     public void setMapping(String JavaDoc m) {
260         mappingFile = m;
261     }
262     
263     /** Getter for property outputDirectory.
264      * @return Value of property outputDirectory.
265      *
266      */

267     public String JavaDoc getOutputDirectory() {
268         return this.outputDirectory;
269     }
270     
271     /** Setter for property outputDirectory.
272      * @param outputDirectory New value of property outputDirectory.
273      *
274      */

275     public void setOutputDirectory(String JavaDoc outputDirectory) {
276         this.outputDirectory = outputDirectory;
277     }
278
279     public void setOutputDirectory(File outputDirectory) {
280         this.outputDirectory = outputDirectory.getAbsolutePath();
281     }
282     
283     /** Getter for property gen.
284      * @return Value of property gen.
285      *
286      */

287     public String JavaDoc getGen() {
288         return this.gen;
289     }
290     
291     /** Setter for property gen.
292      * @param gen New value of property gen.
293      *
294      */

295     public void setGen(String JavaDoc gen) {
296         this.gen = gen;
297     }
298     
299     /** Getter for property keep.
300      * @return Value of property keep.
301      *
302      */

303     public boolean isKeep() {
304         return this.keep;
305     }
306     
307     /** Setter for property keep.
308      * @param keep New value of property keep.
309      *
310      */

311     public void setKeep(boolean keep) {
312         this.keep = keep;
313     }
314     
315     /** Getter for property nonclassOutputDirectory.
316      * @return Value of property nonclassOutputDirectory.
317      *
318      */

319     public String JavaDoc getNonclassOutputDirectory() {
320         return this.nonclassOutputDirectory;
321     }
322     
323     /** Setter for property nonclassOutputDirectory.
324      * @param nonclassOutputDirectory New value of property nonclassOutputDirectory.
325      *
326      */

327     public void setNonclassOutputDirectory(String JavaDoc nonclassOutputDirectory) {
328         this.nonclassOutputDirectory = nonclassOutputDirectory;
329     }
330     
331     /** Getter for property sourceOutputDirectory.
332      * @return Value of property sourceOutputDirectory.
333      *
334      */

335     public String JavaDoc getSourceOutputDirectory() {
336         return this.sourceOutputDirectory;
337     }
338     
339     /** Setter for property sourceOutputDirectory.
340      * @param sourceOutputDirectory New value of property sourceOutputDirectory.
341      *
342      */

343     public void setSourceOutputDirectory(String JavaDoc sourceOutputDirectory) {
344         this.sourceOutputDirectory = sourceOutputDirectory;
345     }
346     
347     /** Getter for property define.
348      * @return Value of property define.
349      *
350      */

351     public boolean isDefine() {
352         return this.define;
353     }
354     
355     /** Setter for property define.
356      * @param define New value of property define.
357      *
358      */

359     public void setDefine(boolean define) {
360         this.define = define;
361     }
362     
363     /** Getter for property importGen.
364      * @return Value of property importGen.
365      *
366      */

367     public boolean isImportGen() {
368         return this.importGen;
369     }
370     
371     /** Setter for property importGen.
372      * @param importGen New value of property importGen.
373      *
374      */

375     public void setImportGen(boolean importGen) {
376         this.importGen = importGen;
377     }
378     
379     /** Getter for property verbose.
380      * @return Value of property verbose.
381      *
382      */

383     public boolean isVerbose() {
384         return this.verbose;
385     }
386     
387     /** Setter for property verbose.
388      * @param verbose New value of property verbose.
389      *
390      */

391     public void setVerbose(boolean verbose) {
392         this.verbose = verbose;
393     }
394     
395     public String JavaDoc toString() {
396         String JavaDoc[] args = toArgs();
397         String JavaDoc result = "";
398         for (int i = 0; i < args.length; ++i) {
399             if (i > 0)
400                 result += " ";
401             result += args[i];
402         }
403         return result;
404     }
405     
406     /** Getter for property configuration.
407      * @return Value of property configuration.
408      *
409      */

410     public Configuration getConfiguration() {
411         return this.configuration;
412     }
413     
414     /** Setter for property configuration.
415      * @param configuration New value of property configuration.
416      *
417      */

418     public void setConfiguration(Configuration configuration) {
419         this.configuration = configuration;
420     }
421
422     /**
423      * Create a Configuration object (if not there already) and set the WSDL
424      * property.
425      */

426     public void prepConfigurationForWSDL(java.net.URL JavaDoc location, java.lang.String JavaDoc packageName) {
427         if (configuration == null)
428             configuration = new Configuration();
429         if (configuration.getWsdl() == null)
430             configuration.setWsdl(new WsdlType(location, packageName));
431         else {
432             configuration.getWsdl().setLocation(location);
433             configuration.getWsdl().setPackageName(packageName);
434         }
435     }
436 }
437
Popular Tags