KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > packaging > cmdline > PATApplication


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-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): Christophe Contreras
23 Contributor(s): ___________________________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.packaging.cmdline;
28
29 // Package dependencies
30
import org.objectweb.openccm.packaging.AssemblyPackager;
31 import org.objectweb.openccm.packaging.CCMMenuBar;
32 import org.objectweb.openccm.packaging.CCMSplitPane;
33 import org.objectweb.openccm.packaging.ComponentPackager;
34 import org.objectweb.openccm.packaging.FileOperations;
35
36 import org.objectweb.util.cmdline.api.CommandLine;
37 import org.objectweb.util.cmdline.lib.ApplicationBase;
38 import org.objectweb.util.cmdline.lib.DefaultCommandLine;
39
40 import org.objectweb.apollon.gui.ApollonFrame;
41
42 /**
43  * This is the Application class for OpenCCM's Packaging/Assembling Tools
44  *
45  * @author <a HREF="mailto:Christophe.Contreras@lifl.fr">Christophe Contreras</a>
46  *
47  */

48 public class PATApplication
49      extends ApplicationBase
50 {
51     // ==================================================================
52
//
53
// Internal state.
54
//
55
// ==================================================================
56

57     /** The GUi display setting. */
58     private boolean displayGUI_;
59     
60     /** The CAR archive maker setting. */
61     private boolean CARMaker_;
62     
63     /** The AAR archive maker setting. */
64     private boolean AARMaker_;
65     
66     // ==================================================================
67
//
68
// Constructors.
69
//
70
// ==================================================================
71

72     /**
73      * The default constructor.
74      */

75     public
76     PATApplication()
77     {
78         // default Application constructor
79
super(
80             new DefaultCommandLine(
81                 new String JavaDoc [] { "ccm_assembling", "car_maker" , "aar_maker" }
82                 ,new String JavaDoc[0]
83                 ,true
84                 ,new String JavaDoc[] {
85                     "Packaging/Assembling Tool providing a GUI and console-based engines (default is GUI)."
86                     ,"car_maker is a shortcut for 'ccm_assembling -CAR'"
87                     ,"aar_maker is a shortcut for 'ccm_assembling -AAR'"
88                     ,"[additional] arguments should be descriptor files to be opened or used for CAR/AAR creation."
89                     }
90                 ,true
91                 )
92             );
93         
94         // inits the commandLine options
95
getCommandLine().addOption(new OptionCAR(this));
96         getCommandLine().addOption(new OptionAAR(this));
97         
98         // inits default to GUI displayed
99
this.displayGUI_ = true;
100     }
101
102     // ==================================================================
103
//
104
// Internal methods.
105
//
106
// ==================================================================
107

108     // ==================================================================
109
//
110
// Public methods for org.objectweb.util.api.Identifiable
111
//
112
// ==================================================================
113

114     /**
115      * Obtains its identity.
116      *
117      * @return Its identity.
118      */

119     public String JavaDoc
120     getIdentity()
121     {
122         return "OpenCCM's Packaging/Assembling Tools";
123     }
124
125     /**
126      * Executes the main function, i.e.
127      * 1 - arguments = getCommandLine().parse(args);
128      * 2 - status = starts(arguments);
129      *
130      * @param args The command line arguments.
131      */

132     public void
133     runMain(String JavaDoc[] args)
134     {
135         try {
136             // Parses the command line arguments.
137
String JavaDoc[] arguments = getCommandLine().parse(args);
138             
139             // Starts the application.
140
int status = start(arguments);
141
142         // If any exception thrown then reports it.
143
//
144
} catch(org.objectweb.util.misc.api.ExceptionWrapper exc) {
145             report_exception(exc.getException());
146         } catch(Exception JavaDoc exc) {
147             report_exception(exc);
148         }
149     }
150
151     /**
152      * Starts the application.
153      *
154      * @param args The command line arguments.
155      *
156      * @return The status.
157      */

158     public int
159     start(String JavaDoc[] args)
160     {
161         boolean result = process(args);
162         return 0;
163
164 // return result?0:1;
165
}
166
167     // ==================================================================
168
//
169
// Public methods.
170
//
171
// ==================================================================
172
/**
173      * Enables/Disables the GUI display
174      *
175      * @param displayGUI The boolean indicating GUI display setting
176      */

177     public void
178     displayGUI(boolean displayGUI)
179     {
180         this.displayGUI_ = displayGUI;
181     }
182
183     /**
184      * Enables the CAR archive maker
185      *
186      * @param CAR indicates to use the CAR maker
187      */

188     public void
189     setCARMaker(boolean CAR)
190     {
191         this.CARMaker_ = CAR;
192     }
193
194     /**
195      * Enables the AAR archive maker
196      *
197      * @param AAR indicates to use the CAR maker
198      */

199     public void
200     setAARMaker(boolean AAR)
201     {
202         this.AARMaker_ = AAR;
203     }
204
205     /**
206      * Global processing method.
207      *
208      * @param filenames The XML DTD to generate Java from.
209      *
210      * @return True if OK.
211      */

212     public boolean
213     process (String JavaDoc[] filenames)
214     {
215         if (this.displayGUI_)
216         {
217             // inits the graphical frame
218
ApollonFrame frame
219              = new ApollonFrame();
220
221             // inits the split panel of the frame
222
frame.set_split_panel(new CCMSplitPane());
223
224             // Adds the CCM part of the Menubar to existing
225
CCMMenuBar ccm_menubar
226              = new CCMMenuBar(frame);
227
228             frame.setVisible(true);
229
230             // opens files given as arguments
231
for (int i=0 ; i<filenames.length ; i++)
232             {
233                 java.io.File JavaDoc file
234                  = new java.io.File JavaDoc(filenames[i]);
235
236                 FileOperations.open_file(file, frame);
237             }
238             synchronized (this)
239             {
240                 try
241                 {
242                     this.wait();
243                 } catch (InterruptedException JavaDoc e) {}
244             }
245         }
246         for (int i=0 ; i<filenames.length ; i++)
247         {
248             String JavaDoc file_used = filenames[i];
249 System.err.println(file_used);
250
251             // direct operations on the files passed as arguments
252
java.io.File JavaDoc file
253              = new java.io.File JavaDoc (file_used);
254
255             org.objectweb.apollon.framework.Bean zeus_instance
256              = null;
257
258             if (CARMaker_)
259             {
260                 // Parses the descriptor
261
try
262                 {
263                     zeus_instance
264                      = org.objectweb.openccm.descriptor.
265                         softpkg.beans.
266                         SoftpkgBeanImpl
267                             .unmarshalBean(file);
268                     // instantiate and call a Packager
269
ComponentPackager maker = new ComponentPackager();
270                     maker.make_zip(zeus_instance,file_used);
271
272                 } catch (Exception JavaDoc e) {
273                     getConsole().getErrorStream().println(
274                         "CAR builder ignored "+file);
275                 }
276             }
277             if (AARMaker_)
278             {
279                 // Parses the descriptor
280
try
281                 {
282                     zeus_instance
283                      = org.objectweb.openccm.descriptor.
284                         componentassembly.beans.
285                         ComponentassemblyBeanImpl
286                             .unmarshalBean(file);
287                     // instantiate and call a Packager
288
AssemblyPackager maker = new AssemblyPackager();
289                     maker.make_zip(zeus_instance,file_used);
290
291                 } catch (Exception JavaDoc e) {
292                     getConsole().getErrorStream().println(
293                         "AAR builder ignored "+file);
294                 }
295             }
296         }
297         return true;
298     }
299
300     // ==================================================================
301
//
302
// Static public methods.
303
//
304
// ==================================================================
305

306     /**
307      * The main bootstrap method.
308      *
309      * @param args The command line arguments.
310      */

311     public static void
312     main(String JavaDoc[] args)
313     {
314         PATApplication application = new PATApplication();
315         application.runMain(args);
316     }
317 }
318
Popular Tags