KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > qfs > apps > qflog > command > CommandFileExit


1 // {{{ copyright
2

3 /********************************************************************
4  *
5  * $Id: CommandFileExit.java,v 1.10 2000/07/05 14:07:44 gs Exp $
6  *
7  * The contents of this file are subject to the Mozilla Public
8  * License Version 1.1 (the "License"); you may not use this file
9  * except in compliance with the License. You may obtain a copy of
10  * the License at http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS
13  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14  * implied. See the License for the specific language governing
15  * rights and limitations under the License.
16  *
17  * The Original Code is qfs.de code.
18  *
19  * The Initial Developer of the Original Code is Gregor Schmid.
20  * Portions created by Gregor Schmid are
21  * Copyright (C) 1999 Quality First Software, Gregor Schmid.
22  * All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  *******************************************************************/

27
28 // }}}
29

30 package de.qfs.apps.qflog.command;
31
32 // {{{ imports
33

34 import java.io.FileOutputStream JavaDoc;
35 import java.rmi.Naming JavaDoc;
36
37 import de.qfs.lib.command.Command;
38 import de.qfs.lib.command.CommandException;
39 import de.qfs.lib.command.Invokable;
40 import de.qfs.lib.config.Configuration;
41 import de.qfs.lib.log.Log;
42 import de.qfs.lib.log.Logger;
43 import de.qfs.lib.logrmi.RemoteLogFilter;
44
45 import de.qfs.apps.qflog.App;
46
47 // }}}
48

49 /**
50  * This Command exits the application, removing the server from the RMI
51  * registry and saving the Configuration first.
52  *
53  * @author Gregor Schmid
54  * @version $Revision: 1.10 $
55  */

56 public class CommandFileExit extends Command
57 implements Invokable
58 {
59     // {{{ variables
60

61     /**
62      * The Logger used for logging.
63      */

64     private final static Logger logger = new Logger (CommandFileExit.class);
65
66
67     // }}}
68

69     // {{{ constructor
70

71     /**
72      * Create a new CommandFileExit.
73      *
74      * @param source The source of the Command.
75      */

76     public CommandFileExit (Object JavaDoc source)
77     {
78         super (source);
79     }
80
81     // }}}
82

83     // {{{ invoke
84

85     /**
86      * Invoke the command.
87      *
88      * @return Always null.
89      *
90      * @throws CommandException Never.
91      */

92     public Object JavaDoc invoke()
93          throws CommandException
94     {
95         if (logger.level >= Log.MTD) {
96             logger.log(Log.MTD, "invoke()", "");
97         }
98
99         // App.getCommandDistributor().assignCommandSilently
100
// (new CommandMaybeSave (source));
101

102         try {
103             // save configuration
104
FileOutputStream JavaDoc fos =
105                 new FileOutputStream JavaDoc (App.instance().getConfigFile());
106             // VersionedSerializable.setSaving(true);
107
Configuration.instance().save(fos);
108             // VersionedSerializable.setSaving(false);
109
fos.close();
110             if (logger.level >= Log.MSG) {
111                 logger.log(Log.MSG, "invoke()",
112                            "Configuration saved");
113             }
114             // remove RMI server
115
Naming.unbind ("//"+ App.instance().getServerHost() +
116                            "/" + App.instance().getServerName());
117             if (logger.level >= Log.MSG) {
118                 logger.log(Log.MSG, "main(String[])",
119                            "TestServer unbound");
120             }
121         } catch (Exception JavaDoc ex) {
122             if (logger.level >= Log.ERR) {
123                 logger.log("invoke()", ex);
124             }
125         }
126         Log.setQueueing(false);
127         RemoteLogFilter.stopLogging();
128         System.exit(0);
129
130         // never reached
131
return null;
132     }
133
134     // }}}
135
}
136
Popular Tags