KickJava   Java API By Example, From Geeks To Geeks.

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


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.corba.TheORB;
32 import org.objectweb.openccm.corba.TheRootPOA;
33
34 /**
35  * Abstract base class providing the main structure of
36  * a CORBA server application.
37  *
38  * Subclasses must defined the before_run() and after_run() methods.
39  *
40  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
41  *
42  * @version 0.1
43  */

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

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

61     /** The default constructor. */
62     public
63     ApplicationServerBase()
64     {
65         // Calls the 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     ApplicationServerBase(CommandLine commandLine)
76     {
77         // Calls the ApplicationBase constructor.
78
super(commandLine);
79     }
80
81     // ==================================================================
82
//
83
// Internal methods.
84
//
85
// ==================================================================
86

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

93     // ==================================================================
94
//
95
// Public methods for org.objectweb.openccm.command.api.Application
96
//
97
// ==================================================================
98

99     /**
100      * Runs the application, i.e.
101      * 1 - Initializes the Root POA,
102      * 2 - Actives it,
103      * 3 - Calls the before_run() method,
104      * 4 - Runs the ORB,
105      * 5 - Calls the after_run() method.
106      *
107      * @param args The command line arguments.
108      *
109      * @return The status returned by the after_run() method or zero.
110      */

111     public int
112     run(String JavaDoc[] args)
113     {
114         // Initializes the Root POA.
115
org.omg.PortableServer.POA JavaDoc rootPOA = TheRootPOA.getRootPOA();
116
117         // Activates the Root POA.
118
try
119         {
120             rootPOA.the_POAManager().activate();
121         }
122         catch(org.omg.PortableServer.POAManagerPackage.AdapterInactive JavaDoc exc)
123         {
124             // Wrap the PortableServer::POAManager::AdapterInactive exception.
125
throw new org.objectweb.openccm.corba.UserExceptionWrapper(exc);
126         }
127
128         // Before running the ORB.
129
int status = before_run(args);
130
131         if(status != 0)
132         {
133             return status;
134         }
135
136         // Runs the ORB.
137
TheORB.run();
138
139         getConsole().message("Shutdown completed.");
140
141         try
142         {
143             // After running the ORB.
144
after_run();
145         }
146         catch(Exception JavaDoc exc)
147         {
148         }
149
150         return 0;
151     }
152
153     // ==================================================================
154
//
155
// Public methods for org.objectweb.openccm.command.api.ApplicationServer
156
//
157
// ==================================================================
158

159     /**
160      * Before running the CORBA::ORB object.
161      *
162      * Must be defined in subclasses.
163      *
164      * @param args The command line arguments.
165      *
166      * @return The status.
167      */

168     public abstract int
169     before_run(String JavaDoc[] args);
170
171     /**
172      * After running the CORBA::ORB object.
173      *
174      * Must be defined in subclasses.
175      */

176     public abstract void
177     after_run();
178 }
179
Popular Tags