KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > actor > commandline > ActorApplication


1 /*===========================================================================
2
3 ObjectWeb Naming Context Framework
4 Copyright (C) 2002 USTL - LIFL - GOAL
5 Contact: architecture@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): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26 package org.coach.actor.commandline;
27
28 import org.objectweb.util.cmdline.lib.ApplicationBase;
29 import org.objectweb.util.cmdline.lib.DefaultCommandLine;
30 import org.objectweb.util.misc.api.ExceptionWrapper;
31 import org.coach.actor.Main;
32 import java.io.File JavaDoc;
33 import java.util.Vector JavaDoc;
34 import java.util.List JavaDoc;
35
36 /**
37  * This class manages the different options and launch the corresponding command.
38  *
39  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
40  * @version 0.1
41  */

42 public class ActorApplication extends ApplicationBase implements DefaultApplication, ConfigApplication {
43
44     /* The default actor config file or directory. */
45     protected String JavaDoc actor_ = "";
46
47     /* The default context config file or directory. */
48     protected String JavaDoc context_ = "";
49
50     /* The actor config file or directory fix by the user. */
51     protected String JavaDoc config_ = null;
52
53     /**
54      * Default Constructor.
55      */

56     public ActorApplication() {
57         super(new DefaultCommandLine(new String JavaDoc[] { "ccm_actor" }, new String JavaDoc[0], new String JavaDoc[] { "Display the OpenCCM actor console" }, true));
58         // Creates the ClientApplication options
59
// getCommandLine().addOption(new DefaultContextOption(this));
60
getCommandLine().addOption(new DefaultActorOption(this));
61 // getCommandLine().addOption(new ConfigOption(this));
62
}
63
64     /**
65      * Remove the ORB arguments.
66      * @param args The command line arguments.
67      * @return The new args without ORB arguments.
68      */

69     private String JavaDoc[] removeORBArgument(String JavaDoc[] args) {
70         int nb = 0;
71         String JavaDoc[] tmp = new String JavaDoc[args.length];
72         for (int i = 0; i < args.length; i++) {
73             if (!args[i].startsWith("-ORB")) {
74                 tmp[nb] = args[i];
75                 nb++;
76             } else {
77                 i++;
78             }
79         }
80         String JavaDoc[] tmp2 = new String JavaDoc[nb];
81         for (int i = 0; i < nb; i++)
82             tmp2[i] = tmp[i];
83         return tmp2;
84     }
85
86     /**
87      * Fixes the Configuration file to use
88      * @param file The configuration file to use
89      */

90     public void setConfigFile(String JavaDoc file) {
91         config_ = file;
92     }
93
94     /**
95      * Fixes the Default Context Configuration file to use
96      * @param file The configuration file to use
97      */

98     public void setDefaultContextConfigFile(String JavaDoc file) {
99         context_ = file;
100     }
101
102     /**
103      * Fixes the Default Actor Configuration file to use
104      * @param file The configuration file to use
105      */

106     public void setDefaultActorConfigFile(String JavaDoc file) {
107         actor_ = file;
108     }
109
110     /**
111      * Executes the main function.
112      * @param args The command line arguments.
113      */

114     public void runMain(String JavaDoc[] args) {
115         // Initializes the CORBA::ORB singleton.
116
org.omg.CORBA.ORB JavaDoc orb = org.objectweb.openccm.Components.Runtime.init(args);
117         //org.objectweb.openccm.corba.TheORB.initialize(args);
118

119         // Surcharges the ApplicationBase.runMain method.
120
try {
121             String JavaDoc[] arguments = getCommandLine().parse(removeORBArgument(args));
122             int ret = start(arguments);
123         } catch (ExceptionWrapper exc) {
124             report_exception(exc.getException());
125         } catch (Exception JavaDoc exc) {
126             report_exception(exc);
127         }
128     }
129
130     /**
131      * Starts the main function.
132      * @param args The command line arguments.
133      */

134     public int start(String JavaDoc[] args) {
135         List JavaDoc fileList = new Vector JavaDoc();
136         fileList.add(new File JavaDoc(actor_));
137         if (config_ != null) {
138             fileList.add(new File JavaDoc(config_));
139         }
140         new Main(new File JavaDoc(context_), (File JavaDoc[]) fileList.toArray(new File JavaDoc[0]));
141         return 0;
142     }
143
144     /**
145      * The main method.
146      * @param args The command line arguments.
147      */

148     public static void main(String JavaDoc[] args) {
149         ActorApplication application = new ActorApplication();
150         application.runMain(args);
151     }
152
153 }
Popular Tags