1 | package jp.co.orkney.restlet.util; |
---|
2 | |
---|
3 | import org.jdom.Element; |
---|
4 | |
---|
5 | /** |
---|
6 | * Copyright (c) 2007 Orkney, Inc. <http://www.orkney.co.jp/> |
---|
7 | * |
---|
8 | * This program is free software: you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation, either version 3 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | */ |
---|
21 | |
---|
22 | /** |
---|
23 | * <b>Parameter is a class which represents a parameter.</b> |
---|
24 | * <p> |
---|
25 | * A parameter is characterized by the following information: |
---|
26 | * <ul> |
---|
27 | * <li>A name</li> |
---|
28 | * <li>A type (integer,text,boolean, ...)</li> |
---|
29 | * <li>A code name (used in GET and POST request)</li> |
---|
30 | * <li>A boolean determining whether this parameter is required for its parent |
---|
31 | * service.</li> |
---|
32 | * <li>A default value</li> |
---|
33 | * <li>A current value</li> |
---|
34 | * </ul> |
---|
35 | * </p> |
---|
36 | * |
---|
37 | * @author Matthieu Bilbille - Orkney Inc. |
---|
38 | * @version 1.0 |
---|
39 | */ |
---|
40 | public class Parameter |
---|
41 | { |
---|
42 | private String name; |
---|
43 | |
---|
44 | private String type; |
---|
45 | |
---|
46 | private String codeName; |
---|
47 | |
---|
48 | private boolean isRequired; |
---|
49 | |
---|
50 | private String defaultValue; |
---|
51 | |
---|
52 | private String value; |
---|
53 | |
---|
54 | /** |
---|
55 | * Constructor Parameter. |
---|
56 | * <p> |
---|
57 | * Creates a new parameter with empty data (name,type,...); "isRequired" |
---|
58 | * is initialized with FALSE value |
---|
59 | * </p> |
---|
60 | */ |
---|
61 | public Parameter() |
---|
62 | { |
---|
63 | name = ""; |
---|
64 | type = ""; |
---|
65 | codeName = ""; |
---|
66 | isRequired = false; |
---|
67 | defaultValue = ""; |
---|
68 | value = ""; |
---|
69 | } |
---|
70 | |
---|
71 | public Parameter(Element parameter) |
---|
72 | { |
---|
73 | this.name = parameter.getAttributeValue("name"); |
---|
74 | this.type = parameter.getAttributeValue("type"); |
---|
75 | this.codeName = parameter.getAttributeValue("codename"); |
---|
76 | this.isRequired = new Boolean(parameter.getAttributeValue("required")); |
---|
77 | this.defaultValue = parameter.getAttributeValue("default"); |
---|
78 | this.value = parameter.getAttributeValue("default"); |
---|
79 | } |
---|
80 | |
---|
81 | /** |
---|
82 | * Constructor Parameter. |
---|
83 | * <p> |
---|
84 | * Creates a new parameter with the specified data (name,type,...). The |
---|
85 | * value of the parameter is initialized with its default value |
---|
86 | * </p> |
---|
87 | * |
---|
88 | * @param name |
---|
89 | * parameter name |
---|
90 | * @param type |
---|
91 | * parameter type |
---|
92 | * @param codeName |
---|
93 | * parameter codeName |
---|
94 | * @param isRequired |
---|
95 | * boolean determining whether this parameter is required |
---|
96 | * for its parent service. |
---|
97 | * @param defaultValue |
---|
98 | * parameter default value |
---|
99 | */ |
---|
100 | public Parameter(String name, String type, String codeName, |
---|
101 | boolean isRequired, String defaultValue) |
---|
102 | { |
---|
103 | this.name = name; |
---|
104 | this.type = type; |
---|
105 | this.codeName = codeName; |
---|
106 | this.isRequired = isRequired; |
---|
107 | this.defaultValue = defaultValue; |
---|
108 | this.value = defaultValue; |
---|
109 | } |
---|
110 | |
---|
111 | /** |
---|
112 | * Gets the value of the parameter |
---|
113 | * |
---|
114 | * @return this parameter's value |
---|
115 | */ |
---|
116 | public String getValue() |
---|
117 | { |
---|
118 | return value; |
---|
119 | } |
---|
120 | |
---|
121 | /** |
---|
122 | * Sets the value of the parameter to the specified string. |
---|
123 | * |
---|
124 | * @param value |
---|
125 | * the string that is to be this parameter's value |
---|
126 | */ |
---|
127 | public void setValue(String value) |
---|
128 | { |
---|
129 | this.value = value; |
---|
130 | } |
---|
131 | |
---|
132 | /** |
---|
133 | * Gets the name of the parameter |
---|
134 | * |
---|
135 | * @return this parameter's name |
---|
136 | */ |
---|
137 | public String getName() |
---|
138 | { |
---|
139 | return name; |
---|
140 | } |
---|
141 | |
---|
142 | /** |
---|
143 | * Sets the name of the parameter to the specified string. |
---|
144 | * |
---|
145 | * @param name |
---|
146 | * the string that is to be this parameter's name |
---|
147 | */ |
---|
148 | public void setName(String name) |
---|
149 | { |
---|
150 | this.name = name; |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | * Gets the type of the parameter |
---|
155 | * |
---|
156 | * @return this parameter's name |
---|
157 | */ |
---|
158 | public String getType() |
---|
159 | { |
---|
160 | return type; |
---|
161 | } |
---|
162 | |
---|
163 | /** |
---|
164 | * Sets the type of the parameter to the specified string. |
---|
165 | * |
---|
166 | * @param type |
---|
167 | * the string that is to be this parameter's type |
---|
168 | */ |
---|
169 | public void setType(String type) |
---|
170 | { |
---|
171 | this.type = type; |
---|
172 | } |
---|
173 | |
---|
174 | /** |
---|
175 | * Gets the code name of the parameter |
---|
176 | * |
---|
177 | * @return this parameter's code name |
---|
178 | */ |
---|
179 | public String getCodeName() |
---|
180 | { |
---|
181 | return codeName; |
---|
182 | } |
---|
183 | |
---|
184 | /** |
---|
185 | * Sets the code name of the parameter to the specified string. |
---|
186 | * |
---|
187 | * @param codeName |
---|
188 | * the string that is to be this parameter's code name |
---|
189 | */ |
---|
190 | public void setCodeName(String codeName) |
---|
191 | { |
---|
192 | this.codeName = codeName; |
---|
193 | } |
---|
194 | |
---|
195 | /** |
---|
196 | * Returns whether this parameter is required for its parent service. |
---|
197 | * |
---|
198 | * @return true if this parameter is required; false otherwise |
---|
199 | */ |
---|
200 | public boolean isRequired() |
---|
201 | { |
---|
202 | return isRequired; |
---|
203 | } |
---|
204 | |
---|
205 | /** |
---|
206 | * Sets required or not required this parameter. A required parameter is |
---|
207 | * needed to launch its parent service. Parameters are not required |
---|
208 | * initially by default. |
---|
209 | * |
---|
210 | * @param isRequired |
---|
211 | * if true, this parameter is required; otherwise it is |
---|
212 | * optional |
---|
213 | */ |
---|
214 | public void setRequired(boolean isRequired) |
---|
215 | { |
---|
216 | this.isRequired = isRequired; |
---|
217 | } |
---|
218 | |
---|
219 | /** |
---|
220 | * Gets the default value of the parameter |
---|
221 | * |
---|
222 | * @return this parameter's default value |
---|
223 | */ |
---|
224 | public String getDefaultValue() |
---|
225 | { |
---|
226 | return defaultValue; |
---|
227 | } |
---|
228 | |
---|
229 | /** |
---|
230 | * Sets the default value of the parameter to the specified string. |
---|
231 | * |
---|
232 | * @param defaultValue |
---|
233 | * the string that is to be this parameter's default |
---|
234 | * value |
---|
235 | */ |
---|
236 | public void setDefaultValue(String defaultValue) |
---|
237 | { |
---|
238 | this.defaultValue = defaultValue; |
---|
239 | } |
---|
240 | } |
---|