[Lutinutil-commits] r900 - trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo
Author: tchemit Date: 2008-07-24 21:06:28 +0000 (Thu, 24 Jul 2008) New Revision: 900 Added: trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/DemoMain.java Removed: trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/MyMain.java Log: demo :) Copied: trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/DemoMain.java (from rev 897, trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/MyMain.java) =================================================================== --- trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/DemoMain.java (rev 0) +++ trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/DemoMain.java 2008-07-24 21:06:28 UTC (rev 900) @@ -0,0 +1,121 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * # #% + */ +package org.codelutin.commandline.demo; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.option.OptionParserResult; +import org.codelutin.option.ParserFailedException; + +import java.io.IOException; + +/** @author chemit */ +public class DemoMain { + + private static final Log log = LogFactory.getLog(DemoMain.class); + + /** le context principal de l'application */ + protected static MyContext context; + + public static MyContext getContext() { + checkInitContext(); + return context; + } + + /** + * initialisation de l'application : + * <p/> + * chargement du context + * + * @param args les arguments pass�s � l'application + */ + public static synchronized void init(String... args) { + + try { + // instanciate context, parser and configs + context = new MyContext(); + + // init context + context.init(args); + + } catch (IOException e) { + log.error("io error : " + e.getMessage()); + e.printStackTrace(); + System.exit(1); + + } catch (ParserFailedException e) { + log.error("parser error : " + e.getMessage()); + e.printStackTrace(); + System.exit(1); + } catch (Exception e) { + log.error("fatal error : " + e.getMessage()); + e.printStackTrace(); + System.exit(1); + } + + } + + /** Lancement de l'ui apr�s init de l'application. */ + public static void launch() { + + getContext().getMainUI().setVisible(true); + + } + + + /** @param args les arguments pass�s au programme */ + public static void main(String[] args) { + + init(args); + + try { + OptionParserResult optionParserResult = getContext().getParser().getLastResult(); + if (optionParserResult.size() > 0) { + optionParserResult.doAllActions(getContext()); + } + } catch (Exception e) { + log.error("a problem occurs while treating commandline : " + e.getMessage(), e); + //TODO should we stop ? + } + + if (getContext().isQuit() || !getContext().isUseUI()) { + // nothing more to be done here + return; + } + + launch(); + + } + + public static void checkInitContext() { + if (context == null) { + throw new RuntimeException("context is null, you must init first the " + MyContext.class.getName() + " class via init method"); + } + } + + public static void dispose(boolean reload) { + + getContext().getActionFactory().dispose(); + + getContext().disposeUI(); + + //ErrorDialog.disposeUI(); + + if (reload) { + launch(); + } + } + +} Deleted: trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/MyMain.java =================================================================== --- trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/MyMain.java 2008-07-24 21:00:46 UTC (rev 899) +++ trunk/commandline/commandline-demo/src/main/java/org/codelutin/commandline/demo/MyMain.java 2008-07-24 21:06:28 UTC (rev 900) @@ -1,121 +0,0 @@ -/** - * # #% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * # #% - */ -package org.codelutin.commandline.demo; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.option.OptionParserResult; -import org.codelutin.option.ParserFailedException; - -import java.io.IOException; - -/** @author chemit */ -public class MyMain { - - private static final Log log = LogFactory.getLog(MyMain.class); - - /** le context principal de l'application */ - protected static MyContext context; - - public static MyContext getContext() { - checkInitContext(); - return context; - } - - /** - * initialisation de l'application : - * <p/> - * chargement du context - * - * @param args les arguments pass�s � l'application - */ - public static synchronized void init(String... args) { - - try { - // instanciate context, parser and configs - context = new MyContext(); - - // init context - context.init(args); - - } catch (IOException e) { - log.error("io error : " + e.getMessage()); - e.printStackTrace(); - System.exit(1); - - } catch (ParserFailedException e) { - log.error("parser error : " + e.getMessage()); - e.printStackTrace(); - System.exit(1); - } catch (Exception e) { - log.error("fatal error : " + e.getMessage()); - e.printStackTrace(); - System.exit(1); - } - - } - - /** Lancement de l'ui apr�s init de l'application. */ - public static void launch() { - - getContext().getMainUI().setVisible(true); - - } - - - /** @param args les arguments pass�s au programme */ - public static void main(String[] args) { - - init(args); - - try { - OptionParserResult optionParserResult = getContext().getParser().getLastResult(); - if (optionParserResult.size() > 0) { - optionParserResult.doAllActions(getContext()); - } - } catch (Exception e) { - log.error("a problem occurs while treating commandline : " + e.getMessage(), e); - //TODO should we stop ? - } - - if (getContext().isQuit() || !getContext().isUseUI()) { - // nothing more to be done here - return; - } - - launch(); - - } - - public static void checkInitContext() { - if (context == null) { - throw new RuntimeException("context is null, you must init first the " + MyContext.class.getName() + " class via init method"); - } - } - - public static void dispose(boolean reload) { - - getContext().getActionFactory().dispose(); - - getContext().disposeUI(); - - //ErrorDialog.disposeUI(); - - if (reload) { - launch(); - } - } - -}
participants (1)
-
tchemit@users.labs.libre-entreprise.org