KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > runtime > ComponentRuntime


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@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.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.ccm.runtime;
31
32 import org.objectweb.corba.runtime.*;
33
34 /**
35  ** <p>The <tt>ComponentRuntime</tt> class provides the bootstrapping feature for a CCM home implemented
36  ** using the system component based framework. It also relies on the fundamental CORBA runtime features.</p>
37  **
38  ** @see org.objectweb.corba.runtime.Runtime Runtime
39  **/

40 public class ComponentRuntime
41 {
42     static private String JavaDoc _class_name = "ComponentRuntime";
43     static private SlotFactory _slot_factory;
44     static private ContainerFactoryImpl _container_factory;
45     // NOTE: stores the main orb instance
46
static private org.omg.CORBA.ORB JavaDoc _orb;
47
48     static {
49         // create the slot factory
50
_slot_factory = new SlotFactory();
51
52         // create container factory
53
_container_factory = (ContainerFactoryImpl)ContainerFactoryImpl.create_factory();
54
55         // register component poa service factory
56
String JavaDoc entrypt = "org.objectweb.ccm.runtime.ComponentPOAFactoryImpl.create_factory";
57         getFFService().register_service_factory(ComponentPOAService.SERVICE_ID, null, entrypt);
58
59         // add various valuetypes factories to the ORB service factory
60
ORBFactory fact = (ORBFactory)getFFService().find_service_factory(ORBService.SERVICE_ID);
61
62         // Cookie
63
String JavaDoc tid = org.omg.Components.CookieHelper.id();
64         org.omg.CORBA.portable.ValueFactory JavaDoc pfact = new CookieFactoryImpl();
65         ValueFactory vfact = new ValueFactoryImpl(tid, pfact);
66         fact.add_default_valuefactory(vfact);
67
68         // NOTE: others factories are registered by the home servant as there're specific to its implementation
69
// or by the deployment servant for the same reason
70

71         _orb = null;
72     }
73
74     //
75
// public operations
76
//
77

78     static public FactoryFinderService
79     getFFService()
80     {
81         return org.objectweb.corba.runtime.Runtime.getFFService();
82     }
83
84     static public RegistrationService
85     getRegistrationService()
86     {
87         return org.objectweb.corba.runtime.Runtime.getRegistrationService();
88     }
89
90     static public MainThread
91     getMainThread()
92     {
93         return org.objectweb.corba.runtime.Runtime.getMainThread();
94     }
95
96     static public SlotFactory
97     getSlotFactory()
98     {
99         return _slot_factory;
100     }
101
102     static public ContainerFactoryImpl
103     getContainerFactory()
104     {
105         return _container_factory;
106     }
107
108     static public org.omg.CORBA.ORB JavaDoc
109     getORB()
110     {
111         return _orb;
112     }
113
114     static public org.omg.Components.CCMHome
115     loadHome(ComponentRuntimeConfiguration config)
116     {
117         final String JavaDoc opname = "loadHome";
118
119         // build home servant configuration
120
// build container service from configuration
121
ContainerService conts = null;
122         String JavaDoc poasid = ComponentPOAService.SERVICE_ID;
123         if (config.orb_service!=null) {
124             // case with pre-existing ORB service
125
conts = _container_factory.asContainerService(config.service_uuids, config.dservice_refs, config.orb_service, poasid);
126         }
127         else {
128             // case with no pre-existing ORB service and a pre-existing ExtCI
129
conts = _container_factory.asContainerService(config.service_uuids, config.dservice_refs, config.initial_references, poasid);
130         }
131
132         // set as ORB singleton
133
try {
134             ORBServiceImpl orbimpl = (ORBServiceImpl)conts.orb_service();
135             _orb = orbimpl.getORB();
136         } catch (ClassCastException JavaDoc ex) {
137             // ignore
138
}
139
140         org.omg.Components.CCMHome href = null;
141         href = conts.component_poa_service().activate_home(config.implementation_uuid);
142
143         // try to store in local file and in ns
144
RegistrationService regs = getRegistrationService();
145         // check if a IOR file is set
146
String JavaDoc iorfile = config.runtime_iorfile;
147         if (iorfile!=null) {
148             // obtain file registration scheme
149
FileRegistrationScheme filescheme = (FileRegistrationScheme)regs.get_scheme(FileRegistrationScheme.SCHEME_ID);
150             filescheme.write_ior(iorfile, href, conts.orb_service());
151         }
152
153         // obtain ns name from properties (always set)
154
String JavaDoc insname = config.runtime_id;
155         INSRegistrationScheme insscheme = (INSRegistrationScheme)regs.get_scheme(INSRegistrationScheme.SCHEME_ID);
156         insscheme.bind(insname, href, conts.orb_service());
157
158         //
159
return href;
160     }
161 }
162
Popular Tags