KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > Components > Runtime


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 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): Mathieu Vadet, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.Components;
28
29 import org.objectweb.openccm.Components.HomeManager;
30 import org.objectweb.openccm.Components.HomeManagerHelper;
31
32 /**
33  * This global class provides utility functions for the OpenCCM
34  * Abstract Model.
35  *
36  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
37  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
38  *
39  * @version 0.3
40  */

41
42 public abstract class Runtime
43 {
44     // ==================================================================
45
//
46
// Internal state.
47
//
48
// ==================================================================
49

50     /**
51      ** To avoid to init the runtime multiple times.
52      **/

53     protected static boolean already_initialized_ = false;
54
55     /**
56      ** The HomeManager (Finder and Register) reference.
57      **/

58     protected static HomeManager home_manager_;
59
60     // ==================================================================
61
//
62
// Constructor.
63
//
64
// ==================================================================
65

66     /**
67      ** The default constructor.
68      **/

69     private
70     Runtime()
71     {
72     }
73
74     // ==================================================================
75
//
76
// Internal methods.
77
//
78
// ==================================================================
79

80     /**
81      ** Register the required Components valuetype factories.
82      **
83      **/

84     protected static void
85     register_valuetype_factories()
86     {
87         register_value_factory(org.omg.Components.ComponentPortDescriptionHelper.id(),
88                                new ComponentPortDescriptionFactory());
89
90         register_value_factory(org.omg.Components.ConfigValueHelper.id(),
91                                new ConfigValueFactory());
92
93         register_value_factory(org.omg.Components.ConnectionDescriptionHelper.id(),
94                                new ConnectionDescriptionFactory());
95
96         register_value_factory(org.omg.Components.ConsumerDescriptionHelper.id(),
97                                new ConsumerDescriptionFactory());
98
99         register_value_factory(org.omg.Components.CookieHelper.id(),
100                                new CookieFactory());
101
102         register_value_factory(org.omg.Components.EmitterDescriptionHelper.id(),
103                                new EmitterDescriptionFactory());
104
105         register_value_factory(org.omg.Components.FacetDescriptionHelper.id(),
106                                new FacetDescriptionFactory());
107
108         register_value_factory(org.omg.Components.FacetDescriptionHelper.id(),
109                                new FacetDescriptionFactory());
110
111         register_value_factory(org.omg.Components.PublisherDescriptionHelper.id(),
112                                new PublisherDescriptionFactory());
113
114         register_value_factory(org.omg.Components.ReceptacleDescriptionHelper.id(),
115                                new ReceptacleDescriptionFactory());
116
117         register_value_factory(org.omg.Components.SubscriberDescriptionHelper.id(),
118                                new SubscriberDescriptionFactory());
119     }
120
121     /**
122      ** Create the OpenCCM::HomeManager.
123      **/

124     protected static void
125     create_home_manager()
126     {
127     // TODO: Must be reviewed to be configurable!!!
128
// e.g. Local or Remote or Trader or ...
129
HomeManagerImpl manager = new HomeManagerImpl();
130
131     // TODO: Must be changed!!!
132
org.omg.CORBA.Object JavaDoc ref = manager._this_object(org.objectweb.openccm.corba.TheORB.getORB());
133     HomeManager managerRef = HomeManagerHelper.narrow(ref);
134
135     // Set the HomeManager singleton reference.
136
home_manager_ = managerRef;
137
138     // Register the ComponentHomeFinder initial service.
139
org.objectweb.openccm.corba.TheORB.register_initial_reference(
140             "ComponentHomeFinder", managerRef);
141     }
142
143     // ==================================================================
144
//
145
// Public methods.
146
//
147
// ==================================================================
148

149     /**
150      ** Initialize the OpenCCM Abstract Model runtime, i.e.
151      ** register valuetype factories,
152      ** create the OpenCCM::HomeManager (HomeFinder and HomeRegister).
153      **/

154     public static void
155     init()
156     {
157     if(already_initialized_ == false)
158     {
159         // Register valuetype factories.
160
register_valuetype_factories();
161
162         // Create the HomeManager.
163
create_home_manager();
164
165         already_initialized_ = true;
166     }
167     }
168
169     /**
170      ** Initialize the OpenCCM Abstract Model runtime, i.e.
171      ** register valuetype factories,
172      ** create the Components::HomeFinder and HomeRegister.
173      **
174      ** @param orb The ORB reference.
175      **/

176     public static void
177     init(org.omg.CORBA.ORB JavaDoc orb)
178     {
179     // Set the ORB singleton reference.
180
org.objectweb.openccm.corba.TheORB.setORB(orb);
181
182     // Init the runtime.
183
init();
184     }
185
186     /**
187      ** Initialize the OpenCCM Abstract Model runtime, i.e.
188      ** initialize the ORB,
189      ** register valuetype factories,
190      ** create the Components::HomeFinder and HomeRegister.
191      **
192      ** @param args The command line arguments.
193      **
194      ** @return The ORB reference.
195      **/

196     public static org.omg.CORBA.ORB JavaDoc
197     init(String JavaDoc[] args)
198     {
199     // Init the ORB.
200
org.objectweb.openccm.corba.TheORB.initialize(args);
201
202     // Init the runtime.
203
init();
204
205     // return the ORB.
206
return org.objectweb.openccm.corba.TheORB.getORB();
207     }
208
209     /**
210      ** Register a valuetype factory.
211      **
212      ** @param id The valuetype repository Id.
213      ** @param factory The valuetype factory.
214      **/

215     public static void
216     register_value_factory(String JavaDoc id,
217                            org.omg.CORBA.portable.ValueFactory JavaDoc factory)
218     {
219         org.objectweb.openccm.corba.TheORB.register_value_factory(id, factory);
220     }
221
222     /**
223      **
224      **/

225     public static HomeManager
226     get_home_manager()
227     {
228         return home_manager_;
229     }
230 }
231
Popular Tags