KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > launcher > LauncherApplication


1 /*====================================================================
2
3 ObjectWeb Util Launcher Package.
4 Copyright (C) 2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Romain Rouvoy.
23 Contributor(s): .
24
25 --------------------------------------------------------------------
26 $Id: LauncherApplication.java,v 1.3 2004/09/24 20:24:59 rouvoy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.launcher;
30
31
32 import org.objectweb.util.cmdline.api.Option;
33 import org.objectweb.util.cmdline.lib.ApplicationBase;
34
35 import org.objectweb.util.launcher.option.OptionVersion;
36 import org.objectweb.util.launcher.parser.ParserZeus;
37 import org.objectweb.util.launcher.parser.Repository;
38 import org.objectweb.util.trace.TraceSystem;
39
40
41
42 /**
43  * LauncherApplication describe the treatments to apply.<BR>
44  * <p>
45  * this structure considers only characters list.
46  * </p>
47  * @author <a HREF="mailto:Romain.Rouvoy@lifl.fr">Romain Rouvoy</a>
48  * @version 0.1
49  */

50 public class LauncherApplication
51      extends ApplicationBase
52 {
53     /**
54      * Default Constructor
55      */

56     public LauncherApplication() {
57         super(new LauncherCmdline(), false);
58         getCommandLine().addOption(new OptionVersion(this));
59     }
60     
61     /**
62      * Obtains the mailing list associated to this development.
63      * @return The mailing list associated to this development.
64      */

65     public String JavaDoc getMailingList() {
66         return "openccm@objectweb.org";
67     }
68     
69     /**
70      * Complete the incoming CommandJava with the content of the argument line.
71      * @param repository the Repository with descriptions.
72      * @param args the arguments for the application.
73      */

74     protected void process(Repository repository, StringList args) {
75         Option[] opt = getCommandLine().getOptions();
76         boolean default_run = true ;
77         for (int i = 0 ; i < opt.length ; i++) {
78             try {
79                 CommandBuilder builder = (CommandBuilder)opt[i];
80                 CommandJava[] cmd = builder.complete(repository);
81                 if (cmd.length!=0) default_run = false;
82                 for (int j=0 ; j < cmd.length ; j++) {
83                     cmd[j].addArguments(args);
84                     cmd[j].run();
85                 }
86             } catch(ClassCastException JavaDoc ex) {
87                 // Nothing to do if a CommandLine option is not a CommandBuilder
88
}
89         }
90         if (default_run) {
91             LauncherCmdline cmdline = (LauncherCmdline) getCommandLine();
92             CommandJava cmd = CommandProvider.get(repository,"default");
93             cmd.addArguments(args);
94             cmd.run();
95         }
96     }
97     
98     /**
99      * Starts the application.
100      * @param args The command line arguments.
101      * @return The status.
102      */

103     public int start(java.lang.String JavaDoc[] args) {
104         StringList arg = new StringList(args);
105         arg.remove(0);
106         try {
107             process((new ParserZeus()).load(args[0]), arg);
108         } catch(Exception JavaDoc ex) {
109             TraceSystem.get("launcher").fatal("Application terminated with "+ex);
110             return -1;
111         }
112         return 0;
113     }
114 }
115
Popular Tags