KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > commands > options > OptionSet


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

23
24 package org.enhydra.xml.xmlc.commands.options;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 /**
31  * Class that contains a set of XMLC options.
32  *
33  * @see Option
34  * @see OptionsParser
35  */

36 public class OptionSet {
37     /**
38      * Ordered list of Option objects associated with this OptionSet.
39      */

40     private ArrayList JavaDoc optionList = new ArrayList JavaDoc();
41
42     /**
43      * Hash table of valid Option objects.
44      */

45     private HashMap JavaDoc options = new HashMap JavaDoc();
46
47     /**
48      * Add an option to the options set.
49      */

50     public void addOption(Option opt) {
51         optionList.add(opt);
52         options.put(opt.getName(), opt);
53     }
54
55     /**
56      * Get an enumeration of all options in the set.
57      */

58     public Iterator JavaDoc getOptions() {
59         return optionList.iterator();
60     }
61
62     /**
63      * Get displayable string of valid options for use in error messages.
64      */

65     public String JavaDoc getOptionsMsg() {
66         StringBuffer JavaDoc msg = new StringBuffer JavaDoc();
67         Iterator JavaDoc opts = getOptions();
68
69         while (opts.hasNext()) {
70             Option opt = (Option)opts.next();
71             msg.append(" ");
72             msg.append(opt.getHelp());
73             msg.append("\n");
74         }
75         return msg.toString();
76     }
77
78     /**
79      * Lookup an option.
80      *
81      * @param name The option name, including the leading `-'.
82      * @return The Option object or null if name is not found.
83      */

84     public Option findOption(String JavaDoc name) {
85         return (Option)options.get(name);
86     }
87 }
88
Popular Tags