1 /**
2 * Copyright 2005-2006 the original author or authors.
3 *
4 * Licensed under the Gnu General Pubic License, Version 2.0 (the
5 * "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/gpl-license.php
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the Gnu General Public License for more details.
14 */
15 package org.figure8.join.control.form;
16
17 import org.figure8.join.control.JoinForm;
18 import org.figure8.join.control.action.SetupActions;
19
20 import org.apache.struts.action.ActionMapping;
21
22 import javax.servlet.http.HttpServletRequest;
23 /**
24 * Form object used during setup phase of Join application.
25 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
26 * @version $Revision: 1.1 $
27 *
28 * @struts.form name="setupForm"
29 */
30 public class SetupForm extends JoinForm{
31
32
33
34 /** Setup type (standard or custom) */
35 private String setupType = null;
36 /** Mode of setup (simple or dissociated) */
37 private String setupMode = null;
38 /** Synchronization of setup (synchronous or asynchronous) */
39 private String setupSynch = null;
40
41 /** Application over side http url */
42 private String httpUrl = null;
43 /** Application over side broker url */
44 private String brokerUrl = null;
45 /** Message broker listening port */
46 private int brokerPort = 0;
47 /** String representation of message broker listening port */
48 private String brokerPortStr = null;
49
50 /** Administrator name */
51 private String adminName = null;
52 /** Administrator password */
53 private String adminPassword = null;
54 /** Administrator password confirmation */
55 private String adminCPassword = null;
56 /** Administrator lastname */
57 private String adminLastname = null;
58 /** Administrator firstname */
59 private String adminFirstname = null;
60
61 /** DB user name */
62 private String userName = null;
63 /** DB user password */
64 private String userPassword = null;
65 /** DB connection URL */
66 private String databaseUrl = null;
67 /** JDBC driver class name */
68 private String driverClassname = null;
69 /** DB dialect to use */
70 private String dialect = null;
71 /** Maximum size of the connection pool. */
72 private int poolSize = 0;
73 /** String representation of maximum size of connection pool */
74 private String poolSizeStr = null;
75
76 /** Datasource jndi name */
77 private String datasource = null;
78
79
80
81
82 /** Creates a new instance of SetupForm */
83 public SetupForm(){
84 }
85
86
87
88
89 /** @param type Installation type choosed */
90 public void setSetupType(String type){
91 this.setupType = type;
92 }
93 /** @return Installation type choosed */
94 public String getSetupType(){
95 return setupType;
96 }
97
98 /** @param setupMode Installation mode choosed */
99 public void setSetupMode(String setupMode){
100 this.setupMode = setupMode;
101 }
102 /** @return Installation mode choosed */
103 public String getSetupMode(){
104 return setupMode;
105 }
106
107 /** @param setupSynch The synchronous property of this installation */
108 public void setSetupSynch(String setupSynch){
109 this.setupSynch = setupSynch;
110 }
111 /** @return The synchronous property of this installation */
112 public String getSetupSynch(){
113 return setupSynch;
114 }
115
116 /** @param httpUrl Application over side http url */
117 public void setHttpUrl(String httpUrl){
118 this.httpUrl = httpUrl;
119 }
120 /** @return Application over side http url */
121 public String getHttpUrl(){
122 return httpUrl;
123 }
124 /** @param brokerUrl Application over side broker url */
125 public void setBrokerUrl(String brokerUrl){
126 this.brokerUrl = brokerUrl;
127 }
128 /** @return Application over side broker url */
129 public String getBrokerUrl(){
130 return brokerUrl;
131 }
132 /** @return Message broker listening port */
133 public int getBrokerPort(){
134 return brokerPort;
135 }
136 /** @param brokerPortStr Message broker port string representation */
137 public void setBrokerPortStr(String brokerPortStr){
138 this.brokerPortStr = brokerPortStr;
139 }
140 /** @return Message broker listening port string repesentation */
141 public String getBrokerPortStr(){
142 return brokerPortStr;
143 }
144
145 /** @param name Administrator name */
146 public void setAdminName(String name){
147 this.adminName = name;
148 }
149 /** @return Adminitrator name */
150 public String getAdminName(){
151 return adminName;
152 }
153 /** @param pwd Administrator password */
154 public void setAdminPassword(String pwd){
155 this.adminPassword = pwd;
156 }
157 /** @return Administrator password */
158 public String getAdminPassword(){
159 return adminPassword;
160 }
161 /** @param cPassword Administrator password confirmation */
162 public void setAdminCPassword(String cPassword){
163 this.adminCPassword = cPassword;
164 }
165 /** @return Administrator password confirmation */
166 public String getAdminCPassword(){
167 return adminCPassword;
168 }
169 /** @param lastname Administrator lastname */
170 public void setAdminLastname(String lastname){
171 this.adminLastname = lastname;
172 }
173 /** @return Administrator lastname */
174 public String getAdminLastname(){
175 return adminLastname;
176 }
177 /** @param firstname Administrator firstname */
178 public void setAdminFirstname(String firstname){
179 this.adminFirstname = firstname;
180 }
181 /** @return Admnistrator firstname */
182 public String getAdminFirstname(){
183 return adminFirstname;
184 }
185
186 /** @param name DB user name */
187 public void setUserName(String name){
188 this.userName = name;
189 }
190 /** @return DB user name */
191 public String getUserName(){
192 return userName;
193 }
194 /** @param pwd DB user password */
195 public void setUserPassword(String pwd){
196 this.userPassword = pwd;
197 }
198 /** @return DB user password */
199 public String getUserPassword(){
200 return userPassword;
201 }
202 /** @param url Database URL */
203 public void setDatabaseUrl(String url){
204 this.databaseUrl = url;
205 }
206 /** @return Database URL */
207 public String getDatabaseUrl(){
208 return databaseUrl;
209 }
210 /** @param driver JDBC driver class name */
211 public void setDriverClassname(String driver){
212 this.driverClassname = driver;
213 }
214 /** @return JDBC driver class name */
215 public String getDriverClassname(){
216 return driverClassname;
217 }
218 /** @param dialect DB dialect to use */
219 public void setDialect(String dialect){
220 this.dialect = dialect;
221 }
222 /** @return DB dialect to use */
223 public String getDialect(){
224 return dialect;
225 }
226 /** @return Maximum size of connection pool size */
227 public int getPoolSize(){
228 return poolSize;
229 }
230 /** @param poolSizeStr Maximum size of connection pool size */
231 public void setPoolSizeStr(String poolSizeStr){
232 this.poolSizeStr = poolSizeStr;
233 }
234 /** @return Maximum size of connection pool size */
235 public String getPoolSizeStr(){
236 return poolSizeStr;
237 }
238
239 /** @param jndi Datasource jndi name */
240 public void setDatasource(String jndi){
241 this.datasource = jndi;
242 }
243 /** @return Datasource jndi name */
244 public String getDatasource(){
245 return datasource;
246 }
247
248
249
250
251 /**
252 * Validation of the form attributes.
253 * @param operation String representing the operation to invoke on Action
254 * @param mapping Mapping between forwards name and path for this action
255 * @param request The servlet container request wrapper
256 */
257 public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
258
259 if (SetupActions.SETUP_TYPE_OP.equals(operation)){
260
261 if (setupType == null || setupType.length() == 0)
262 addActionError("errors.required", getGuiMessageResources().getMessage("label.setup.type"));
263 }
264 else if (SetupActions.SETUP_MODE_OP.equals(operation)){
265
266 if (setupMode == null || setupMode.length() == 0)
267 addActionError("errors.required", getGuiMessageResources().getMessage("label.setup.mode"));
268 }
269 else if (SetupActions.SETUP_ADMIN_OP.equals(operation)){
270
271 if (adminName == null || adminName.length() == 0)
272 addActionError("errors.required", getGuiMessageResources().getMessage("label.user.login"));
273
274 if (adminPassword == null || adminPassword.length() == 0)
275 addActionError("errors.required", getGuiMessageResources().getMessage("label.user.password"));
276
277 if (adminLastname == null || adminLastname.length() == 0)
278 addActionError("errors.required", getGuiMessageResources().getMessage("label.user.lastname"));
279
280 if (adminFirstname == null || adminFirstname.length() == 0)
281 addActionError("errors.required", getGuiMessageResources().getMessage("label.user.firstname"));
282
283 if (adminPassword != null && adminCPassword != null && !adminPassword.equals(adminCPassword))
284 addActionError("errors.different", getGuiMessageResources().getMessage("label.user.password"), getGuiMessageResources().getMessage("label.user.cpassword"));
285 }
286 else if (SetupActions.SETUP_OTHERSIDE_OP.equals(operation)){
287
288 if (brokerPortStr != null && brokerPortStr.length() > 0){
289 try {brokerPort = Integer.parseInt(brokerPortStr);}
290 catch (Exception e){
291 addActionError("errors.integer", getGuiMessageResources().getMessage("label.setup.brokerPort"));
292 }
293 }
294 }
295 else if (SetupActions.SETUP_DATAB_OP.equals(operation)){
296
297 if (userName == null || userName.length() == 0)
298 addActionError("errors.required", getGuiMessageResources().getMessage("label.setup.database.userName"));
299
300 if (userPassword == null || userPassword.length() == 0)
301 addActionError("errors.required", getGuiMessageResources().getMessage("label.setup.database.userPassword"));
302
303 if (databaseUrl == null || databaseUrl.length() == 0)
304 addActionError("errors.required", getGuiMessageResources().getMessage("label.setup.database.databaseUrl"));
305
306 if (driverClassname == null || driverClassname.length() == 0)
307 addActionError("errors.required", getGuiMessageResources().getMessage("label.setup.database.driverClassname"));
308
309 if (dialect == null || dialect.length() == 0)
310 addActionError("errors.required", getGuiMessageResources().getMessage("label.setup.database.dialect"));
311
312 if (poolSizeStr == null || poolSizeStr.length() == 0)
313 addActionError("errors.required", getGuiMessageResources().getMessage("label.setup.database.poolSize"));
314 else{
315 try {poolSize = Integer.parseInt(poolSizeStr);}
316 catch (Exception e){
317 poolSize = 5;
318 }
319 }
320 }
321 else if (SetupActions.SETUP_DATAS_OP.equals(operation)){
322
323 if (datasource == null || datasource.length() == 0)
324 addActionError("errors.required", getGuiMessageResources().getMessage("label.setup.datasource"));
325 }
326 }
327 }