KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > portableInterceptor > ORBInitInfoImpl


1 package org.jacorb.orb.portableInterceptor;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import org.omg.PortableInterceptor.*;
24 import org.omg.PortableInterceptor.ORBInitInfoPackage.*;
25 import org.omg.CORBA.Object JavaDoc;
26 import org.omg.IOP.CodecFactory JavaDoc;
27
28 import java.util.*;
29
30 import org.jacorb.orb.ORB;
31
32 /**
33  * This class represents the type of info object
34  * that will be passed to the ORBInitializers. <br>
35  * See PI Spec p. 9-70ff
36  *
37  * @author Nicolas Noffke
38  * @version $Id: ORBInitInfoImpl.java,v 1.13 2004/10/18 11:07:31 simon.mcqueen Exp $
39  */

40
41 public class ORBInitInfoImpl
42     extends org.omg.CORBA.LocalObject JavaDoc
43     implements ORBInitInfo
44 {
45     private int slot_count = 0;
46     private ORB orb = null;
47
48     private Hashtable named_server_interceptors = null;
49     private Vector anonymous_server_interceptors = null;
50
51     private Hashtable named_client_interceptors = null;
52     private Vector anonymous_client_interceptors = null;
53
54     private Hashtable named_ior_interceptors = null;
55     private Vector anonymous_ior_interceptors = null;
56
57     private Hashtable policy_factories = null;
58
59     private boolean valid = true;
60
61     public ORBInitInfoImpl(ORB orb)
62     {
63         this.orb = orb;
64         
65         named_server_interceptors = new Hashtable();
66         named_client_interceptors = new Hashtable();
67
68         anonymous_server_interceptors = new Vector();
69         anonymous_client_interceptors = new Vector();
70
71         named_ior_interceptors = new Hashtable();
72         anonymous_ior_interceptors = new Vector();
73     
74         policy_factories = new Hashtable();
75     
76     }
77
78     /**
79      * This method is for interceptors that need access to the ORB.
80      * Be careful with that since there is a reason, why there is no
81      * other way to get acces to the ORB.
82      */

83     public ORB getORB()
84     {
85         return orb;
86     }
87
88     public void setInvalid()
89     {
90         valid = false;
91     }
92
93     /**
94      * Copies the elements of a Hashtable into
95      * a Vector.
96      */

97
98     private void merge(Vector target, Hashtable source)
99     {
100         Enumeration enumeration = source.elements();
101
102         while(enumeration.hasMoreElements())
103             target.addElement(enumeration.nextElement());
104     }
105
106     public Vector getClientInterceptors()
107     {
108         merge(anonymous_client_interceptors,
109               named_client_interceptors);
110     
111         return anonymous_client_interceptors;
112     }
113
114     public Vector getServerInterceptors()
115     {
116         merge(anonymous_server_interceptors,
117               named_server_interceptors);
118     
119         return anonymous_server_interceptors;
120     }
121
122     public Vector getIORInterceptors()
123     {
124         merge(anonymous_ior_interceptors,
125               named_ior_interceptors);
126     
127         return anonymous_ior_interceptors;
128     }
129
130     public Hashtable getPolicyFactories()
131     {
132         return policy_factories;
133     }
134
135     public int getSlotCount()
136     {
137         return slot_count;
138     }
139
140     // implementation of org.omg.PortableInterceptor.ORBInitInfoOperations interface
141
public void add_client_request_interceptor(ClientRequestInterceptor interceptor)
142         throws DuplicateName
143     {
144
145         if (! valid)
146             throw new org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc("This ORBInitIfo is not valid anymore!");
147         
148         if (interceptor.name() == null)
149             throw new DuplicateName("The name is null!");
150
151         if (interceptor.name().length() == 0)
152             anonymous_client_interceptors.addElement(interceptor);
153         else
154         {
155             if (named_client_interceptors.containsKey(interceptor.name()))
156                 throw new DuplicateName(interceptor.name());
157
158             named_client_interceptors.put(interceptor.name(), interceptor);
159         }
160     }
161   
162     public void add_ior_interceptor(IORInterceptor interceptor)
163         throws DuplicateName
164     {
165
166         if (interceptor.name() == null)
167             throw new DuplicateName("The name is null!");
168
169         if (interceptor.name().length() == 0)
170             anonymous_ior_interceptors.addElement(interceptor);
171         else
172         {
173             if (named_ior_interceptors.containsKey(interceptor.name()))
174                 throw new DuplicateName(interceptor.name());
175
176             named_ior_interceptors.put(interceptor.name(), interceptor);
177         }
178     }
179   
180     public void add_server_request_interceptor(ServerRequestInterceptor interceptor)
181         throws DuplicateName
182     {
183
184         if (! valid)
185             throw new org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc("This ORBInitIfo is not valid anymore!");
186
187         if (interceptor.name() == null)
188             throw new DuplicateName("The name is null!");
189
190         if (interceptor.name().length() == 0)
191             anonymous_server_interceptors.addElement(interceptor);
192         else {
193             if (named_server_interceptors.containsKey(interceptor.name()))
194                 throw new DuplicateName(interceptor.name());
195
196             named_server_interceptors.put(interceptor.name(), interceptor);
197         }
198     }
199   
200     public int allocate_slot_id()
201     {
202         if (! valid)
203             throw new org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc("This ORBInitIfo is not valid anymore!");
204
205         return slot_count++;
206     }
207
208     public String JavaDoc[] arguments()
209     {
210         if (! valid)
211             throw new org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc("This ORBInitIfo is not valid anymore!");
212         return orb._args ;
213     }
214
215     public CodecFactory JavaDoc codec_factory()
216     {
217         if (! valid)
218             throw new org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc("This ORBInitIfo is not valid anymore!");
219
220         try
221         {
222             return (CodecFactory JavaDoc) orb.resolve_initial_references("CodecFactory");
223         }
224         catch (Exception JavaDoc e)
225         {
226             //shouldn't happen anyway
227
}
228         return null;
229     }
230
231     public String JavaDoc orb_id()
232     {
233         if (! valid)
234             throw new org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc("This ORBInitIfo is not valid anymore!");
235         return orb.orb_id;
236     }
237
238     public void register_initial_reference( String JavaDoc id, Object JavaDoc obj )
239         throws InvalidName
240     {
241         if (! valid)
242             throw new org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc("This ORBInitIfo is not valid anymore!");
243       
244         try
245         {
246             orb.register_initial_reference(id, obj);
247         }
248         catch(org.omg.CORBA.ORBPackage.InvalidName JavaDoc e)
249         {
250             throw new InvalidName();
251         }
252     }
253
254     public void register_policy_factory(int type, PolicyFactory policy_factory)
255     {
256         if (! valid)
257             throw new org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc("This ORBInitIfo is not valid anymore!");
258       
259         if (policy_factory == null)
260             throw new org.omg.CORBA.BAD_PARAM JavaDoc("Actual parameter policy_factory is null!");
261
262         Integer JavaDoc key = new Integer JavaDoc(type);
263         if (policy_factories.containsKey(key))
264             throw new org.omg.CORBA.BAD_INV_ORDER JavaDoc("A PolicyFactory for type " + type +
265                                                   " has already been registered!", 12,
266                                                   org.omg.CORBA.CompletionStatus.
267                                                   COMPLETED_MAYBE);
268       
269         policy_factories.put(key, policy_factory);
270     }
271
272
273     public org.omg.CORBA.Object JavaDoc resolve_initial_references(String JavaDoc id)
274         throws InvalidName
275     {
276         if (! valid)
277             throw new org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc("This ORBInitIfo is not valid anymore!");
278
279         try
280         {
281             return orb.resolve_initial_references(id);
282         }
283         catch(org.omg.CORBA.ORBPackage.InvalidName JavaDoc e)
284         {
285             throw new InvalidName();
286         }
287     }
288 } // ORBInitInfoImpl
289

290
291
292
293
294
295
Popular Tags