KickJava   Java API By Example, From Geeks To Geeks.

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


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: DocClassCmdOptions.java,v 1.4 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.FlagOption;
29 import org.enhydra.xml.xmlc.commands.options.Option;
30 import org.enhydra.xml.xmlc.commands.options.OptionSet;
31 import org.enhydra.xml.xmlc.metadata.DOMType;
32 import org.enhydra.xml.xmlc.metadata.DocumentClass;
33 import org.enhydra.xml.xmlc.metadata.GenerateType;
34 import org.enhydra.xml.xmlc.metadata.MetaData;
35
36 /**
37  * Command line options parsing document class options.
38  */

39 class DocClassCmdOptions extends BaseCmdOptions {
40     /**
41      * Class for the -implements option.
42      */

43     private class ImplementsOption extends Option {
44         /**
45          * Constructor.
46          */

47         public ImplementsOption() {
48             super("-implements", 1, true,
49                   "interface - Specify an interface the generate class will implement");
50         }
51
52         /**
53          * Parse an instance of the option.
54          */

55         protected void parse(String JavaDoc[] args,
56                              ErrorReporter errorReporter,
57                              Object JavaDoc clientData) throws XMLCException {
58             ((MetaData)clientData).getDocumentClass().addImplements(args[0]);
59         }
60     }
61
62     /**
63      * Class for the -generate option.
64      */

65     private class GenerateOption extends Option {
66         /**
67          * Constructor.
68          */

69         public GenerateOption() {
70             super("-generate", 1, true,
71                   "generate which - Specify type of class to generate (both, interface, implementation, class)");
72         }
73
74         /**
75          * Parse an instance of the option.
76          */

77         protected void parse(String JavaDoc[] args,
78                              ErrorReporter errorReporter,
79                              Object JavaDoc clientData) throws XMLCException {
80             GenerateType generate;
81             try {
82                 generate = GenerateType.getType(args[0]);
83             } catch (IllegalArgumentException JavaDoc except) {
84                 throw new XMLCException(except.getMessage(),
85                                         except);
86             }
87             ((MetaData)clientData).getDocumentClass().setGenerate(generate);
88         }
89     }
90
91     /**
92      * Class for the -class option.
93      */

94     private class ClassOption extends Option {
95         /**
96          * Constructor.
97          */

98         public ClassOption() {
99             super( "-class", 1, false,
100                    "class - Fully qualified class name for the generated class or interface.");
101         }
102
103         /**
104          * Parse an instance of the option.
105          */

106         protected void parse(String JavaDoc[] args,
107                              ErrorReporter errorReporter,
108                              Object JavaDoc clientData) throws XMLCException {
109             ((MetaData)clientData).getDocumentClass().setName(args[0]);
110         }
111     }
112
113     /**
114      * Class for the -extends option.
115      */

116     private class ExtendsOption extends Option {
117         /**
118          * Constructor.
119          */

120         public ExtendsOption() {
121             super("-extends", 1, false,
122                   "classname - Class the generated document extends");
123         }
124
125         /**
126          * Parse an instance of the option.
127          */

128         protected void parse(String JavaDoc[] args,
129                              ErrorReporter errorReporter,
130                              Object JavaDoc clientData) throws XMLCException {
131             ((MetaData)clientData).getDocumentClass().setExtends(args[0]);
132         }
133     }
134
135     /**
136      * Class for the -for-recomp option.
137      */

138     private class ForRecompOption extends FlagOption {
139         /**
140          * Constructor.
141          */

142         public ForRecompOption() {
143             super("-for-recomp",
144                   "Deprecated. No longer part of XMLC proper...too container (Enhydra3) specific. Use -for-deferred-parsing instead.");
145         }
146
147         /**
148          * Set value.
149          */

150         protected void set(Object JavaDoc clientData) throws XMLCException {
151             ((MetaData)clientData).getDocumentClass().setRecompilation(true);
152         }
153     }
154
155     /**
156      * Class for the -for-deferred-parsing option.
157      */

158     private class ForDeferredParsingOption extends FlagOption {
159         /**
160          * Constructor.
161          */

162         public ForDeferredParsingOption() {
163             super("-for-deferred-parsing",
164                   "Generate support for deferred parsing and automatic re-parsing of the actual document *ML.");
165         }
166
167         /**
168          * Set value.
169          */

170         protected void set(Object JavaDoc clientData) throws XMLCException {
171             ((MetaData)clientData).getDocumentClass().setDeferredParsing(true);
172         }
173     }
174
175     /**
176      * Class for the -domfactory option.
177      */

178     private class DOMFactoryOption extends Option {
179         /**
180          * Constructor.
181          */

182         public DOMFactoryOption() {
183             super("-domfactory", 1, false,
184                   "classname - XMLCDOMFactory class for creating DTD-specific documents");
185         }
186
187         /**
188          * Parse an instance of the option.
189          */

190         protected void parse(String JavaDoc[] args,
191                              ErrorReporter errorReporter,
192                              Object JavaDoc clientData) throws XMLCException {
193             DocumentClass docClass = ((MetaData)clientData).getDocumentClass();
194             if (docClass.getDom() != null) {
195                 throw new XMLCException("can't specify both -dom and -domfactory");
196             }
197             docClass.setDomFactory(args[0]);
198         }
199     }
200
201     /**
202      * Class for the -dom option.
203      */

204     private class DOMOption extends Option {
205         /**
206          * Constructor.
207          */

208         public DOMOption() {
209             super("-dom", 1, false,
210                   "dom - Specify one of a predefined set of DOM factories; one of `lazydom', `xerces', 'generic', 'xhtml', 'wml', 'voicexml', or 'chtml'");
211         }
212
213         /**
214          * Parse an instance of the option.
215          */

216         protected void parse(String JavaDoc[] args,
217                              ErrorReporter errorReporter,
218                              Object JavaDoc clientData) throws XMLCException {
219             DocumentClass docClass = ((MetaData)clientData).getDocumentClass();
220             if (docClass.getDomFactory() != null) {
221                 throw new XMLCException("can't specify both -dom and -domfactory");
222             }
223             docClass.setDom(DOMType.getType(args[0]));
224         }
225     }
226
227     /**
228      * Class for the -create-get-tag-methods option.
229      */

230     private class CreateGetTagMethods extends FlagOption {
231         /**
232          * Constructor.
233          */

234         public CreateGetTagMethods() {
235             super("-create-get-tag-methods",
236                   "name - getTagXXX() methods with generic return types");
237         }
238
239         /**
240          * Set value.
241          */

242         protected void set(Object JavaDoc clientData) throws XMLCException {
243             ((MetaData)clientData).getDocumentClass().setCreateGetTagMethods(true);
244         }
245     }
246
247     /**
248      * Constructor. Add options to option set.
249      */

250     public DocClassCmdOptions(OptionSet optionSet) {
251         super(optionSet);
252         optionSet.addOption(new ImplementsOption());
253         optionSet.addOption(new GenerateOption());
254         optionSet.addOption(new ClassOption());
255         optionSet.addOption(new ExtendsOption());
256         optionSet.addOption(new ForRecompOption());
257         optionSet.addOption(new ForDeferredParsingOption());
258         optionSet.addOption(new DOMFactoryOption());
259         optionSet.addOption(new DOMOption());
260         optionSet.addOption(new GenerateOption());
261         optionSet.addOption(new CreateGetTagMethods());
262     }
263 }
264
Popular Tags