KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > metadata > CompileOptions


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: CompileOptions.java,v 1.3 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.metadata;
25
26 import java.io.File JavaDoc;
27
28 import org.enhydra.xml.xmlc.XMLCException;
29 import org.enhydra.xml.xmlc.codegen.JavaLang;
30 import org.w3c.dom.Document JavaDoc;
31
32 /**
33  * Specifies options for the document compiler.
34  */

35 public class CompileOptions extends MetaDataElement {
36     /**
37      * Element name.
38      */

39     public static final String JavaDoc TAG_NAME = "compileOptions";
40
41     /**
42      * Attribute names.
43      */

44     private static final String JavaDoc VERBOSE_ATTR = "verbose";
45     private static final String JavaDoc PRINT_VERSION_ATTR = "printVersion";
46     private static final String JavaDoc PRINT_DOCUMENT_INFO_ATTR = "printDocumentInfo";
47     private static final String JavaDoc PRINT_PARSE_INFO_ATTR = "printParseInfo";
48     private static final String JavaDoc PRINT_DOM_ATTR = "printDOM";
49     private static final String JavaDoc PRINT_ACCESSOR_INFO_ATTR = "printAccessorInfo";
50     private static final String JavaDoc KEEP_GENERATED_SOURCE_ATTR = "keepGeneratedSource";
51     private static final String JavaDoc CREATE_SOURCE_ATTR = "createSource";
52     private static final String JavaDoc COMPILE_SOURCE_ATTR = "compileSource";
53     private static final String JavaDoc SOURCE_OUTPUT_ROOT_ATTR = "sourceOutputRoot";
54     private static final String JavaDoc CLASS_OUTPUT_ROOT_ATTR = "classOutputRoot";
55     private static final String JavaDoc DOCUMENT_OUTPUT_ATTR = "documentOutput";
56     private static final String JavaDoc WARNINGS_ATTR = "warnings";
57
58     /**
59      * Deprecated attributes that have been moved to the InputDocument
60      * object. If a file is parsed that has these options, their values
61      * are moved to the InputDocument object.
62      */

63     private static final String JavaDoc INPUT_DOCUMENT_ATTR = "inputDocument";
64     private static final String JavaDoc PROCESS_SSI_ATTR = "processSSI";
65     private static final String JavaDoc DOCUMENT_FORMAT_ATTR = "documentFormat";
66
67     /**
68      * Constructor.
69      */

70     public CompileOptions(Document JavaDoc ownerDoc) {
71         super(ownerDoc, TAG_NAME);
72     }
73
74     /**
75      * Get the verbose attribute.
76      */

77     public boolean getVerbose() {
78         return getBooleanAttribute(VERBOSE_ATTR);
79     }
80
81     /**
82      * Set the verbose attribute.
83      */

84     public void setVerbose(boolean value) {
85         setBooleanAttribute(VERBOSE_ATTR, value);
86     }
87
88     /**
89      * Get the printVersion attribute.
90      */

91     public boolean getPrintVersion() {
92         return getBooleanAttribute(PRINT_VERSION_ATTR);
93     }
94
95     /**
96      * Set the printVersion attribute.
97      */

98     public void setPrintVersion(boolean value) {
99         setBooleanAttribute(PRINT_VERSION_ATTR, value);
100     }
101
102     /**
103      * Get the printDocumentInfo attribute.
104      */

105     public boolean getPrintDocumentInfo() {
106         return getBooleanAttribute(PRINT_DOCUMENT_INFO_ATTR);
107     }
108
109     /**
110      * Set the printDocumentInfo attribute.
111      */

112     public void setPrintDocumentInfo(boolean value) {
113         setBooleanAttribute(PRINT_DOCUMENT_INFO_ATTR, value);
114     }
115
116     /**
117      * Get the printParseInfo attribute.
118      */

119     public boolean getPrintParseInfo() {
120         return getBooleanAttribute(PRINT_PARSE_INFO_ATTR);
121     }
122
123     /**
124      * Set the printParseInfo attribute.
125      */

126     public void setPrintParseInfo(boolean value) {
127         setBooleanAttribute(PRINT_PARSE_INFO_ATTR, value);
128     }
129
130     /**
131      * Get the printDOM attribute.
132      */

133     public boolean getPrintDOM() {
134         return getBooleanAttribute(PRINT_DOM_ATTR);
135     }
136
137     /**
138      * Set the printDOM attribute.
139      */

140     public void setPrintDOM(boolean value) {
141         setBooleanAttribute(PRINT_DOM_ATTR, value);
142     }
143
144     /**
145      * Get the printAccessorInfo attribute.
146      */

147     public boolean getPrintAccessorInfo() {
148         return getBooleanAttribute(PRINT_ACCESSOR_INFO_ATTR);
149     }
150
151     /**
152      * Set the printAccessorInfo attribute.
153      */

154     public void setPrintAccessorInfo(boolean value) {
155         setBooleanAttribute(PRINT_ACCESSOR_INFO_ATTR, value);
156     }
157
158     /**
159      * Get the keepGeneratedSource attribute.
160      */

161     public boolean getKeepGeneratedSource() {
162         return getBooleanAttribute(KEEP_GENERATED_SOURCE_ATTR);
163     }
164
165     /**
166      * Set the keepGeneratedSource attribute.
167      */

168     public void setKeepGeneratedSource(boolean value) {
169         setBooleanAttribute(KEEP_GENERATED_SOURCE_ATTR, value);
170     }
171
172     /**
173      * Get the compileSource attribute or the default value if not specified.
174      * The default for this attribute is true.
175      */

176     public boolean getCompileSource() {
177         return getBooleanAttribute(COMPILE_SOURCE_ATTR, true);
178     }
179
180     /**
181      * Set the compileSource attribute.
182      */

183     public void setCompileSource(boolean value) {
184         setBooleanAttribute(COMPILE_SOURCE_ATTR, value, true);
185     }
186
187     /**
188      * Determine if the compileSource attribute is specified.
189      */

190     public boolean isCompileSourceSpecified() {
191         return isAttributeSpecified(COMPILE_SOURCE_ATTR);
192     }
193
194     /**
195      * Get the createSource attribute or the default value if not specified.
196      * The default for this attribute is true.
197      */

198     public boolean getCreateSource() {
199         return getBooleanAttribute(CREATE_SOURCE_ATTR, true);
200     }
201
202     /**
203      * Set the createSource attribute.
204      */

205     public void setCreateSource(boolean value) {
206         setBooleanAttribute(CREATE_SOURCE_ATTR, value, true);
207     }
208
209     /**
210      * Determine if the createSource attribute is specified.
211      */

212     public boolean isCreateSourceSpecified() {
213         return isAttributeSpecified(CREATE_SOURCE_ATTR);
214     }
215
216     /**
217      * Get the sourceOutputRoot attribute.
218      */

219     public String JavaDoc getSourceOutputRoot() {
220         return getAttributeNull(SOURCE_OUTPUT_ROOT_ATTR);
221     }
222
223     /**
224      * Set the sourceOutputRoot attribute.
225      */

226     public void setSourceOutputRoot(String JavaDoc value) {
227         setRemoveAttribute(SOURCE_OUTPUT_ROOT_ATTR, value);
228     }
229
230     /**
231      * Get the classOutputRoot attribute.
232      */

233     public String JavaDoc getClassOutputRoot() {
234         return getAttributeNull(CLASS_OUTPUT_ROOT_ATTR);
235     }
236
237     /**
238      * Set the classOutputRoot attribute.
239      */

240     public void setClassOutputRoot(String JavaDoc value) {
241         setRemoveAttribute(CLASS_OUTPUT_ROOT_ATTR, value);
242     }
243
244     /**
245      * Get the package output directory, obtained from the classOutputRoot
246      * attribute and package name. Null if returned classOutputRoot is not
247      * specified.
248      */

249     public File JavaDoc getPackageOutputDir() {
250         String JavaDoc outputRoot = getClassOutputRoot();
251         if (outputRoot == null) {
252         outputRoot = getSourceOutputRoot();
253         if (outputRoot == null) {
254         return null;
255         }
256         }
257         String JavaDoc packageName = getMetaData().getDocumentClass().getPackageName();
258         return new File JavaDoc(new File JavaDoc(outputRoot),
259                         JavaLang.packageNameToFileName(packageName));
260     }
261
262     /**
263      * Get the documentOutput attribute.
264      */

265     public String JavaDoc getDocumentOutput() {
266         return getAttributeNull(DOCUMENT_OUTPUT_ATTR);
267     }
268
269     /**
270      * Set the documentOutput attribute.
271      */

272     public void setDocumentOutput(String JavaDoc value) {
273         setRemoveAttribute(DOCUMENT_OUTPUT_ATTR, value);
274     }
275
276     /**
277      * Get the parser warning flag. Returns null if not specified.
278      */

279     public boolean getWarnings() {
280         return getBooleanAttribute(WARNINGS_ATTR, true);
281     }
282
283     /**
284      * Set the document validation flag.
285      */

286     public void setWarnings(boolean warnings) {
287         setBooleanAttribute(WARNINGS_ATTR, warnings, true);
288     }
289
290     /**
291      * Move deprecated attributes to InputDocument.
292      */

293     private void moveToInputDocument() {
294        InputDocument inputDoc = getMetaData().getInputDocument();
295        String JavaDoc value = getAttributeNull(INPUT_DOCUMENT_ATTR);
296        if (value != null) {
297            inputDoc.setUrl(value);
298            removeAttribute(INPUT_DOCUMENT_ATTR);
299        }
300        if (isAttributeSpecified(PROCESS_SSI_ATTR)) {
301            inputDoc.setProcessSSI(getBooleanAttribute(PROCESS_SSI_ATTR));
302            removeAttribute(PROCESS_SSI_ATTR);
303        }
304        value = getAttributeNull(DOCUMENT_FORMAT_ATTR);
305        if (value != null) {
306            inputDoc.setDocumentFormat(DocumentFormat.getType(value));
307            removeAttribute(DOCUMENT_FORMAT_ATTR);
308        }
309     }
310
311     /**
312      * Complete modifications to DOM. Move d
313      */

314     protected void completeModifications() throws XMLCException {
315         if (isAttributeSpecified(INPUT_DOCUMENT_ATTR)
316             || isAttributeSpecified(PROCESS_SSI_ATTR)
317             || isAttributeSpecified(DOCUMENT_FORMAT_ATTR)) {
318             moveToInputDocument();
319         }
320     }
321
322     /**
323      * Get the inputDocument attribute.
324      * @deprecated use InputDocument#getUrl()
325      * @see InputDocument#getUrl()
326      */

327     public String JavaDoc getInputDocument() {
328         return getMetaData().getInputDocument().getUrl();
329     }
330
331     /**
332      * Set the inputDocument attribute.
333      * @deprecated use InputDocument#setUrl(String)
334      * @see InputDocument#setUrl(String)
335      */

336     public void setInputDocument(String JavaDoc value) {
337         getMetaData().getInputDocument().setUrl(value);
338     }
339 }
340
Popular Tags