KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > commandLine > ExplorerApplication


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2005 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): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================
26 $Id: ExplorerApplication.java,v 1.3 2005/07/01 15:55:17 moroy Exp $
27 ====================================================================*/

28 package org.objectweb.openccm.explorer.commandLine;
29
30 import org.objectweb.openccm.corba.TheORB;
31 import org.objectweb.openccm.corba.TheRootPOA;
32 import org.objectweb.util.cmdline.lib.ApplicationBase;
33 import org.objectweb.util.cmdline.lib.DefaultCommandLine;
34 import org.objectweb.util.misc.api.ExceptionWrapper;
35 import org.objectweb.openccm.explorer.Main;
36 import org.objectweb.openccm.explorer.MainPDA;
37 import org.objectweb.openccm.explorer.CORBA.ConsoleFactory;
38
39 import java.util.Vector JavaDoc;
40 import java.util.List JavaDoc;
41
42 /**
43  * This class manages the different options and launch the corresponding command.
44  *
45  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>,
46  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
47  *
48  * @version 0.1
49  */

50 public class ExplorerApplication
51      extends ApplicationBase
52   implements DefaultApplication, ConfigApplication, ViewApplication {
53
54     /* The default explorer configuration files or directory. */
55     protected String JavaDoc[] explorerConfigFiles_ = null;
56
57     /* The default context config file or directory. */
58     protected String JavaDoc context_ = "";
59
60     /* The browser config file or directory fix by the user. */
61     protected String JavaDoc config_ = null;
62
63     /* The view of the main frame to use. */
64     protected String JavaDoc view_ = "basic";
65
66     /**
67      * Default Constructor.
68      */

69     public ExplorerApplication() {
70         super(new DefaultCommandLine(new String JavaDoc[] { "ccm_explorer" }, new String JavaDoc[0], new String JavaDoc[] { "Display the OpenCCM explorer console" }, true));
71         // Creates the ClientApplication options
72
getCommandLine().addOption(new DefaultContextOption(this));
73         getCommandLine().addOption(new DefaultExplorerOption(this));
74         getCommandLine().addOption(new ConfigOption(this));
75         getCommandLine().addOption(new ViewOption(this));
76     }
77
78     /**
79      * Remove the ORB arguments.
80      * @param args The command line arguments.
81      * @return The new args without ORB arguments.
82      */

83     private String JavaDoc[] removeORBArgument(String JavaDoc[] args) {
84         int nb = 0;
85         String JavaDoc[] tmp = new String JavaDoc[args.length];
86         for (int i = 0; i < args.length; i++) {
87             if (!args[i].startsWith("-ORB")) {
88                 tmp[nb] = args[i];
89                 nb++;
90             } else {
91                 i++;
92             }
93         }
94         String JavaDoc[] tmp2 = new String JavaDoc[nb];
95         for (int i = 0; i < nb; i++)
96             tmp2[i] = tmp[i];
97         return tmp2;
98     }
99
100     /**
101      * Fixes the Configuration file to use
102      * @param file The configuration file to use
103      */

104     public void setConfigFile(String JavaDoc file) {
105         config_ = file;
106     }
107
108     /**
109      * Fixes the Default Context Configuration file to use
110      * @param file The configuration file to use
111      */

112     public void setDefaultContextConfigFile(String JavaDoc file) {
113         context_ = file;
114     }
115
116     /**
117      * Fixes the Default Explorer Configuration file to use
118      * @param file The configuration file to use
119      */

120     public void setDefaultExplorerConfigFile(String JavaDoc[] file) {
121         explorerConfigFiles_ = file;
122     }
123
124     /**
125      * Fixes the view to use
126      * @param file The view to use
127      */

128     public void setView(String JavaDoc view){
129         view_ = view;
130     }
131     
132     /**
133      * Executes the main function.
134      * @param args The command line arguments.
135      */

136     public void runMain(String JavaDoc[] args) {
137         // Initializes the CORBA::ORB singleton.
138
org.omg.CORBA.ORB JavaDoc orb = org.objectweb.openccm.Components.Runtime.init(args);
139         //org.objectweb.ccm.CORBA.TheORB.initialize(args);
140

141         // Surcharges the ApplicationBase.runMain method.
142
try {
143             String JavaDoc[] arguments = getCommandLine().parse(removeORBArgument(args));
144             int ret = start(arguments);
145         } catch (ExceptionWrapper exc) {
146             report_exception(exc.getException());
147         } catch (Exception JavaDoc exc) {
148             report_exception(exc);
149         }
150     }
151
152     /**
153      * Starts the main function.
154      * @param args The command line arguments.
155      */

156     public int start(String JavaDoc[] args) {
157         List JavaDoc fileList = new Vector JavaDoc();
158         if(explorerConfigFiles_!=null){
159             for(int i=0 ; i < explorerConfigFiles_.length ; i++) {
160                 fileList.add(explorerConfigFiles_[i]);
161             }
162         }
163         if (config_ != null) {
164             fileList.add(config_);
165         }
166         if(view_.equals("tabs")) {
167             new MainPDA(context_, (String JavaDoc[]) fileList.toArray(new String JavaDoc[0]));
168         } else if(view_.equals("basic")) {
169             new Main(context_, (String JavaDoc[]) fileList.toArray(new String JavaDoc[0]));
170         }
171         return 0;
172     }
173
174     /**
175      * The main method.
176      * @param args The command line arguments.
177      */

178     public static void main(String JavaDoc[] args) {
179         ExplorerApplication application = new ExplorerApplication();
180         application.runMain(args);
181         ConsoleFactory.getDebugConsole().add("Running the ORB \n");
182         
183         // Activates the POA
184
try
185         {
186             ConsoleFactory.getDebugConsole().add("Activating the RootPOA\n");
187             TheRootPOA.getRootPOA().the_POAManager().activate();
188         }
189         catch ( java.lang.Exception JavaDoc ex )
190         {
191             System.err.println( "An exception has been intercepted" );
192             ex.printStackTrace();
193         }
194         
195         TheORB.run();
196     }
197
198 }
199
Popular Tags