KickJava   Java API By Example, From Geeks To Geeks.

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


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>Default implementation of the <tt>ECA::ServiceInitInfo</tt> interface.</p>
36  **/

37 public class ServiceInitInfoImpl
38 extends org.omg.CORBA.LocalObject JavaDoc
39 implements org.coach.ECA.ServiceInitInfo
40 {
41     //
42
private String JavaDoc _class_name = "ServiceInitInfoImpl";
43     private ORBService _orb_service;
44     private java.util.Hashtable JavaDoc _orb_inits; // (ECM::ServiceId, String)
45
private java.util.Hashtable JavaDoc _value_factories; // (repid, ::ccm::runtime::ValueFactory)
46
private java.util.Hashtable JavaDoc _policy_factories; // (ECA::PolicyType, ECA::PolicyFactory)
47
private java.util.Hashtable JavaDoc _services; // (ECM::ServiceId, ::ccm::runtime::Service)
48
private java.util.Hashtable JavaDoc _initial_references; // (string, CORBA::Object)
49
private java.util.Hashtable JavaDoc _stringified_initial_references; // (string, string)
50

51     public
52     ServiceInitInfoImpl(ServiceImpl[] services,
53                         CORBAServiceRef[] degenservices)
54     {
55         _orb_service = null;
56         _orb_inits = new java.util.Hashtable JavaDoc();
57         _value_factories = new java.util.Hashtable JavaDoc();
58         _policy_factories = new java.util.Hashtable JavaDoc();
59         _services = new java.util.Hashtable JavaDoc();
60         _initial_references = new java.util.Hashtable JavaDoc();
61         _stringified_initial_references = new java.util.Hashtable JavaDoc();
62
63         CORBAServiceRef csref = null;
64         for (int i=0;i<services.length;i++) {
65             csref = services[i].getCorbaServiceRef();
66             if (csref!=null) {
67                 if (csref.initial_reference!=null) {
68                     _initial_references.put(csref.orb_registration_name, csref.initial_reference);
69                 }
70                 else {
71                     _stringified_initial_references.put(csref.orb_registration_name, csref.stringified_initial_reference);
72                 }
73             }
74             
75
76             _services.put(services[i].service_id(), services[i]);
77         }
78
79         for (int i=0;i<degenservices.length;i++) {
80             csref = degenservices[i];
81             if (csref.initial_reference!=null) {
82                 _initial_references.put(csref.orb_registration_name, csref.initial_reference);
83             }
84             else {
85                 _stringified_initial_references.put(csref.orb_registration_name, csref.stringified_initial_reference);
86             }
87         }
88     }
89
90     //
91
// public operations
92
//
93

94     final public void
95     setORBService(ORBService orbs)
96     {
97         _orb_service = orbs;
98     }
99
100     final public ORBConfiguration
101     getORBConfiguration()
102     {
103         // orb initializer
104
String JavaDoc[] inits = (String JavaDoc[])_orb_inits.values().toArray(new String JavaDoc[0]);
105
106         // value factories
107
ValueFactory[] vfacts = (ValueFactory[])_value_factories.values().toArray(new ValueFactory[0]);
108
109         // initial references
110
String JavaDoc[] names = (String JavaDoc[])_initial_references.keySet().toArray(new String JavaDoc[0]);
111         org.omg.CORBA.Object JavaDoc[] refs = (org.omg.CORBA.Object JavaDoc[])_initial_references.values().toArray(new org.omg.CORBA.Object JavaDoc[0]);
112         InitialReference[] irefs = new InitialReference[names.length];
113
114         for (int i=0;i<names.length;i++) {
115             irefs[i] = new InitialReference();
116             irefs[i].name = names[i];
117             irefs[i].ref = refs[i];
118         }
119
120         // stringified initial references
121
names = (String JavaDoc[])_stringified_initial_references.keySet().toArray(new String JavaDoc[0]);
122         String JavaDoc[] srefs = (String JavaDoc[])_stringified_initial_references.values().toArray(new String JavaDoc[0]);
123         StringifiedInitialReference[] sirefs = new StringifiedInitialReference[names.length];
124
125         for (int i=0;i<names.length;i++) {
126             sirefs[i] = new StringifiedInitialReference();
127             sirefs[i].name = names[i];
128             sirefs[i].ref = srefs[i];
129         }
130
131         return new ORBConfigurationImpl(inits, vfacts, irefs, sirefs);
132     }
133
134     //
135
// IDL:coach.org/ECA/ServiceInitInfo:1.0
136
//
137

138     final public org.omg.CORBA.Object JavaDoc
139     resolve_initial_references(String JavaDoc name)
140     {
141         // TODO: trap some initial refs
142

143         // some initial references are available even if no ORB instance
144
// is set, these are
145
// - degenerated service initial references
146
// - initial references specified in usedservice/corbaserviceref element
147
org.omg.CORBA.Object JavaDoc ref = (org.omg.CORBA.Object JavaDoc)_initial_references.get(name);
148         if (ref!=null) {
149             return ref;
150         }
151
152         // check if ORB service set <=> post_install
153
if (_orb_service==null) {
154             // NOTE: TODO: should throw an exception instead (like in the PI)
155
final String JavaDoc opname = "resolve_initial_references";
156             final String JavaDoc msg = "IGNORE (operation can not be called in pre_install)";
157             TheLogger.debug(_class_name, opname, msg);
158             return null;
159         }
160
161         return _orb_service.resolve_initial_references(name);
162     }
163
164     final public org.omg.CORBA.Current JavaDoc
165     get_current(String JavaDoc cname)
166     {
167         // TODO: trap some currents
168

169         // check if ORB service set <=> post_install
170
if (_orb_service==null) {
171             final String JavaDoc opname = "get_current";
172             final String JavaDoc msg = "IGNORE (operation can not be called in pre_install)";
173             TheLogger.debug(_class_name, opname, msg);
174             return null;
175         }
176
177         return org.omg.CORBA.CurrentHelper.narrow(_orb_service.resolve_initial_references(cname));
178     }
179
180     final public void
181     register_orb_initializer(String JavaDoc sid, String JavaDoc orbinit)
182     {
183         // obtain Service for the service id
184
ServiceImpl sinst = (ServiceImpl)_services.get(sid);
185
186         // set orb init
187
sinst.setORBInitializer(orbinit);
188
189         // store
190
_orb_inits.put(sid, orbinit);
191     }
192
193     final public void
194     register_service_internal(String JavaDoc sid, String JavaDoc internal_id,
195                               org.omg.CORBA.Object JavaDoc internal)
196     {
197         // obtain Service for the service id
198
ServiceImpl sinst = (ServiceImpl)_services.get(sid);
199
200         // add internal
201
sinst.addServiceInternal(internal_id, internal);
202     }
203
204     final public void
205     register_controller_factory(String JavaDoc sid,
206                                 org.coach.ECA.CallControllerFactory fact)
207     {
208         // obtain Service for the service id
209
ServiceImpl sinst = (ServiceImpl)_services.get(sid);
210
211         // set factory
212
sinst.setCallControllerFactory(fact);
213     }
214
215     final public void
216     register_value_factory(String JavaDoc sid, String JavaDoc typeid,
217                            org.omg.CORBA.portable.ValueFactory JavaDoc fact)
218     {
219         // NOTE: are the value factories stored in the service ?
220
// is this of any use ??? (for clean removal of the service ?)
221

222         // create struct
223
ValueFactory vfact = new ValueFactoryImpl(typeid, fact);
224
225         // store
226
_value_factories.put(sid, vfact);
227     }
228
229     final public void
230     register_policy_factory(String JavaDoc sid, String JavaDoc ptype,
231                             org.coach.ECA.PolicyFactory fact)
232     {
233         // obtain Service for the service id
234
ServiceImpl sinst = (ServiceImpl)_services.get(sid);
235
236         // add policy factory
237
sinst.addPolicyFactory(ptype, fact);
238     }
239 }
240
Popular Tags