1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44:
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60:
61: import ;
62: import ;
63: import ;
64: import ;
65:
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73:
74:
81: public class Registrator extends LocalObject implements ORBInitInfo
82: {
83:
86: private static final long serialVersionUID = 1;
87:
88:
91: public static final String m_prefix =
92: "org.omg.PortableInterceptor.ORBInitializerClass.";
93:
94:
97: private ArrayList m_server = new ArrayList();
98:
99:
102: private ArrayList m_client = new ArrayList();
103:
104:
107: private ArrayList m_ior = new ArrayList();
108:
109:
112: public Hashtable m_policyFactories = new Hashtable();
113:
114:
119: public TreeMap m_references = new TreeMap();
120:
121:
124: public ArrayList m_initializers = new ArrayList();
125:
126:
129: final ORB_1_4 orb;
130:
131:
134: final String[] m_args;
135:
136:
139: final gnuCodecFactory m_codecFactory;
140:
141:
150: public Registrator(ORB_1_4 an_orb, Properties props, String[] an_args)
151: {
152: orb = an_orb;
153: m_args = an_args;
154: m_codecFactory = new gnuCodecFactory(orb);
155: checkProperties(props);
156: checkProperties(System.getProperties());
157: checkFile("user.home", null);
158: checkFile("java.home", "lib");
159: }
160:
161:
164: private void checkProperties(Properties props)
165: {
166: if (props == null)
167: {
168: return;
169: }
170:
171: Enumeration names = props.propertyNames();
172: java.lang.Object key;
173: String sk;
174:
175: while (names.hasMoreElements())
176: {
177: key = names.nextElement();
178: if (key != null)
179: {
180: sk = key.toString();
181: if (sk.startsWith(m_prefix))
182: {
183: try
184: {
185: String cn = sk.substring(m_prefix.length());
186: Class iClass = ObjectCreator.forName(cn);
187:
188: ORBInitializer initializer =
189: (ORBInitializer) iClass.newInstance();
190: m_initializers.add(initializer);
191: }
192: catch (Exception exc)
193: {
194:
195:
196:
197:
198: System.err.println(sk + " failed");
199: }
200: }
201: }
202: }
203: }
204:
205:
208: private void checkFile(String dir, String subdir)
209: {
210: try
211: {
212: File f = new File(dir);
213: if (!f.exists())
214: {
215: return;
216: }
217:
218: if (subdir != null)
219: {
220: f = new File(f, subdir);
221: }
222: f = new File(f, "orb.properties");
223:
224: if (!f.exists())
225: {
226: return;
227: }
228:
229: Properties p = new Properties();
230: p.load(new BufferedInputStream(new FileInputStream(f)));
231:
232: checkProperties(p);
233: }
234: catch (IOException ex)
235: {
236: }
237: }
238:
239:
242: public void pre_init()
243: {
244: Iterator iter = m_initializers.iterator();
245: while (iter.hasNext())
246: {
247: ORBInitializerOperations initializer =
248: (ORBInitializerOperations) iter.next();
249: initializer.pre_init(this);
250: }
251: }
252:
253:
257: public Map getRegisteredReferences()
258: {
259: return m_references;
260: }
261:
262:
266: public void post_init()
267: {
268: Iterator iter = m_initializers.iterator();
269: while (iter.hasNext())
270: {
271: ORBInitializerOperations initializer =
272: (ORBInitializerOperations) iter.next();
273: initializer.post_init(this);
274: }
275: }
276:
277: public ServerRequestInterceptor[] getServerRequestInterceptors()
278: {
279: ServerRequestInterceptor[] iServer =
280: new ServerRequestInterceptor[ m_server.size() ];
281: for (int i = 0; i < iServer.length; i++)
282: {
283: iServer [ i ] = (ServerRequestInterceptor) m_server.get(i);
284: }
285: return iServer;
286: }
287:
288: public ClientRequestInterceptor[] getClientRequestInterceptors()
289: {
290: ClientRequestInterceptor[] iClient =
291: new ClientRequestInterceptor[ m_client.size() ];
292: for (int i = 0; i < iClient.length; i++)
293: {
294: iClient [ i ] = (ClientRequestInterceptor) m_client.get(i);
295: }
296: return iClient;
297: }
298:
299: public IORInterceptor[] getIORInterceptors()
300: {
301: IORInterceptor[] iIor = new IORInterceptor[ m_ior.size() ];
302: for (int i = 0; i < iIor.length; i++)
303: {
304: iIor [ i ] = (IORInterceptor) m_ior.get(i);
305: }
306: return iIor;
307: }
308:
309: public void add_client_request_interceptor(
310: ClientRequestInterceptor interceptor
311: ) throws DuplicateName
312: {
313: add(m_client, interceptor);
314: }
315:
316: public void add_ior_interceptor(IORInterceptor interceptor)
317: throws DuplicateName
318: {
319: add(m_ior, interceptor);
320: }
321:
322: public void add_server_request_interceptor(
323: ServerRequestInterceptor interceptor
324: ) throws DuplicateName
325: {
326: add(m_server, interceptor);
327: }
328:
329:
332: public int allocate_slot_id()
333: {
334: return orb.icSlotSize++;
335: }
336:
337:
343: private void add(ArrayList list, Interceptor interceptor)
344: throws DuplicateName
345: {
346: if (interceptor.name().length() > 0)
347: {
348: Iterator iter = list.iterator();
349: Interceptor ic;
350:
351: while (iter.hasNext())
352: {
353: ic = (Interceptor) iter.next();
354: if (ic.name().equals(interceptor.name()))
355: {
356: throw new DuplicateName(interceptor.name());
357: }
358: }
359: }
360: list.add(interceptor);
361: }
362:
363:
366: public String[] arguments()
367: {
368: return m_args;
369: }
370:
371:
374: public CodecFactory codec_factory()
375: {
376: return m_codecFactory;
377: }
378:
379:
382: public String orb_id()
383: {
384: return "orb_" + orb;
385: }
386:
387:
390: public void register_initial_reference(String object_name, Object object)
391: throws InvalidName
392: {
393: if (object_name == null)
394: {
395: throw new InvalidName("null");
396: }
397: else if (object_name.length() == 0)
398: {
399: throw new InvalidName("Empty string");
400: }
401: else if (m_references.containsKey(object_name))
402: {
403: throw new InvalidName(object_name);
404: }
405: else
406: {
407: m_references.put(object_name, object);
408: }
409: }
410:
411:
414: public void register_policy_factory(int policy_type,
415: PolicyFactory policy_factory
416: )
417: {
418: Integer it = new Integer(policy_type);
419: if (m_policyFactories.containsKey(it))
420: {
421: throw new BAD_INV_ORDER(
422: "Repetetive registration of the policy factory for type " +
423: policy_type,
424: 16,
425: CompletionStatus.COMPLETED_NO
426: );
427: }
428: m_policyFactories.put(it, policy_factory);
429: }
430:
431:
434: public org.omg.CORBA.Object resolve_initial_references(String object_name)
435: throws InvalidName
436: {
437: try
438: {
439: return orb.resolve_initial_references(object_name);
440: }
441: catch (org.omg.CORBA.ORBPackage.InvalidName e)
442: {
443: InvalidName in = new InvalidName(e.getMessage());
444: in.initCause(e);
445: throw in;
446: }
447: }
448:
449:
452: public boolean hasClientRequestInterceptors()
453: {
454: return m_client.size() > 0;
455: }
456:
457:
460: public boolean hasServerRequestInterceptors()
461: {
462: return m_server.size() > 0;
463: }
464:
465:
468: public boolean hasIorInterceptors()
469: {
470: return m_ior.size() > 0;
471: }
472: }