KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > newbean > ParameterSet


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Nicolas Christin
22  * Contributor(s): ______________________________________.
23  *
24  * --------------------------------------------------------------------------
25  * $Id: ParameterSet.java,v 1.5 2003/11/21 01:13:25 skrupanszky Exp $
26  * --------------------------------------------------------------------------
27  */

28
29
30 package org.objectweb.jonas.newbean;
31
32
33 import org.apache.velocity.VelocityContext;
34
35
36 /**
37  * This class defines the set of parameters used by the application.
38  */

39 public class ParameterSet {
40
41     private Parameter beanNameParameter = null;
42     private Parameter beanFlavorParameter = null;
43     private Parameter sessionTypeParameter = null;
44     private Parameter persistenceManagerParameter = null;
45     private Parameter isLocalParameter = null;
46     private Parameter pkgNameParameter = null;
47     private Parameter jarNameParameter = null;
48     private Parameter pkClassParameter = null;
49
50
51     /**
52      * Creates a new set of parameters associated to the specified
53      * Velocity context.
54      */

55     public ParameterSet(VelocityContext context) {
56
57         // ----------------------------
58
// beanNameParameter definition
59
// ----------------------------
60

61         beanNameParameter = new Parameter(context) {
62
63                 public String JavaDoc getPrompt() {
64                     return "Bean Name";
65                 }
66
67                 public String JavaDoc getArgKeyword()
68                 {
69                     return "-beanName";
70                 }
71
72                 public boolean isValid() {
73                     return (value.length() > 0);
74                 }
75         
76                 public void export() {
77                     vContext.put("beanName", value);
78                 }
79         
80                 public Parameter getNextParameter() {
81                     return beanFlavorParameter;
82                 }
83
84             };
85
86
87         // ------------------------------
88
// beanFlavorParameter definition
89
// ------------------------------
90

91         beanFlavorParameter = new Parameter(context) {
92
93                 private final Integer JavaDoc SESSION_BEAN = new Integer JavaDoc(0);
94                 private final Integer JavaDoc ENTITY_BEAN = new Integer JavaDoc(1);
95                 private final Integer JavaDoc MESSAGE_DRIVEN_BEAN = new Integer JavaDoc(2);
96         
97                 public String JavaDoc getPrompt() {
98                     return "Bean type\n S Session bean\n E Entity bean\n MD Message-Driven bean";
99                 }
100
101                 public String JavaDoc getArgKeyword()
102                 {
103                     return "-beanType";
104                 }
105
106                 public void setValue(String JavaDoc input) {
107                     value = input.toUpperCase();
108                 }
109     
110                 public boolean isValid() {
111                     return (value.equals("S")
112                             || value.equals("E")
113                             || value.equals("MD"));
114                 }
115
116                 public void export() {
117                     vContext.put("SESSION_BEAN", SESSION_BEAN);
118                     vContext.put("ENTITY_BEAN", ENTITY_BEAN);
119                     vContext.put("MESSAGE_DRIVEN_BEAN", MESSAGE_DRIVEN_BEAN);
120                     Integer JavaDoc beanFlavor = null;
121                     String JavaDoc beanType = null;
122                     if (value.equals("S")) {
123                         beanFlavor = SESSION_BEAN;
124                         beanType = "S";
125                     }
126                     else if (value.equals("E")) {
127                         beanFlavor = ENTITY_BEAN;
128                         beanType = "E";
129                     }
130                     else if (value.equals("MD")) {
131                         beanFlavor = MESSAGE_DRIVEN_BEAN;
132                         beanType = "MD";
133                     }
134                     vContext.put("beanFlavor", beanFlavor);
135                     vContext.put("beanType", beanType);
136                 }
137
138                 public Parameter getNextParameter() {
139                     Integer JavaDoc beanFlavor = (Integer JavaDoc)vContext.get("beanFlavor");
140                     if (beanFlavor == SESSION_BEAN) {
141                         return sessionTypeParameter;
142                     }
143                     else if (beanFlavor == ENTITY_BEAN) {
144                         return persistenceManagerParameter;
145                     }
146                     return pkgNameParameter;
147                 }
148
149             };
150     
151
152         // -------------------------------
153
// sessionTypeParameter definition
154
// -------------------------------
155

156         sessionTypeParameter = new Parameter(context) {
157
158                 private final Integer JavaDoc STATELESS = new Integer JavaDoc(0);
159                 private final Integer JavaDoc STATEFUL = new Integer JavaDoc(1);
160
161                 public String JavaDoc getPrompt() {
162                     return "Session type\n L Staless\n F Stateful";
163                 }
164
165                 public String JavaDoc getArgKeyword()
166                 {
167                     return "-sessionType";
168                 }
169
170                 public void setValue(String JavaDoc input) {
171                     value = input.toUpperCase();
172                 }
173     
174                 public boolean isValid() {
175                     return (value.equals("L")
176                             || value.equals("F"));
177                 }
178         
179                 public void export() {
180                     vContext.put("STATELESS", STATELESS);
181                     vContext.put("STATEFUL", STATEFUL);
182                     Integer JavaDoc sessionType = null;
183                     String JavaDoc beanType = (String JavaDoc)vContext.get("beanType");
184                     if (value.equals("L")) {
185                         sessionType = STATELESS;
186                         beanType += "L";
187                     }
188                     else if (value.equals("F")) {
189                         sessionType = STATEFUL;
190                         beanType += "F";
191                     }
192                     vContext.put("sessionType", sessionType);
193                     vContext.put("beanType", beanType);
194                 }
195         
196                 public Parameter getNextParameter() {
197                     return isLocalParameter;
198                 }
199
200             };
201
202
203         // --------------------------------------
204
// persistenceManagerParameter definition
205
// --------------------------------------
206

207         persistenceManagerParameter = new Parameter(context) {
208
209                 private final Integer JavaDoc BMP = new Integer JavaDoc(0);
210                 private final Integer JavaDoc CMP1 = new Integer JavaDoc(1);
211                 private final Integer JavaDoc CMP2 = new Integer JavaDoc(2);
212
213                 public String JavaDoc getPrompt() {
214                     return "Persistance manager\n B BMP\n C CMP 1.x\n C2 CMP 2.x";
215                 }
216
217                 public String JavaDoc getArgKeyword()
218                 {
219                     return "-persistence";
220                 }
221
222                 public void setValue(String JavaDoc input) {
223                     value = input.toUpperCase();
224                 }
225     
226                 public boolean isValid() {
227                     return (value.equals("C")
228                             || value.equals("B")
229                             || value.equals("C2"));
230                 }
231         
232                 public void export() {
233                     vContext.put("CMP1", CMP1);
234                     vContext.put("CMP2", CMP2);
235                     vContext.put("BMP", BMP);
236                     Integer JavaDoc persistenceManager = null;
237             
238                     String JavaDoc beanType = (String JavaDoc)vContext.get("beanType");
239                     if (value.equals("C")) {
240                         persistenceManager = CMP1;
241                         beanType += "C";
242                     }
243                     else if (value.equals("B")) {
244                         persistenceManager = BMP;
245                         beanType += "B";
246                     }
247                     else if (value.equals("C2")) {
248                         persistenceManager = CMP2;
249                         beanType += "C2";
250                     }
251                     vContext.put("persistenceManager", persistenceManager);
252                     vContext.put("beanType", beanType);
253                 }
254         
255                 public Parameter getNextParameter() {
256                     return isLocalParameter;
257                 }
258
259             };
260
261
262         // ---------------------------
263
// isLocalParameter definition
264
// ---------------------------
265

266         isLocalParameter = new Parameter(context) {
267
268                 private final Boolean JavaDoc FALSE = Boolean.FALSE;
269                 private final Boolean JavaDoc TRUE = Boolean.TRUE;
270
271                 public String JavaDoc getPrompt() {
272                     return "Bean location\n R Remote\n L Local";
273                 }
274
275                 public String JavaDoc getArgKeyword()
276                 {
277                     return "-location";
278                 }
279
280                 public void setValue(String JavaDoc input) {
281                     value = input.toUpperCase();
282                 }
283     
284                 public boolean isValid() {
285                     return (value.equals("R")
286                             || value.equals("L"));
287                 }
288         
289                 public void export() {
290                     Boolean JavaDoc isLocal = null;
291                     String JavaDoc beanType = (String JavaDoc)vContext.get("beanType");
292                     if (value.equals("L")) {
293                         isLocal = TRUE;
294                         beanType += "L";
295                     }
296                     else if (value.equals("R")) {
297                         isLocal = FALSE;
298                         beanType += "R";
299                     }
300                     vContext.put("isLocal", isLocal);
301                     vContext.put("beanType", beanType);
302                 }
303         
304                 public Parameter getNextParameter() {
305                     return pkgNameParameter;
306                 }
307
308             };
309
310
311         // ---------------------------
312
// pkgNameParameter definition
313
// ---------------------------
314

315         pkgNameParameter = new Parameter(context) {
316
317                 public String JavaDoc getPrompt() {
318                     return "Package name";
319                 }
320
321                 public String JavaDoc getArgKeyword()
322                 {
323                     return "-pkgName";
324                 }
325
326                 public boolean isValid() {
327                     return (value.length() > 0);
328                 }
329         
330                 public void export() {
331                     vContext.put("pkgName", value);
332                 }
333         
334                 public Parameter getNextParameter() {
335                     return jarNameParameter;
336                 }
337
338             };
339
340
341         // ---------------------------
342
// jarNameParameter definition
343
// ---------------------------
344

345         jarNameParameter = new Parameter(context) {
346
347                 public String JavaDoc getPrompt() {
348                     return "Jar name";
349                 }
350
351                 public String JavaDoc getArgKeyword()
352                 {
353                     return "-jarName";
354                 }
355
356                 public void setValue(String JavaDoc input) {
357                     if (input.endsWith(".jar")) {
358                         value = input.substring(0, input.length() - 4);
359                     }
360                     else {
361                         value = input;
362                     }
363                 }
364         
365                 public boolean isValid() {
366                     return (value.length() > 0);
367                 }
368         
369                 public void export() {
370                     vContext.put("jarName", value);
371                 }
372         
373                 public Parameter getNextParameter() {
374                     final Integer JavaDoc ENTITY_BEAN =
375                         (Integer JavaDoc)vContext.get("ENTITY_BEAN");
376                     Integer JavaDoc beanFlavor =
377                         (Integer JavaDoc)vContext.get("beanFlavor");
378                     if (beanFlavor == ENTITY_BEAN)
379                         return pkClassParameter;
380                     else
381                         return null;
382                 }
383
384             };
385
386
387         // ---------------------------
388
// pkClassParameter definition
389
// ---------------------------
390

391         pkClassParameter = new Parameter(context) {
392
393                 public String JavaDoc getPrompt() {
394                     return "Primary Key class\n S String\n I Integer\n O Object";
395                 }
396
397                 public String JavaDoc getArgKeyword()
398                 {
399                     return "-primaryKey";
400                 }
401
402                 public void setValue(String JavaDoc input) {
403                     value = input.toUpperCase();
404                 }
405     
406                 public boolean isValid() {
407                     return (value.equals("S")
408                             || value.equals("I")
409                             || value.equals("O"));
410                 }
411         
412                 public void export() {
413                     String JavaDoc pkClass = null;
414                     if (value.equals("S"))
415                         pkClass = "java.lang.String";
416                     else if (value.equals("I"))
417                         pkClass = "java.lang.Integer";
418                     else if (value.equals("O"))
419                         pkClass = "java.lang.Object";
420                     vContext.put("pkClass", pkClass);
421                 }
422         
423                 public Parameter getNextParameter() {
424                     return null;
425                 }
426
427             };
428
429     }
430
431
432     /**
433      * Walk through ({@link Parameter#walkThrough()}) the whole
434      * parameters set.
435      */

436     public void walkThrough() {
437         beanNameParameter.walkThrough();
438     }
439
440 }
441
Popular Tags