KickJava   Java API By Example, From Geeks To Geeks.

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


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>.</p>
36  **/

37 public class ContainerImpl
38 extends org.omg.CORBA.LocalObject JavaDoc
39 implements Servant, org.omg.Components.Deployment.ContainerOperations
40 {
41     // component server
42
static private String JavaDoc _class_name = "ContainerImpl";
43     static final private String JavaDoc _type_id = org.omg.Components.Deployment.ContainerHelper.id();
44     private ORBService _orb_service;
45     private String JavaDoc _ns_sref;
46     private String JavaDoc _extci_sref;
47     private java.util.ArrayList JavaDoc _home_refs; // (list of ::Components::CCMHome)
48
private org.omg.Components.ConfigValue[] _configuration;
49     private org.omg.Components.Deployment.ComponentServer _cs_ref;
50
51     // default constructor
52
public
53     ContainerImpl()
54     {
55         // component server
56
_orb_service = null;
57         _ns_sref = null;
58         _extci_sref = null;
59         _home_refs = new java.util.ArrayList JavaDoc();
60         _configuration = new org.omg.Components.ConfigValue[0];
61         _cs_ref = null;
62     }
63
64     //
65
// Entry point
66
//
67

68     static public Servant
69     create_servant()
70     {
71         return new ContainerImpl();
72     }
73
74     //
75
// internal operations
76
//
77

78     //
79
// IDL:org/objectweb/corba/runtime/SystemComponent:1.0
80
//
81

82     final public void
83     system_configuration_complete(SystemConfiguration cfg)
84     {
85         // obtain services
86
ServantConfiguration scfg = (ServantConfiguration)cfg;
87         _orb_service = scfg.orb_service();
88
89         // extract references which must be passed to the services set
90
org.omg.CORBA.Object JavaDoc obj = null;
91         // extract NS ref
92
obj = _orb_service.resolve_initial_references("NameService");
93
94         // check if found
95
if (obj==null) {
96             // NOTE: should not happen
97
final String JavaDoc opname = "system_configuration_complete";
98             final String JavaDoc msg = "FAILED (NS not found)";
99             TheLogger.error(_class_name, opname, msg);
100             return ;
101         }
102
103         _ns_sref = _orb_service.object_to_string(obj);
104
105         // extract ExtCI ref
106
obj = _orb_service.resolve_initial_references("ExtComponentInstallation");
107
108         // check if found
109
if (obj==null) {
110             // NOTE: should not happen
111
final String JavaDoc opname = "system_configuration_complete";
112             final String JavaDoc msg = "FAILED (ExtCI not found)";
113             TheLogger.error(_class_name, opname, msg);
114             return ;
115         }
116
117         _extci_sref = _orb_service.object_to_string(obj);
118
119         // NOTE: how is the ComponentActivator reference obtained ?
120
// - using the (local) name service
121
// - using a config value
122
// - using the system configuration
123
// - other ?
124

125     }
126
127     final public void
128     destroy()
129     {
130         // destroy all installed home
131
org.omg.Components.CCMHome[] refs = get_homes();
132         for (int i=0;i<refs.length;i++) {
133             try {
134                 //
135
refs[i].remove_home();
136
137                 // NOTE: TODO: deactivate home servants
138
} catch (org.omg.Components.RemoveFailure ex) {
139                 // ignore
140
final String JavaDoc opname = "destroy";
141                 TheLogger.debug(_class_name, opname, "IGNORE", ex);
142                 return ;
143             }
144         }
145
146         // clear list
147
_home_refs.clear();
148     }
149
150     //
151
// IDL:org/objectweb/corba/runtime/Servant:1.0
152
//
153

154     final public String JavaDoc
155     type_id()
156     {
157         return _type_id;
158     }
159
160     final public org.omg.PortableServer.Servant JavaDoc
161     as_native_servant()
162     {
163         return new org.omg.Components.Deployment.ContainerPOATie(this);
164     }
165
166     //
167
// IDL:omg.org/Components/Deployment/Container:1.0
168
//
169

170     final public org.omg.Components.ConfigValue[]
171     configuration()
172     {
173         return _configuration;
174     }
175
176     final public org.omg.Components.Deployment.ComponentServer
177     get_component_server()
178     {
179         return _cs_ref;
180     }
181
182     final public org.omg.Components.CCMHome
183     install_home(String JavaDoc uuid, String JavaDoc entrypt, org.omg.Components.ConfigValue[] config)
184     throws org.omg.Components.Deployment.UnknownImplId,
185            org.omg.Components.Deployment.ImplEntryPointNotFound,
186            org.omg.Components.Deployment.InstallationFailure,
187            org.omg.Components.Deployment.InvalidConfiguration
188     {
189         // extract configvalues infos: none at present
190

191         // build configuration
192
ComponentRuntimeConfiguration cfg = new ComponentRuntimeConfiguration();
193
194         // NOTE: need to propagate the ExtCI and NS refs
195
org.coach.ECM.DegeneratedServiceRef[] dsrefs = new org.coach.ECM.DegeneratedServiceRef[2];
196         dsrefs[0] = new org.coach.ECM.DegeneratedServiceRef();
197         dsrefs[0].orb_registration_name = "NameService";
198         dsrefs[0].initial_reference = _ns_sref;
199         dsrefs[1] = new org.coach.ECM.DegeneratedServiceRef();
200         dsrefs[1].orb_registration_name = "ExtComponentInstallation";
201         dsrefs[1].initial_reference = _extci_sref;
202         cfg.dservice_refs = dsrefs;
203
204         cfg.orb_service = _orb_service;
205         cfg.implementation_uuid = uuid;
206
207         // delegate to component runtime
208
org.omg.Components.CCMHome href = ComponentRuntime.loadHome(cfg);
209
210         // store
211
_home_refs.add(href);
212
213         return href;
214     }
215
216     final public void
217     remove_home(org.omg.Components.CCMHome href)
218     throws org.omg.Components.RemoveFailure
219     {
220         // remove from storage
221
org.omg.Components.CCMHome[] refs = get_homes();
222         int i=0;
223         for (;i<refs.length;i++) {
224             if (href._is_equivalent(refs[i])) {
225                 _home_refs.remove(i);
226
227                 // NOTE: only call remove on the container if it was found
228
href.remove_home();
229
230                 // NOTE: TODO: deactivate home servant
231
break;
232             }
233         }
234
235         // if it wasn't found, report removal failure
236
if (i==refs.length) {
237             throw new org.omg.Components.RemoveFailure();
238         }
239     }
240
241     final public org.omg.Components.CCMHome[]
242     get_homes()
243     {
244         return (org.omg.Components.CCMHome[])_home_refs.toArray(new org.omg.Components.CCMHome[0]);
245     }
246
247     final public void
248     remove()
249     throws org.omg.Components.RemoveFailure
250     {
251         // destroy
252
destroy();
253     }
254 }
255
Popular Tags