KickJava   Java API By Example, From Geeks To Geeks.

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


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: XMLCOptionsParser.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 java.io.IOException JavaDoc;
27
28 import org.enhydra.xml.io.ErrorReporter;
29 import org.enhydra.xml.xmlc.XMLCException;
30 import org.enhydra.xml.xmlc.commands.options.OptionSet;
31 import org.enhydra.xml.xmlc.commands.options.OptionsParser;
32 import org.enhydra.xml.xmlc.metadata.CompileOptions;
33 import org.enhydra.xml.xmlc.metadata.MetaData;
34
35 /**
36  * Parser for xmlc command line options. Includes OptionSet that defines
37  * the options. Parses them into a MetaData object.
38  */

39 public class XMLCOptionsParser {
40     /**
41      * Usage message.
42      */

43     private static final String JavaDoc USAGE = "wrong # args: xmlc [options] [optfile.xmlc ...] src.ext";
44
45     /**
46      * Set of options.
47      */

48     private OptionSet optionSet = new OptionSet();
49
50     /**
51      * Constructor. Initializes all option objects.
52      */

53     public XMLCOptionsParser() {
54         new CompileOptsCmdOptions(optionSet);
55         new CompilerCmdOptions(optionSet);
56         new DOMEditCmdOptions(optionSet);
57         new DocClassCmdOptions(optionSet);
58         new HTMLCmdOptions(optionSet);
59         new ParserCmdOptions(optionSet);
60     }
61
62     /**
63      * Parse command line, returning the metadata object.
64      * @param errorReporter Use to report metadata parse errors.
65      */

66     public MetaData parse(String JavaDoc[] args,
67                           ErrorReporter errorReporter)
68         throws XMLCException, IOException JavaDoc {
69         OptionsParser optParser = new OptionsParser(optionSet,
70                                                     errorReporter);
71         optParser.parse(args);
72
73         MetaData metaData = optParser.getMetaData();
74         CompileOptions compileOptions = metaData.getCompileOptions();
75         String JavaDoc[] posArgs = optParser.getPositionalArgs();
76
77         // No filename is required if print version is specified, otherwise
78
// must have an input (although it is allowed with -version).
79
if (posArgs.length > 1) {
80             throw new XMLCException(USAGE);
81         } else if (posArgs.length == 0) {
82             if (!compileOptions.getPrintVersion()) {
83                 throw new XMLCException(USAGE);
84             }
85         } else {
86             metaData.getInputDocument().setUrl(posArgs[0]);
87             metaData.getDocument().completeModifications();
88         }
89         return metaData;
90     }
91
92 }
93
Popular Tags