DBVIEW
src/org/dbview/runtime/Dbview.java
00001 /*
00002         DbView - Graph Visualization
00003     Copyright (C) 2012  Denis BEURIVE
00004 
00005     This program is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 /**
00020  * @author Denis Beurive
00021  */
00022 
00023 package org.dbview.runtime;
00024 
00025 import org.jdom.*;
00026 import org.dbview.runtime.actions.*;
00027 import org.dbview.runtime.cli.*;
00028 
00029 /**
00030  * This class implements the main entry point of the application.
00031  * @author Denis Beurive
00032  */
00033 public class Dbview
00034 {
00035     /**
00036      * This is the main entry point.
00037      * @param args Command line arguments.
00038      */
00039         public static void main(String[] args)
00040         {
00041                 try
00042                 {
00043                         // ---------------------------------------------------------------------------
00044                         // Parse the command line.
00045                         // ---------------------------------------------------------------------------
00046 
00047                         CliData cli_data = CliParser.parse(args);
00048                         if (CliActionSelector.CLI_UNKNOWN == cli_data.type) { Dbview.__unexpectedCli(); System.exit(1); }
00049                         if (null != cli_data.message) { Dbview.__errorMessage(cli_data.message); System.exit(1); }
00050 
00051                         // ---------------------------------------------------------------------------
00052                         // Look what we have...
00053                         // ---------------------------------------------------------------------------
00054 
00055             if (cli_data.type == CliActionSelector.CLI_HELP)                     { System.out.println(CliParser.help()); }
00056             if (cli_data.type == CliActionSelector.CLI_INPUT_HELP)               { Actions.helpInputAddOn(cli_data.data); }
00057             if (cli_data.type == CliActionSelector.CLI_OUTPUT_HELP)              { Actions.helpOutputAddOn(cli_data.data); }
00058             if (cli_data.type == CliActionSelector.CLI_LIST_INPUT_ADDONS)        { Actions.listInputTargets(); }
00059             if (cli_data.type == CliActionSelector.CLI_LIST_OUTPUT_TABLE_ADDONS) { Actions.listOutputTargets(); }
00060             if (cli_data.type == CliActionSelector.CLI_LIST_SFK_DETECTOR)        { Actions.listFkMatchers(); }
00061             if (cli_data.type == CliActionSelector.CLI_PROFILE_ADD)              { Actions.addProfile(cli_data.data); }
00062             if (cli_data.type == CliActionSelector.CLI_PROFILE_REMOVE)           { Actions.removeProfile(cli_data.data); }
00063             if (cli_data.type == CliActionSelector.CLI_PROFILE_SHOW)             { Actions.showProfile(cli_data.data); }
00064             if (cli_data.type == CliActionSelector.CLI_PROFILE_UPDATE)           { Actions.updateProfile(cli_data.data); }
00065             if (cli_data.type == CliActionSelector.CLI_PROFILE_LIST)             { Actions.listProfiles(); }
00066             if (cli_data.type == CliActionSelector.CLI_EXPORT)                   { Actions.export(cli_data.data); }
00067 
00068                 System.exit(0);
00069                 }
00070                 catch (Exception e)
00071                 {
00072                         System.out.println(e.getMessage());
00073                         System.exit(1);
00074                 }
00075         }
00076 
00077         /**
00078          * Prints the help message (if the action's selector is unknown).
00079          */
00080         private static void __unexpectedCli()
00081         {
00082                 System.out.println("Unrecognizable command line's pattern.");
00083                 System.out.println("Type \"" + System.getProperty("program.name") + " help\" for help." );
00084         }
00085 
00086         /**
00087          * Prints an error message.
00088          * @param in_message Error message to print.
00089          */
00090         private static void __errorMessage(String in_message)
00091         {
00092                 System.out.println(in_message);
00093         }
00094 }