KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > setup > forms > ShutdownForm


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
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. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.setup.forms;
21
22 import java.text.SimpleDateFormat JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26 import org.apache.struts.Globals;
27 import org.apache.struts.action.ActionErrors;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.action.ActionMessage;
30
31 import com.sslexplorer.core.CoreServlet;
32 import com.sslexplorer.core.forms.CoreForm;
33 import com.sslexplorer.tasks.shutdown.ShutdownTimerTask;
34 import com.sslexplorer.tasks.timer.StoppableTimer;
35
36 public class ShutdownForm extends CoreForm {
37
38     public static final String JavaDoc SHUTDOWN = "shutdown";
39     public static final String JavaDoc RESTART = "restart";
40     public static final String JavaDoc BOTH = "both";
41     public static final String JavaDoc SHUTTING_DOWN = "shutting_down";
42     
43     private String JavaDoc shutdownDelay = "0";
44
45     private String JavaDoc shutdownType;
46     private String JavaDoc shutdownOperation;
47     private boolean alreadyPerforming = false;
48     private String JavaDoc shutdownTime;
49
50     /**
51      * @return Returns the shutdownType.
52      */

53     public String JavaDoc getShutdownType() {
54         return shutdownType;
55     }
56
57     /**
58      * @param shutdownType The shutdownType to set.
59      */

60     public void setShutdownType(String JavaDoc shutdownType) {
61         this.shutdownType = shutdownType;
62     }
63
64     public String JavaDoc getShutdownDelay() {
65         return shutdownDelay;
66     }
67
68     public void setShutdownDelay(String JavaDoc shutdownTime) {
69         this.shutdownDelay = shutdownTime;
70     }
71     
72     public boolean isImmediate(){
73         if (getShutdownDelay().equals("0"))
74             return true;
75         else
76             return false;
77     }
78
79     public boolean getAlreadyPerforming(){
80         return this.alreadyPerforming;
81     }
82     
83     public void setAlreadyPerforming(boolean alreadyPerforming) {
84         this.alreadyPerforming = alreadyPerforming;
85     }
86     
87     public String JavaDoc getShutdownTime() {
88         return shutdownTime;
89     }
90
91     public ActionErrors validate(ActionMapping arg0, HttpServletRequest JavaDoc arg1) {
92         StoppableTimer timer = (StoppableTimer) CoreServlet.getServlet().getServletContext().getAttribute(StoppableTimer.NAME);
93         if (timer.containsTimerTask(ShutdownTimerTask.NAME)){
94             shutdownTime = new SimpleDateFormat JavaDoc("HH:mm").format(((ShutdownTimerTask)timer.getTimerTask(ShutdownTimerTask.NAME)).getShutDownTime());
95             alreadyPerforming = true;
96         }
97         else {
98             shutdownTime = null;
99             alreadyPerforming = false;
100         }
101
102         ActionErrors errors = new ActionErrors();
103         
104         try {
105             int shutdownDelayInt = Integer.parseInt(getShutdownDelay());
106             if(!getAlreadyPerforming() && shutdownDelayInt < 0) {
107                 errors.add(Globals.ERROR_KEY, new ActionMessage("shutdown.global.error.message.negative"));
108                 setShutdownDelay("0");
109                 return errors;
110             }
111         } catch (Exception JavaDoc e) {
112             errors.add(Globals.ERROR_KEY, new ActionMessage("shutdown.global.error.message.decimal"));
113             setShutdownDelay("0");
114         }
115         
116         return errors;
117     }
118     
119     public void setShutdownOperation(String JavaDoc shutdownOperation) {
120         this.shutdownOperation = shutdownOperation;
121     }
122     
123     public String JavaDoc getShutdownOperation() {
124         return shutdownOperation;
125     }
126     
127     
128 }
Popular Tags