KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > framework > ValidOption


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.cli.framework;
25
26
27 import java.util.Vector JavaDoc;
28 import java.io.Serializable JavaDoc;
29
30 /**
31  * Definition for the valid option
32  * @version $Revision: 1.3 $
33  */

34 public class ValidOption implements Serializable JavaDoc
35 {
36
37     // name of the option
38
private String JavaDoc name;
39     // short name for the option
40
private Vector JavaDoc shortNames = new Vector JavaDoc();
41     // type of the option
42
private String JavaDoc type;
43     // is the value required for this option
44
private int required;
45     // default value for this option
46
private String JavaDoc defaultValue = null;
47     // corresponding deprecated option if any
48
private String JavaDoc deprecatedOption = null;
49
50     // option value is required
51
public static final int REQUIRED = 1;
52     // option value is optional
53
public static final int OPTIONAL = 2;
54     // option value is not required
55
public static final int NOT_REQUIRED = 3;
56     
57     
58     /** Creates new ValidOption */
59     public ValidOption()
60     {
61     }
62
63     
64     /**
65      Overloaded constructor for ValidOption
66      @param name the name of the option
67      @param type the datatype of this option
68      @param required specifies if the value for this option is required or optional
69      @param defaultValue the default value for this option if nonce specified on command line
70      */

71     public ValidOption(String JavaDoc name, String JavaDoc type, int required,
72                         String JavaDoc defaultValue )
73     {
74         this.name = name;
75         this.type = type;
76         this.required = required;
77         this.defaultValue = defaultValue;
78     }
79
80     
81     /** copy constructor for ValidOption
82         @param vo
83     */

84     public ValidOption(ValidOption vo)
85     {
86         this.name = vo.name;
87         this.shortNames = vo.shortNames;
88         this.type = vo.type;
89         this.required = vo.required;
90         this.defaultValue = vo.defaultValue;
91         this.deprecatedOption = vo.deprecatedOption;
92     }
93     
94
95     
96     /**
97      Gets the name of the option
98      @return the name of the option
99      */

100     public String JavaDoc getName()
101     {
102         return name;
103     }
104     
105     
106     /**
107      Sets the name of the option
108      @param name name of the option to set
109      */

110     public void setName(String JavaDoc name)
111     {
112         this.name = name;
113     }
114     
115     
116     /**
117      Returns the short name of the option
118      @return the short name
119      */

120     public Vector JavaDoc getShortNames()
121     {
122         return shortNames;
123     }
124     
125     
126     /**
127      Sets the short option name
128      @param shortName short name to set
129      */

130     public void setShortName(String JavaDoc shortName)
131     {
132         this.shortNames.add(shortName);
133     }
134     
135     
136     /**
137      Sets the short option names
138      @param shortNames short names to set
139      */

140     public void setShortNames(Vector JavaDoc shortNames)
141     {
142         this.shortNames.addAll(shortNames);
143     }
144     
145     
146     /**
147      Returns the type of the option value
148      @return the type
149      */

150     public String JavaDoc getType()
151     {
152         return type;
153     }
154     
155     
156     /**
157      Sets the type of the option value
158      @param type the type to set
159      */

160     public void setType(String JavaDoc type)
161     {
162         this.type = type;
163     }
164     
165     
166     /**
167      Checks to see if the value is required
168      @return the value required
169      */

170     public int isValueRequired()
171     {
172         return required;
173     }
174     
175     
176     /**
177      Sets the required field of the option
178      @param isValueRequired the value to set
179      */

180     public void setRequired(int isValueRequired)
181     {
182         required = isValueRequired;
183     }
184     
185     
186     /**
187      Returns the default value of the option
188      @return the default value
189      */

190     public String JavaDoc getDefaultValue()
191     {
192         return defaultValue;
193     }
194     
195     
196     /**
197      Sets the default value of the option
198      @param defaultValue the default value to set
199      */

200     public void setDefaultValue(String JavaDoc defaultValue)
201     {
202         this.defaultValue = defaultValue;
203     }
204     
205     
206     /**
207      Returns the deprecated option
208      @return the deprecated option
209      */

210     public String JavaDoc getDeprecatedOption()
211     {
212         return deprecatedOption;
213     }
214     
215     
216     /**
217      Sets the deprecated option
218      @param deprecatedOption option value
219      */

220     public void setDeprecatedOption(String JavaDoc deprecatedOption)
221     {
222         this.deprecatedOption = deprecatedOption;
223     }
224     
225     
226     /**
227      Checks to see if there is a default value for this option
228      @return if there is a default value
229      */

230     public boolean hasDefaultValue()
231     {
232         return (defaultValue != null);
233     }
234     
235     
236     /**
237      Checks to see if there is a short option name for this option
238      @return if there is a short option name
239      */

240     public boolean hasShortName()
241     {
242         if (shortNames.size() > 0)
243         {
244             return true;
245         }
246         return false;
247     }
248
249     
250     /**
251      Checks to see if there is a default value for this option
252      @return if there is a default value
253      */

254     public boolean hasDeprecatedOption()
255     {
256         return (deprecatedOption != null);
257     }
258     
259     
260     /**
261      converts the object to string
262       returns toString() of this object
263      */

264     public String JavaDoc toString()
265     {
266         String JavaDoc shortNamesStr = "";
267         
268         for (int i = 0; i < shortNames.size(); i++)
269         {
270             shortNamesStr += shortNames.get(i) + ",";
271         }
272         return (name + " " + type + " " + shortNamesStr + " " + defaultValue);
273     }
274 }
275
Popular Tags