KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > commands > xmlc > CompilerCmdOptions


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: CompilerCmdOptions.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.commands.xmlc;
25
26 import org.enhydra.xml.io.ErrorReporter;
27 import org.enhydra.xml.xmlc.XMLCException;
28 import org.enhydra.xml.xmlc.commands.options.Option;
29 import org.enhydra.xml.xmlc.commands.options.OptionSet;
30 import org.enhydra.xml.xmlc.metadata.JavacOption;
31 import org.enhydra.xml.xmlc.metadata.MetaData;
32
33 /**
34  * Command line options parsing for Java compiler-related options.
35  */

36 class CompilerCmdOptions extends BaseCmdOptions {
37     /**
38      * Class for the -d option.
39      */

40     private class DestDirOption extends Option {
41         /**
42          * Constructor.
43          */

44         public DestDirOption() {
45             super("-d", 1, false,
46                   "dir - Destintation directory, passed to javac");
47         }
48
49         /**
50          * Parse an instance of the option.
51          */

52         protected void parse(String JavaDoc[] args,
53                              ErrorReporter errorReporter,
54                              Object JavaDoc clientData) throws XMLCException {
55             ((MetaData)clientData).getCompileOptions().setClassOutputRoot(args[0]);
56         }
57     }
58
59     /**
60      * Class for directly supported javac flag or option.
61      */

62     private class JavacStdArg extends Option {
63         /**
64          * Constructor.
65          */

66         public JavacStdArg(String JavaDoc option, int numArgs, String JavaDoc optHelp) {
67             super(option, numArgs, false, optHelp);
68         }
69
70         /**
71          * Parse an instance of the option.
72          */

73         protected void parse(String JavaDoc[] args,
74                              ErrorReporter errorReporter,
75                              Object JavaDoc clientData) throws XMLCException {
76             JavacOption javacOption = ((MetaData)clientData).getJavaCompilerSection().addJavacOption();
77             javacOption.setName(getName());
78             if (args.length > 0) {
79                 javacOption.setValue(args[0]);
80             }
81         }
82     }
83
84     /**
85      * Class for arbitrary javac flag or option.
86      */

87     private class JavacArbitraryArg extends Option {
88         /**
89          * Constructor.
90          */

91         public JavacArbitraryArg(String JavaDoc option, int numArgs, String JavaDoc optHelp) {
92             super(option, numArgs, true, optHelp);
93         }
94
95         /**
96          * Parse an instance of the option.
97          */

98         protected void parse(String JavaDoc[] args,
99                              ErrorReporter errorReporter,
100                              Object JavaDoc clientData) throws XMLCException {
101             JavacOption javacOption = ((MetaData)clientData).getJavaCompilerSection().addJavacOption();
102             javacOption.setName(args[0]);
103             if (args.length > 1) {
104                 javacOption.setValue(args[1]);
105             }
106         }
107     }
108
109     /**
110      * Class for the javac program option.
111      */

112     private class JavacProgOption extends Option {
113         /**
114          * Constructor.
115          */

116         public JavacProgOption() {
117             super("-javac", 1, false,
118                   "prog - Specify the java compiler to use.");
119         }
120
121         /**
122          * Parse an instance of the option.
123          */

124         protected void parse(String JavaDoc[] args,
125                              ErrorReporter errorReporter,
126                              Object JavaDoc clientData) throws XMLCException {
127             ((MetaData)clientData).getJavaCompilerSection().setJavac(args[0]);
128         }
129     }
130
131     /**
132      * Constructor. Add options to option set.
133      */

134     public CompilerCmdOptions(OptionSet optionSet) {
135         super(optionSet);
136         optionSet.addOption(new DestDirOption());
137         optionSet.addOption(new JavacStdArg("-g", 0,
138                                             "- Passed to javac"));
139         optionSet.addOption(new JavacStdArg("-O", 0,
140                                             "- Passed to javac"));
141         optionSet.addOption(new JavacStdArg("-classpath", 1,
142                                             "path - Passed to javac"));
143         optionSet.addOption(new JavacArbitraryArg("-javacflag", 1,
144                                                   "flag - Aribitrary flag to pass to the javac program; including leading `-' or `+' character"));
145         optionSet.addOption(new JavacArbitraryArg("-javacopt", 2,
146                                                   "opt value - Aribitrary option and value to pass to the javac program; including leading `-' or `+' character"));
147         optionSet.addOption(new JavacProgOption());
148     }
149 }
150
Popular Tags