KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > engine > dm > UserAlertManagementOperation


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.framework.engine.dm;
20
21 import sync4j.framework.core.AlertCode;
22
23 /**
24  * ManagementOperation for Alerts. This is intended as a base class for derived
25  * alert types (such as DisplayManagementOperation, ConfirmManagementOpertation
26  * and so on. However, it can be used directly for maximum configurability.
27  *
28  * @author Stefano Fornari @ Funambol
29  *
30  * @version $Id: UserAlertManagementOperation.java,v 1.1 2005/05/16 17:32:55 nichele Exp $
31  */

32 public class UserAlertManagementOperation extends TreeManagementOperation {
33     // --------------------------------------------------------------- Constants
34

35     protected final String JavaDoc INPUT_TYPES = "ANDTPI";
36     protected final String JavaDoc ECHO_TYPES = "TP" ;
37
38     // ------------------------------------------------------------ Private Data
39
private static final String JavaDoc DESCRIPTION = "Alert";
40
41     // ---------------------------------------------------------- Public Methods
42
public String JavaDoc getDescription() {
43       return DESCRIPTION;
44     }
45
46
47     /**
48      * The messages that must be displayed to the user
49      */

50     protected String JavaDoc[] alerts;
51
52     /**
53      * Minimum display time (-1 for not specified)
54      */

55     protected int minDisplayTime;
56
57     /**
58      * Maximum display time (-1 for not specified)
59      */

60     protected int maxDisplayTime;
61
62     /**
63      * Default response (null for not specified)
64      */

65     protected String JavaDoc defaultResponse;
66
67     /**
68      * Max length (-1 for not specified)
69      */

70     protected int maxLength;
71
72     /**
73      * Input type (' ' for not specified). See protocol for content meaning.
74      * Possible values are here summarized:
75      * <ul>
76      * <li>A - alphanumeric</li>
77      * <li>N - numeric</li>
78      * <li>D - date in the form <i>DDMMYYYY</i></li>
79      * <li>T - time in the form <i>hhmmss</i></li>
80      * <li>P - phone number (the following chars included: "+", "p", "w", "s")</li>
81      * <li>I - IP address in the form xxx.yyy.www.zzz
82      * </ul>
83      */

84     protected char inputType;
85
86     /**
87      * Echo type (' ' for not specified). One of the following values:
88      * <ul>
89      * <li>T - text</li>
90      * <li>P - password</li>
91      * </ul>
92      */

93     protected char echoType;
94
95     /**
96      * The alert code
97      */

98     protected int alertCode;
99
100     // ------------------------------------------------------------ Constructors
101
public UserAlertManagementOperation() {
102     }
103
104     /**
105      * Creates a new UserAlertManagementOperation with minimal information.
106      * It is the same as:
107      * <code>
108      * UserAlertManagementOperation(alertCode, alerts, -1, -1, null, -1, ' ', ' ')
109      * </code>
110      *
111      * @param alertCode the alert code to use
112      * @param String[] alerts
113      *
114      * @throws IllegalArgumentException if any of the given parameter is
115      * not correct
116      */

117     public UserAlertManagementOperation(final int alertCode, final String JavaDoc[] alerts)
118     throws IllegalArgumentException JavaDoc {
119         this(alertCode, alerts, -1, -1, null, -1, ' ', ' ');
120     }
121
122     /**
123      * Creates a new UserAlertManagementOperation with the complete parameter
124      * list.
125      *
126      * @param alertCode the alert code
127      * @param alerts alert texts
128      * @param mindt minimum display time
129      * @param maxdt maximum display time
130      * @param dr default response
131      * @param maxlen maximum length
132      * @param it input type
133      * @param et echo type
134      *
135      * @throws IllegalArgumentException if any of the given parameter is
136      * not correct
137      */

138     public UserAlertManagementOperation(
139         int alertCode,
140         String JavaDoc[] alerts ,
141         int mindt ,
142         int maxdt ,
143         String JavaDoc dr ,
144         int maxlen ,
145         char it ,
146         char et
147     ) {
148         if (!AlertCode.isUserAlertCode(alertCode)) {
149             throw new IllegalArgumentException JavaDoc(alertCode + " is not a user alert code");
150         }
151
152         if ((it != ' ') && (INPUT_TYPES.indexOf(it) < 0)) {
153             throw new IllegalArgumentException JavaDoc( "Input type '"
154                                               + it
155                                               + "' is not one of "
156                                               + INPUT_TYPES
157                                               );
158         }
159
160         if ((et != ' ') && (ECHO_TYPES.indexOf(et) < 0)) {
161             throw new IllegalArgumentException JavaDoc( "Echo type '"
162                                               + et
163                                               + "' is not one of "
164                                               + ECHO_TYPES
165                                               );
166         }
167
168         this.alertCode = alertCode;
169
170         if (alerts == null) {
171             this.alerts = new String JavaDoc[0];
172         } else {
173             this.alerts = alerts;
174         }
175
176         minDisplayTime = mindt ;
177         maxDisplayTime = maxdt ;
178         defaultResponse = dr ;
179         maxLength = maxlen;
180         inputType = it ;
181         echoType = et ;
182     }
183
184
185     // ---------------------------------------------------------- Public methods
186

187     /**
188      * Getter for property minimumDisplayTime.
189      * @return Value of property minimumDisplayTime.
190      */

191     public int getMinDisplayTime() {
192         return minDisplayTime;
193     }
194
195     /**
196      * Setter for property minimumDisplayTime.
197      * @param minimumDisplayTime New value of property minimumDisplayTime.
198      */

199     public void setMinDisplayTime(int minDisplayTime) {
200         this.minDisplayTime = minDisplayTime;
201     }
202
203     /**
204      * Getter for property alerts.
205      * @return Value of property alerts.
206      */

207     public String JavaDoc[] getAlerts() {
208         return this.alerts;
209     }
210
211     /**
212      * Setter for property alerts.
213      * @param alerts New value of property alerts.
214      */

215     public void setAlerts(String JavaDoc[] alerts) {
216         this.alerts = alerts;
217     }
218
219     /**
220      * Getter for property maximumDisplayTime.
221      * @return Value of property maximumDisplayTime.
222      */

223     public int getMaxDisplayTime() {
224         return maxDisplayTime;
225     }
226
227     /**
228      * Setter for property maximumDisplayTime.
229      * @param maximumDisplayTime New value of property maximumDisplayTime.
230      */

231     public void setMaxDisplayTime(int maxDisplayTime) {
232         this.maxDisplayTime = maxDisplayTime;
233     }
234
235     /**
236      * Getter for property defaultResponse.
237      * @return Value of property defaultResponse.
238      */

239     public String JavaDoc getDefaultResponse() {
240         return defaultResponse;
241     }
242
243     /**
244      * Setter for property defaultResponse.
245      * @param defaultResponse New value of property defaultResponse.
246      */

247     public void setDefaultResponse(String JavaDoc defaultResponse) {
248         this.defaultResponse = defaultResponse;
249     }
250
251     /**
252      * Getter for property maxLength.
253      * @return Value of property maxLength.
254      */

255     public int getMaxLength() {
256         return maxLength;
257     }
258
259     /**
260      * Setter for property maxLength.
261      * @param maxLength New value of property maxLength.
262      */

263     public void setMaxLength(int maxLength) {
264         this.maxLength = maxLength;
265     }
266
267     /**
268      * Getter for property inputType.
269      * @return Value of property inputType.
270      */

271     public char getInputType() {
272         return inputType;
273     }
274
275     /**
276      * Setter for property inputType.
277      * @param inputType New value of property inputType.
278      */

279     public void setInputType(char inputType) {
280         this.inputType = inputType;
281     }
282
283     /**
284      * Getter for property echoType.
285      * @return Value of property echoType.
286      */

287     public char getEchoType() {
288         return echoType;
289     }
290
291     /**
292      * Setter for property echoType.
293      * @param echoType New value of property echoType.
294      */

295     public void setEchoType(char echoType) {
296         this.echoType = echoType;
297     }
298
299         /**
300      * Getter for property alertCode.
301      * @return Value of property alertCode.
302      */

303     public int getAlertCode() {
304         return alertCode;
305     }
306
307     /**
308      * Setter for property alertCode.
309      * @param alertCode New value of property alertCode.
310      */

311     public void setAlertCode(int alertCode) {
312         this.alertCode = alertCode;
313     }
314
315     // --------------------------------------------------- Public static methods
316

317     /**
318      * Creates a UserAlertManagementOperation for a DISPLAY alert. No options
319      * are specified
320      *
321      * @param text the text to display
322      *
323      * @return the created UserAlertManagementOperation object
324      *
325      */

326     public static UserAlertManagementOperation getDisplay(final String JavaDoc text) {
327         return getDisplay(text, -1, -1);
328     }
329
330     /**
331      * Creates a UserAlertManagementOperation for a DISPLAY alert with options.
332      *
333      * @param text the text to display
334      * @param mindt minimum display time
335      * @param maxdt maximum display time
336      *
337      * @return the created UserAlertManagementOperation object
338      *
339      */

340     public static UserAlertManagementOperation getDisplay(
341         final String JavaDoc text ,
342         final int mindt,
343         final int maxdt) {
344
345         return getUserAlert(
346             AlertCode.DISPLAY ,
347             new String JavaDoc[] { text },
348             mindt , /* MINDT */
349             maxdt , /* MAXDT */
350             null , /* DR */
351             -1 , /* MAXLEN */
352             ' ' , /* IT */
353             ' ' /* ET */
354         );
355     }
356
357     /**
358      * Creates a UserAlertManagementOperation for a DISPLAY alert. No options
359      * are specified
360      *
361      * @param text the text to display
362      *
363      * @return the created UserAlertManagementOperation object
364      *
365      */

366     public static UserAlertManagementOperation getConfirm(final String JavaDoc text) {
367         return getConfirm(text, -1, -1, null);
368     }
369
370     /**
371      * Creates a UserAlertManagementOperation for a DISPLAY alert with options.
372      *
373      * @param text the text to display
374      * @param mindt minimum display time
375      * @param maxdt maximum display time
376      *
377      * @return the created UserAlertManagementOperation object
378      *
379      */

380     public static UserAlertManagementOperation getConfirm(
381         final String JavaDoc text ,
382         final int mindt,
383         final int maxdt,
384         final String JavaDoc dr ) {
385
386         return getUserAlert(
387             AlertCode.CONFIRM_OR_REJECT,
388             new String JavaDoc[] { text } ,
389             mindt , /* MINDT */
390             maxdt , /* MAXDT */
391             dr , /* DR */
392             -1 , /* MAXLEN */
393             ' ' , /* IT */
394             ' ' /* ET */
395         );
396     }
397
398
399     /**
400      * Creates a UserAlertManagementOperation for an INPUT alert. No options
401      * are specified
402      *
403      * @param text the text to display
404      *
405      * @return the created UserAlertManagementOperation object
406      *
407      */

408     public static UserAlertManagementOperation getInput(final String JavaDoc text) {
409         return getInput(text, -1, -1, null, -1, ' ', ' ');
410     }
411
412     /**
413      * Creates a UserAlertManagementOperation for an INPUT alert with options.
414      *
415      * @param text the text to display
416      * @param mindt minimum display time
417      * @param maxdt maximum display time
418      * @param dr default response
419      * @param maxlen maximum length
420      * @param it input type
421      * @param et echo type
422      *
423      * @return the created UserAlertManagementOperation object
424      *
425      */

426     public static UserAlertManagementOperation getInput(
427         final String JavaDoc text ,
428         final int mindt ,
429         final int maxdt ,
430         final String JavaDoc dr ,
431         final int maxlen,
432         final char it ,
433         final char et ) {
434
435         return getUserAlert(
436             AlertCode.INPUT ,
437             new String JavaDoc[] { text },
438             mindt , /* MINDT */
439             maxdt , /* MAXDT */
440             dr , /* DR */
441             maxlen , /* MAXLEN */
442             it , /* IT */
443             et /* ET */
444         );
445     }
446
447     /**
448      * Creates a UserAlertManagementOperation for a CHOICE alert. No options
449      * are specified
450      *
451      * @param text the text to display
452      * @param options the available options
453      *
454      * @return the created UserAlertManagementOperation object
455      *
456      */

457     public static UserAlertManagementOperation getChoice(
458         final String JavaDoc text ,
459         final String JavaDoc[] options
460     ) {
461         return getChoice(text, options, -1, -1, null);
462     }
463
464     /**
465      * Creates a UserAlertManagementOperation for a CHOICE alert with options.
466      *
467      * @param text the text to display
468      * @param mindt minimum display time
469      * @param maxdt maximum display time
470      * @param dr default response
471      *
472      * @return the created UserAlertManagementOperation object
473      *
474      */

475     public static UserAlertManagementOperation getChoice(
476         final String JavaDoc text ,
477         final String JavaDoc[] options,
478         final int mindt ,
479         final int maxdt ,
480         final String JavaDoc dr ) {
481
482         if ((options == null) || (options.length == 0)) {
483             throw new IllegalArgumentException JavaDoc("options cannot be null or zero length");
484         }
485
486         String JavaDoc[] alerts = new String JavaDoc[options.length+1];
487
488         alerts[0] = text;
489         System.arraycopy(options, 0, alerts, 1, options.length);
490
491         return getUserAlert(
492             AlertCode.SINGLE_CHOICE,
493             alerts ,
494             mindt , /* MINDT */
495             maxdt , /* MAXDT */
496             dr , /* DR */
497             -1 , /* MAXLEN */
498             ' ' , /* TI */
499             ' ' /* TE */
500         );
501     }
502
503     /**
504      * Creates a UserAlertManagementOperation for a CHOICE alert with options.
505      *
506      * @param text the text to display
507      * @param mindt minimum display time
508      * @param maxdt maximum display time
509      * @param dr default response
510      *
511      * @return the created UserAlertManagementOperation object
512      *
513      */

514     public static UserAlertManagementOperation getMultiChoice(
515         final String JavaDoc text ,
516         final String JavaDoc[] options,
517         final int mindt ,
518         final int maxdt ,
519         final String JavaDoc dr ) {
520
521         if ((options == null) || (options.length == 0)) {
522             throw new IllegalArgumentException JavaDoc("options cannot be null or zero length");
523         }
524
525         String JavaDoc[] alerts = new String JavaDoc[options.length+1];
526
527         alerts[0] = text;
528         System.arraycopy(options, 0, alerts, 1, options.length);
529
530         return getUserAlert(
531             AlertCode.MULTIPLE_CHOICE,
532             alerts ,
533             mindt , /* MINDT */
534             maxdt , /* MAXDT */
535             dr , /* DR */
536             -1 , /* MAXLEN */
537             ' ' , /* TI */
538             ' ' /* TE */
539         );
540     }
541
542     // ------------------------------------------------ Protected static methods
543

544     /**
545      * Creates a UserAlertManagementOperation from the given parameters.
546      *
547      * @param alertCode the alert code
548      * @param alerts alert texts
549      * @param mindt minimum display time
550      * @param maxdt maximum display time
551      * @param dr default response
552      * @param maxlen maximum length
553      * @param it input type
554      * @param et echo type
555      *
556      * @return the created UserAlertManagementOperation object
557      */

558     protected static UserAlertManagementOperation getUserAlert(
559         final int alertCode,
560         final String JavaDoc[] alerts ,
561         final int mindt ,
562         final int maxdt ,
563         final String JavaDoc dr ,
564         final int maxlen ,
565         final char it ,
566         final char et
567     ) {
568         return new UserAlertManagementOperation(
569                    alertCode,
570                    alerts ,
571                    mindt ,
572                    maxdt ,
573                    dr ,
574                    maxlen ,
575                    it ,
576                    et
577         );
578     }
579
580 }
Popular Tags