summaryrefslogtreecommitdiff
path: root/sources/shared/Main.java
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shared/Main.java')
-rw-r--r--sources/shared/Main.java216
1 files changed, 110 insertions, 106 deletions
diff --git a/sources/shared/Main.java b/sources/shared/Main.java
index 54e11a9..328867b 100644
--- a/sources/shared/Main.java
+++ b/sources/shared/Main.java
@@ -1,3 +1,7 @@
+/* NetCalendar 2006, 2009 (c) Dipl.-Inform. (FH) Paul C. Buetow
+ * http://netcalendar.buetow.org - netcalendar@dev.buetow.org
+ */
+
package shared;
import java.io.*;
@@ -13,123 +17,123 @@ import client.*;
*
*/
public final class Main {
- private static NetCalendarClient netCalendarClient = null;
- private static BufferedWriter bufferedLogfileWriter = null;
-
- /**
- * This method is the start point of the whole program. Its initializing the static Config object
- * and starts a calendar server and/or a calendar client thread depending on the "server_run" and
- * "client_run" configuration options.
- * @param args Specifies the program arguments (not used yet by the program)
- */
- public static void main(String[] args) {
- Config.initialize(args);
-
- try {
- FileWriter fileWriter = new FileWriter(Config.getStringValue("logfile"));
- bufferedLogfileWriter = new BufferedWriter(fileWriter);
-
- } catch (IOException e) {
- infoMessage("Error: Could not open logfile: " + e.getMessage());
+ private static NetCalendarClient netCalendarClient = null;
+ private static BufferedWriter bufferedLogfileWriter = null;
+
+ /**
+ * This method is the start point of the whole program. Its initializing the static Config object
+ * and starts a calendar server and/or a calendar client thread depending on the "server_run" and
+ * "client_run" configuration options.
+ * @param args Specifies the program arguments (not used yet by the program)
+ */
+ public static void main(String[] args) {
+ Config.initialize(args);
+
+ try {
+ FileWriter fileWriter = new FileWriter(Config.getStringValue("logfile"));
+ bufferedLogfileWriter = new BufferedWriter(fileWriter);
+
+ } catch (IOException e) {
+ infoMessage("Error: Could not open logfile: " + e.getMessage());
+ }
+
+
+ if (Config.getBooleanValue("server_run")) {
+ new NetCalendarServer(
+ Config.getIntValue("server_port"),
+ checkDatabaseDir(Config.getStringValue("server_database_dir")));
+ }
+
+ if (Config.getBooleanValue("client_run")) {
+ new Thread(new SplashScreen()).start();
+ //Make sure we have nice window decorations.
+ JFrame.setDefaultLookAndFeelDecorated(true);
+ netCalendarClient = new NetCalendarClient();
+ }
}
-
- if (Config.getBooleanValue("server_run")) {
- new NetCalendarServer(
- Config.getIntValue("server_port"),
- checkDatabaseDir(Config.getStringValue("server_database_dir")));
+ /**
+ * For checking if the database dir exists. If not, use one upper level
+ * directory.
+ * @param sDatabaseDir The database dir
+ * @return The database dir if exists, else one upper level directory
+ */
+ private static String checkDatabaseDir(String sDatabaseDir) {
+ if (new File(sDatabaseDir).exists())
+ return sDatabaseDir;
+
+ return "../" + sDatabaseDir;
}
- if (Config.getBooleanValue("client_run")) {
- new Thread(new SplashScreen()).start();
- //Make sure we have nice window decorations.
- JFrame.setDefaultLookAndFeelDecorated(true);
- netCalendarClient = new NetCalendarClient();
+ /**
+ * All info messages of the calendar client and the calendar server go through this method.
+ * They are not using System.out.* directly.
+ * @param sMessage Specifies the program info message.
+ */
+ public static void infoMessage(String sMessage) {
+ // Later: Add logging to a logfile!
+ System.out.println(sMessage);
+ logMessage(sMessage);
}
- }
-
- /**
- * For checking if the database dir exists. If not, use one upper level
- * directory.
- * @param sDatabaseDir The database dir
- * @return The database dir if exists, else one upper level directory
- */
- private static String checkDatabaseDir(String sDatabaseDir) {
- if (new File(sDatabaseDir).exists())
- return sDatabaseDir;
-
- return "../" + sDatabaseDir;
- }
-
- /**
- * All info messages of the calendar client and the calendar server go through this method.
- * They are not using System.out.* directly.
- * @param sMessage Specifies the program info message.
- */
- public static void infoMessage(String sMessage) {
- // Later: Add logging to a logfile!
- System.out.println(sMessage);
- logMessage(sMessage);
- }
-
- /**
- * This method is for various messages. All messages will show up in the status bar of the client's main window.
- * If there is no main window, the infoMessage method will be used instead.
- * @param sMessage Specifies the message to be displayed in the status bar.
- */
- public static void statusMessage(String sMessage) {
- if (netCalendarClient != null)
- netCalendarClient.statusMessage(sMessage);
- else
- infoMessage(sMessage);
- }
-
- /**
- * This method writes a specific message string into a logfile which is specified in the netcalendar.conf.
- * @param sMessage Specified the message string to write into the logfile.
- */
- private static void logMessage(String sMessage) {
- if (bufferedLogfileWriter != null) {
- try {
- bufferedLogfileWriter.write(sMessage + "\n");
- // bufferedLogfileWriter.flush();
-
- } catch (IOException e) {
- Main.infoMessage("Error: Could not write to logfile: " + e.toString());
- }
+
+ /**
+ * This method is for various messages. All messages will show up in the status bar of the client's main window.
+ * If there is no main window, the infoMessage method will be used instead.
+ * @param sMessage Specifies the message to be displayed in the status bar.
+ */
+ public static void statusMessage(String sMessage) {
+ if (netCalendarClient != null)
+ netCalendarClient.statusMessage(sMessage);
+ else
+ infoMessage(sMessage);
}
- }
-
- /**
- * This method is called thenever the server or the client process wants to exit.
- * @param iCode Specifies the exit code to use for the System.exit call.
- */
- public static void exit(int iCode) {
- infoMessage("Shutting down the current process");
-
- try {
- bufferedLogfileWriter.close();
- } catch (IOException e) {
- System.err.println("Error: Could not close logfile: " + e.toString());
+
+ /**
+ * This method writes a specific message string into a logfile which is specified in the netcalendar.conf.
+ * @param sMessage Specified the message string to write into the logfile.
+ */
+ private static void logMessage(String sMessage) {
+ if (bufferedLogfileWriter != null) {
+ try {
+ bufferedLogfileWriter.write(sMessage + "\n");
+ // bufferedLogfileWriter.flush();
+
+ } catch (IOException e) {
+ Main.infoMessage("Error: Could not write to logfile: " + e.toString());
+ }
+ }
}
- System.exit(iCode);
- }
+ /**
+ * This method is called thenever the server or the client process wants to exit.
+ * @param iCode Specifies the exit code to use for the System.exit call.
+ */
+ public static void exit(int iCode) {
+ infoMessage("Shutting down the current process");
+
+ try {
+ bufferedLogfileWriter.close();
+ } catch (IOException e) {
+ System.err.println("Error: Could not close logfile: " + e.toString());
+ }
+
+ System.exit(iCode);
+ }
- /**
- * This method executes an external program.
- * @param sCommand Specifies the command string to execute.
- */
- public static void execExternalCommand(String sCommand) {
- if (sCommand.equals("none") || sCommand.equals(""))
- return;
+ /**
+ * This method executes an external program.
+ * @param sCommand Specifies the command string to execute.
+ */
+ public static void execExternalCommand(String sCommand) {
+ if (sCommand.equals("none") || sCommand.equals(""))
+ return;
- try {
- Runtime.getRuntime().exec(sCommand);
+ try {
+ Runtime.getRuntime().exec(sCommand);
- } catch (IOException e) {
- Main.infoMessage("Error while executing external command: " + e.getMessage());
+ } catch (IOException e) {
+ Main.infoMessage("Error while executing external command: " + e.getMessage());
+ }
}
- }
}