KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > runtime > ORBServiceImpl


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.corba.runtime;
31
32 /**
33  ** <p>Default implementation of the <tt>ORBService</tt> system service.</p>
34  **/

35 public class ORBServiceImpl
36 extends org.omg.CORBA.LocalObject JavaDoc
37 implements ORBService
38 {
39     // orb service
40
static final private String JavaDoc _class_name = "ORBServiceImpl";
41     static final private String JavaDoc _service_id = ORBService.SERVICE_ID;
42     private org.omg.CORBA.ORB JavaDoc _orb;
43     private java.util.Hashtable JavaDoc _initial_references;
44
45     // default constructor
46
protected
47     ORBServiceImpl(org.omg.CORBA.ORB JavaDoc orb)
48     {
49         // orb service
50
_orb = orb;
51         _initial_references = null;
52     }
53
54     //
55
// internal operations
56
//
57

58
59     //
60
// public operations
61
//
62

63     final public org.omg.CORBA.ORB JavaDoc
64     getORB()
65     {
66         return _orb;
67     }
68
69     //
70
// IDL:objectweb.org/corba/runtime/SystemComponent:1.0
71
//
72

73     final public void
74     system_configuration_complete(SystemConfiguration cfg)
75     {
76         _initial_references = new java.util.Hashtable JavaDoc();
77     }
78
79     final public void
80     destroy()
81     {
82         // NOTE: as destroy calls shutdown for 'wait_for_completion' param as true, we have
83
// to destroy the ORB before removing it from the main thread
84
// otherwise, the ORB will never have any time slot to finish its shutdown
85

86         // destroy ORB
87
_orb.shutdown(true);
88
89         // remove ORB from main thread
90
Runtime.getMainThread().stopORB(_orb);
91
92         // clean init ref table
93
_initial_references.clear();
94     }
95
96     //
97
// IDL:objectweb.org/corba/runtime/SystemService:1.0
98
//
99

100     final public String JavaDoc
101     service_id()
102     {
103         return _service_id;
104     }
105
106     //
107
// IDL:objectweb.org/corba/runtime/ORBService:1.0
108
//
109

110     final public org.omg.CORBA.Object JavaDoc
111     string_to_object(String JavaDoc str)
112     {
113         // always use extracted IOR (to handle file: or http: IORs)
114
return _orb.string_to_object(ORBFactoryImpl.extractIOR(str));
115     }
116
117     final public String JavaDoc
118     object_to_string(org.omg.CORBA.Object JavaDoc obj)
119     {
120         return _orb.object_to_string(obj);
121     }
122
123     final public org.omg.CORBA.Any JavaDoc
124     create_any()
125     {
126         return _orb.create_any();
127     }
128
129     final public org.omg.CORBA.Policy JavaDoc
130     create_policy(int type, org.omg.CORBA.Any JavaDoc value)
131     {
132         try {
133             return _orb.create_policy(type, value);
134         } catch (org.omg.CORBA.PolicyError JavaDoc ex) {
135             // ignore
136
final String JavaDoc opname = "create_policy";
137             TheLogger.debug(_class_name, opname, "IGNORE", ex);
138             return null;
139         }
140     }
141
142     final public java.io.Serializable JavaDoc
143     create_valuetype(String JavaDoc repid)
144     {
145         final String JavaDoc opname = "create_valuetype";
146
147         // find ValueFactory
148
org.omg.CORBA_2_3.ORB JavaDoc orb23 = (org.omg.CORBA_2_3.ORB JavaDoc)_orb;
149         org.omg.CORBA.portable.ValueFactory JavaDoc vfact = orb23.lookup_value_factory(repid);
150
151         // check if found
152
if (vfact==null) {
153             final String JavaDoc msg = "IGNORE (no factory for: "+repid+")";
154             TheLogger.debug(_class_name, opname, msg);
155             return null;
156         }
157
158         // try to create new instance
159
// assume "create_valuetype" as operation name
160
String JavaDoc opn = "create_valuetype";
161         try {
162             java.lang.reflect.Method JavaDoc op = null;
163             op = vfact.getClass().getMethod(opn, new Class JavaDoc[0]);
164             return (java.io.Serializable JavaDoc)op.invoke(null, new Object JavaDoc[0]);
165         } catch (NoSuchMethodException JavaDoc ex) {
166             final String JavaDoc msg = "IGNORE (no \"create_valuetype\" operation for: "+repid+")";
167             TheLogger.debug(_class_name, opname, msg, ex);
168             return null;
169         } catch (Exception JavaDoc ex) {
170             TheLogger.debug(_class_name, opname, "IGNORE", ex);
171             return null;
172         }
173     }
174
175     final public void
176     register_valuefactory(ValueFactory vfact)
177     {
178         org.omg.CORBA_2_3.ORB JavaDoc orb23 = (org.omg.CORBA_2_3.ORB JavaDoc)_orb;
179         orb23.register_value_factory(vfact.type_id(), vfact.value_factory());
180     }
181
182     final public org.omg.CORBA.portable.ValueFactory JavaDoc
183     get_valuefactory(String JavaDoc type_id)
184     {
185         org.omg.CORBA_2_3.ORB JavaDoc orb23 = (org.omg.CORBA_2_3.ORB JavaDoc)_orb;
186         return orb23.lookup_value_factory(type_id);
187     }
188
189     final public org.omg.CORBA.Object JavaDoc
190     resolve_initial_references(String JavaDoc name)
191     {
192         // first check the ORBService internal storage
193
org.omg.CORBA.Object JavaDoc res = (org.omg.CORBA.Object JavaDoc)_initial_references.get(name);
194         if (res!=null) {
195             return res;
196         }
197
198         // else ask the ORB itself
199
try {
200             return _orb.resolve_initial_references(name);
201         } catch (Exception JavaDoc ex) {
202             final String JavaDoc opname = "resolve_initial_references";
203             TheLogger.debug(_class_name, opname, "IGNORE", ex);
204             return null;
205         }
206     }
207
208     final public void
209     register_initial_references(String JavaDoc name, org.omg.CORBA.Object JavaDoc ref)
210     {
211         _initial_references.put(name, ref);
212     }
213
214     final public String JavaDoc[]
215     list_initial_references()
216     {
217         // NOTE: how do we obtain init ref from the ORB ??
218
// TODO
219

220         return (String JavaDoc[])_initial_references.keySet().toArray(new String JavaDoc[0]);
221     }
222 }
223
Popular Tags