1   /**
2    * Distribution License:
3    * JSword is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU Lesser General Public License, version 2.1 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU Lesser General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/lgpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2008
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: org.eclipse.jdt.ui.prefs 1178 2006-11-06 12:48:02Z dmsmith $
21   */
22  
23  package org.crosswire.common.options;
24  
25  /**
26   * An Option is representation of a single named parameter. An Option has a
27   * short, or a long name, or both.
28   * <p>
29   * It's inspiration was for command-line argument processing, but it can be used
30   * for any other purpose.
31   * </p>
32   * <ul>
33   * <li>An Option has a description, suitable for a usage statement.</li>
34   * <li>An Option's argument can be optional, required or unexpected. Default is
35   * NO_ARGUMENT.</li>
36   * <li>An Option can have an argument of a type. Default is DataType.BOOLEAN.</li>
37   * <li>An Option can have short name consisting of a single character.</li>
38   * <li>An Option can have a long name given by any string. What is allowed in
39   * the long name is dependent upon usage, but typically does not allow spaces.</li>
40   * <li>An Option can have a default value. Default is no default value.</li>
41   * </ul>
42   * 
43   * @see gnu.lgpl.License for license details.<br>
44   *      The copyright to this program is held by it's authors.
45   * @author DM Smith [dmsmith555 at yahoo dot com]
46   */
47  public class Option {
48      /**
49       * Create a BOOLEAN Option with a short name, having no default value.
50       * 
51       * @param description
52       *            the description
53       * @param shortName
54       *            the short name
55       */
56      public Option(String description, char shortName) {
57          this(description, ArgumentType.NO_ARGUMENT, DataType.BOOLEAN, shortName, null, null);
58      }
59  
60      /**
61       * Create a BOOLEAN Option with a long name, having no default value.
62       * 
63       * @param description
64       *            the description
65       * @param longName
66       *            the long name
67       */
68      public Option(String description, String longName) {
69          this(description, ArgumentType.NO_ARGUMENT, DataType.BOOLEAN, '\u0000', longName, null);
70      }
71  
72      /**
73       * Create a BOOLEAN Option with both short and long names, having no default
74       * value.
75       * 
76       * @param description
77       *            the description
78       * @param shortName
79       *            the short name
80       * @param longName
81       *            the long name
82       */
83      public Option(String description, char shortName, String longName) {
84          this(description, ArgumentType.NO_ARGUMENT, DataType.BOOLEAN, shortName, longName, null);
85      }
86  
87      /**
88       * Create an Option with both short and long names of a given DataType
89       * having a default value.
90       * 
91       * @param description
92       *            the description
93       * @param shortName
94       *            the short name
95       * @param longName
96       *            the long name
97       * @param defaultValue
98       *            the default value for this Option
99       */
100     public Option(String description, char shortName, String longName, String defaultValue) {
101         this(description, ArgumentType.NO_ARGUMENT, DataType.BOOLEAN, shortName, longName, defaultValue);
102     }
103 
104     /**
105      * Create an Option with a short name, having no default value.
106      * 
107      * @param description
108      *            the description
109      * @param argumentType
110      *            the type of the argument
111      * @param dataType
112      *            the type of argument's data
113      * @param shortName
114      *            the short name
115      */
116     public Option(String description, ArgumentType argumentType, DataType dataType, char shortName) {
117         this(description, argumentType, dataType, shortName, null, null);
118     }
119 
120     /**
121      * Create an Option with a long name, having no default value.
122      * 
123      * @param description
124      *            the description
125      * @param argumentType
126      *            the type of the argument
127      * @param dataType
128      *            the type of argument's data
129      * @param longName
130      *            the long name
131      */
132     public Option(String description, ArgumentType argumentType, DataType dataType, String longName) {
133         this(description, argumentType, dataType, '\u0000', longName, null);
134     }
135 
136     /**
137      * Create an Option with both short and long names, having no default value.
138      * 
139      * @param description
140      *            the description
141      * @param argumentType
142      *            the type of the argument
143      * @param dataType
144      *            the type of argument's data
145      * @param shortName
146      *            the short name
147      * @param longName
148      *            the long name
149      */
150     public Option(String description, ArgumentType argumentType, DataType dataType, char shortName, String longName) {
151         this(description, argumentType, dataType, shortName, longName, null);
152     }
153 
154     /**
155      * Create an Option with both short and long names of a given DataType
156      * having a default value.
157      * 
158      * @param description
159      *            the description
160      * @param argumentType
161      *            the type of the argument
162      * @param dataType
163      *            the type of argument's data
164      * @param shortName
165      *            the short name
166      * @param longName
167      *            the long name
168      * @param defaultValue
169      *            the default value for this Option
170      */
171     public Option(String description, ArgumentType argumentType, DataType dataType, char shortName, String longName, String defaultValue) {
172         this.description = description;
173         this.argumentType = argumentType;
174         this.dataType = dataType;
175         this.shortName = shortName;
176         this.longName = longName;
177         this.defaultValue = defaultValue;
178     }
179 
180     /**
181      * The description provides a brief explanation of the option.
182      * 
183      * @return the description
184      */
185     public String getDescription() {
186         return description;
187     }
188 
189     /**
190      * The short name of an Option is the single character by which this Option
191      * is known. If it is not set then there is no short name for this Option.
192      * 
193      * @return the shortName
194      */
195     public char getShortName() {
196         return shortName;
197     }
198 
199     /**
200      * The long name of an Option is the single character by which this Option
201      * is known. If it is not set then there is no long name for this Option.
202      * 
203      * @return the longName
204      */
205     public String getLongName() {
206         return longName;
207     }
208 
209     /**
210      * The ArgumentType indicates this Option's ability to use a following
211      * argument.
212      * 
213      * @return the argumentType
214      */
215     public ArgumentType getArgumentType() {
216         return argumentType;
217     }
218 
219     /**
220      * @return the dataType
221      */
222     public DataType getDataType() {
223         return dataType;
224     }
225 
226     /**
227      * @return the defaultValue
228      */
229     public String getDefaultValue() {
230         return defaultValue;
231     }
232 
233     private String description;
234     private char shortName;
235     private String longName;
236     private DataType dataType;
237     private ArgumentType argumentType;
238     private String defaultValue;
239 }
240