KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > corba > ApplicationServer


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.corba;
28
29 /**
30  * This class provides the main structure of a CORBA server application.
31  *
32  * Subclasses must defined the before_run() and after_run() methods.
33  *
34  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
35  *
36  * @version 0.3
37  */

38
39 public abstract class ApplicationServer
40        extends Application
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     // ==================================================================
49
//
50
// Constructor.
51
//
52
// ==================================================================
53

54     /**
55      ** The default constructor.
56      **/

57     public
58     ApplicationServer()
59     {
60     }
61
62     // ==================================================================
63
//
64
// Internal methods.
65
//
66
// ==================================================================
67

68     // ==================================================================
69
//
70
// Public methods.
71
//
72
// ==================================================================
73

74     /**
75      ** Run the application, i.e.
76      ** initialize the Root POA,
77      ** active it,
78      ** call the before_run() method,
79      ** run the ORB,
80      ** call the after_run() method.
81      **
82      ** @param args The command line arguments.
83      **
84      ** @return The status returned by the after_run() method or zero.
85      **/

86     public int
87     run(String JavaDoc[] args)
88     {
89         // Initialize the Root POA.
90
org.omg.PortableServer.POA JavaDoc rootPOA = TheRootPOA.getRootPOA();
91
92         // Activate the Root POA.
93
try
94         {
95             rootPOA.the_POAManager().activate();
96         }
97         catch(org.omg.PortableServer.POAManagerPackage.AdapterInactive JavaDoc exc)
98         {
99             // Wrap the PortableServer::POAManager::AdapterInactive exception.
100
throw new UserExceptionWrapper(exc);
101         }
102
103         // Before running the ORB.
104
int status = before_run(args);
105
106         if(status != 0)
107         {
108               return status;
109         }
110
111         // Run the ORB.
112
TheORB.run();
113
114         System.err.println("The ApplicationServer shutdowns.");
115
116         try
117         {
118             // After running the ORB.
119
after_run();
120         }
121         catch(Exception JavaDoc exc)
122         {
123         }
124     
125         return 0;
126     }
127
128     /**
129      ** Before running the CORBA::ORB.
130      **
131      ** @param args The command line arguments.
132      **
133      ** @return The status.
134      **/

135     public abstract int
136     before_run(String JavaDoc[] args);
137
138     /**
139      ** After running the CORBA::ORB.
140      **/

141     public abstract void
142     after_run();
143 }
144
Popular Tags