KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > command > lib > ApplicationBase


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): Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.command.lib;
28
29 // Package dependencies.
30
import org.objectweb.util.cmdline.api.CommandLine;
31 import org.objectweb.openccm.command.lib.ReleaseInfo;
32 import org.objectweb.openccm.corba.TheORB;
33
34 /**
35  * Abstract base class providing the main structure of
36  * a CORBA client application.
37  *
38  * Subclasses must defined the run() method.
39  *
40  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
41  *
42  * @version 0.1
43  */

44
45 public abstract class ApplicationBase
46               extends org.objectweb.util.cmdline.lib.ApplicationBase
47            implements org.objectweb.openccm.command.api.Application
48 {
49     // ==================================================================
50
//
51
// Internal state.
52
//
53
// ==================================================================
54

55     // ==================================================================
56
//
57
// Constructors.
58
//
59
// ==================================================================
60

61     /** The default constructor. */
62     public
63     ApplicationBase()
64     {
65         // Calls the org.objectweb.util.cmdline.lib.ApplicationBase constructor.
66
super();
67     }
68
69     /**
70      * The constructor with the command line manager.
71      *
72      * @param commandLine The command line manager.
73      */

74     public
75     ApplicationBase(CommandLine commandLine)
76     {
77         // Calls the org.objectweb.util.cmdline.lib.ApplicationBase constructor.
78
super(commandLine);
79     }
80
81     // ==================================================================
82
//
83
// Internal methods.
84
//
85
// ==================================================================
86

87     // ==================================================================
88
//
89
// Public methods for org.objectweb.util.api.Identifiable
90
//
91
// ==================================================================
92

93     /**
94      * Obtains its identity.
95      *
96      * Should be defined in subclasses.
97      *
98      * @return Its identity.
99      */

100     public String JavaDoc
101     getIdentity()
102     {
103         return getCommandLine().getLabels()[0]
104              + ' ' + ReleaseInfo.VERSION;
105     }
106
107     // ==================================================================
108
//
109
// Public methods for org.objectweb.util.cmdline.api.Application
110
//
111
// ==================================================================
112

113     /**
114      * Obtains the associated version information.
115      *
116      * @return The associated version information.
117      */

118     public String JavaDoc[]
119     getVersionInformation()
120     {
121         String JavaDoc[] result = super.getVersionInformation();
122         result[0] = ReleaseInfo.NAME_SHORT + ' '
123                   + getIdentity()
124                   + " (on top of "
125                   + System.getProperty("orb.name", "UNKNOWN")
126                   + ' '
127                   + System.getProperty("orb.version", "X.X")
128                   + ')';
129         return result;
130     }
131
132     /**
133      * Executes the main function, i.e.
134      * 1 - Initializes the CORBA::ORB,
135      * 2 - Calls super.runMain().
136      *
137      * @param args The command line arguments.
138      */

139     public void
140     runMain(String JavaDoc[] args)
141     {
142         try
143         {
144             // Initializes the CORBA::ORB singleton.
145
args = TheORB.initialize(args);
146         }
147         // If any exception thrown then reports it.
148
//
149
catch(org.objectweb.util.misc.api.ExceptionWrapper exc)
150         {
151             report_exception(exc.getException());
152         }
153         catch(Exception JavaDoc exc)
154         {
155             report_exception(exc);
156         }
157
158         // Calls ApplicationBase.runMain method.
159
super.runMain(args);
160     }
161
162     /**
163      * Starts the application, i.e.
164      * 1 - Runs the application,
165      * 2 - Destroys the CORBA::ORB.
166      *
167      * @param args The command line arguments.
168      */

169     public int
170     start(String JavaDoc[] args)
171     {
172         int status = 0;
173
174         try
175         {
176             // Runs the application.
177
status = run(args);
178         }
179         finally
180         {
181            // Destroys the CORBA::ORB singleton.
182
TheORB.destroy();
183         }
184
185         return status;
186     }
187
188     // ==================================================================
189
//
190
// Public methods for org.objectweb.openccm.command.api.Application
191
//
192
// ==================================================================
193

194     /**
195      * Runs the application.
196      *
197      * Note that the CORBA::ORB is always initialized
198      * before this method is called.
199      *
200      * Must be defined in subclasses.
201      *
202      * @param args The command line arguments.
203      *
204      * @return The status.
205      */

206     public abstract int
207     run(String JavaDoc[] args);
208 }
209
Popular Tags