KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > interceptors > ORBInitInfoImpl


1 /*
2  * @(#)ORBInitInfoImpl.java 1.26 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.interceptors;
9
10 import org.omg.CORBA.BAD_PARAM JavaDoc;
11 import org.omg.CORBA.BAD_INV_ORDER JavaDoc;
12 import org.omg.CORBA.CompletionStatus JavaDoc;
13 import org.omg.CORBA.NO_IMPLEMENT JavaDoc;
14 import org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc;
15 import org.omg.CORBA.LocalObject JavaDoc;
16 import org.omg.CORBA.Policy JavaDoc;
17 import org.omg.CORBA.PolicyError JavaDoc;
18 import org.omg.IOP.CodecFactory JavaDoc;
19 import org.omg.PortableInterceptor.ORBInitInfo JavaDoc;
20 import org.omg.PortableInterceptor.ClientRequestInterceptor JavaDoc;
21 import org.omg.PortableInterceptor.IORInterceptor JavaDoc;
22 import org.omg.PortableInterceptor.PolicyFactory JavaDoc;
23 import org.omg.PortableInterceptor.ServerRequestInterceptor JavaDoc;
24 import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName JavaDoc;
25 import org.omg.PortableInterceptor.ORBInitInfoPackage.InvalidName JavaDoc;
26
27 import com.sun.corba.se.spi.orb.ORB;
28 import com.sun.corba.se.spi.legacy.interceptor.ORBInitInfoExt ;
29 import com.sun.corba.se.spi.logging.CORBALogDomains;
30
31 import com.sun.corba.se.impl.orbutil.ORBUtility;
32
33 import com.sun.corba.se.impl.logging.InterceptorsSystemException;
34 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
35 import com.sun.corba.se.impl.logging.OMGSystemException;
36
37 /**
38  * ORBInitInfoImpl is the implementation of the ORBInitInfo class to be
39  * passed to ORBInitializers, as described in orbos/99-12-02.
40  */

41 public final class ORBInitInfoImpl
42     extends org.omg.CORBA.LocalObject JavaDoc
43     implements ORBInitInfo JavaDoc, ORBInitInfoExt
44 {
45     // The ORB we are initializing
46
private ORB orb;
47     
48     private InterceptorsSystemException wrapper ;
49     private ORBUtilSystemException orbutilWrapper ;
50     private OMGSystemException omgWrapper ;
51
52     // The arguments passed to ORB_init
53
private String JavaDoc[] args;
54
55     // The ID of the ORB being initialized
56
private String JavaDoc orbId;
57
58     // The CodecFactory
59
private CodecFactory JavaDoc codecFactory;
60
61     // The current stage of initialization
62
private int stage = STAGE_PRE_INIT;
63
64     // The pre-initialization stage (pre_init() being called)
65
public static final int STAGE_PRE_INIT = 0;
66
67     // The post-initialization stage (post_init() being called)
68
public static final int STAGE_POST_INIT = 1;
69
70     // Reject all calls - this object should no longer be around.
71
public static final int STAGE_CLOSED = 2;
72
73     // The description for the OBJECT_NOT_EXIST exception in STAGE_CLOSED
74
private static final String JavaDoc MESSAGE_ORBINITINFO_INVALID =
75     "ORBInitInfo object is only valid during ORB_init";
76  
77     /**
78      * Creates a new ORBInitInfoImpl object (scoped to package)
79      *
80      * @param args The arguments passed to ORB_init.
81      */

82     ORBInitInfoImpl( ORB orb, String JavaDoc[] args,
83     String JavaDoc orbId, CodecFactory JavaDoc codecFactory )
84     {
85     this.orb = orb;
86
87     wrapper = InterceptorsSystemException.get( orb,
88         CORBALogDomains.RPC_PROTOCOL ) ;
89     orbutilWrapper = ORBUtilSystemException.get( orb,
90         CORBALogDomains.RPC_PROTOCOL ) ;
91     omgWrapper = OMGSystemException.get( orb,
92         CORBALogDomains.RPC_PROTOCOL ) ;
93
94     this.args = args;
95     this.orbId = orbId;
96     this.codecFactory = codecFactory;
97     }
98
99     /** Return the ORB behind this ORBInitInfo. This is defined in the
100      * ORBInitInfoExt interface.
101      */

102     public ORB getORB()
103     {
104     return orb ;
105     }
106
107     /**
108      * Sets the current stage we are in. This limits access to certain
109      * functionality.
110      */

111     void setStage( int stage ) {
112     this.stage = stage;
113     }
114
115     /**
116      * Throws an exception if the current stage is STAGE_CLOSED.
117      * This is called before any method is invoked to ensure that
118      * no method invocations are attempted after all calls to post_init()
119      * are completed.
120      */

121     private void checkStage() {
122     if( stage == STAGE_CLOSED ) {
123         throw wrapper.orbinitinfoInvalid() ;
124     }
125     }
126
127     /*
128      *******************************************************************
129      * The following are implementations of the ORBInitInfo operations.
130      *******************************************************************/

131
132     /**
133      * This attribute contains the arguments passed to ORB_init. They may
134      * or may not contain the ORB's arguments
135      */

136     public String JavaDoc[] arguments () {
137     checkStage();
138     return args;
139     }
140
141     /**
142      * This attribute is the ID of the ORB being initialized
143      */

144     public String JavaDoc orb_id () {
145     checkStage();
146     return orbId;
147     }
148
149     /**
150      * This attribute is the IOP::CodecFactory. The CodecFactory is normally
151      * obtained via a call to ORB::resolve_initial_references( "CodecFactory" )
152      * but since the ORB is not yet available and Interceptors, particularly
153      * when processing service contexts, will require a Codec, a means of
154      * obtaining a Codec is necessary during ORB intialization.
155      */

156     public CodecFactory JavaDoc codec_factory () {
157     checkStage();
158     return codecFactory;
159     }
160
161     /**
162      * See orbos/99-12-02, Chapter 11, Dynamic Initial References on page
163      * 11-81. This operation is identical to ORB::register_initial_reference
164      * described there. This same functionality exists here because the ORB,
165      * not yet fully initialized, is not yet available but initial references
166      * may need to be registered as part of Interceptor registration.
167      * <p>
168      * This method may not be called during post_init.
169      */

170     public void register_initial_reference( String JavaDoc id,
171                                         org.omg.CORBA.Object JavaDoc obj )
172         throws InvalidName JavaDoc
173     {
174     checkStage();
175     if( id == null ) nullParam();
176
177     // As per CORBA 3.0 section 21.8.1,
178
// if null is passed as the obj parameter,
179
// throw BAD_PARAM with minor code OMGSystemException.RIR_WITH_NULL_OBJECT.
180
// Though the spec is talking about IDL null, we will address both
181
// Java null and IDL null:
182
// Note: Local Objects can never be nil!
183
if( obj == null ) {
184         throw omgWrapper.rirWithNullObject() ;
185     }
186
187     // This check was made to determine that the objref is a
188
// non-local objref that is fully
189
// initialized: this was called only for its side-effects of
190
// possibly throwing exceptions. However, registering
191
// local objects should be permitted!
192
// XXX/Revisit?
193
// IOR ior = ORBUtility.getIOR( obj ) ;
194

195     // Delegate to ORB. If ORB version throws InvalidName, convert to
196
// equivalent Portable Interceptors InvalidName.
197
try {
198         orb.register_initial_reference( id, obj );
199     } catch( org.omg.CORBA.ORBPackage.InvalidName JavaDoc e ) {
200         InvalidName JavaDoc exc = new InvalidName JavaDoc( e.getMessage() );
201         exc.initCause( e ) ;
202         throw exc ;
203     }
204     }
205
206     /**
207      * This operation is only valid during post_init. It is identical to
208      * ORB::resolve_initial_references. This same functionality exists here
209      * because the ORB, not yet fully initialized, is not yet available,
210      * but initial references may be required from the ORB as part
211      * of Interceptor registration.
212      * <p>
213      * (incorporates changes from errata in orbos/00-01-01)
214      * <p>
215      * This method may not be called during pre_init.
216      */

217     public org.omg.CORBA.Object JavaDoc resolve_initial_references (String JavaDoc id)
218     throws InvalidName JavaDoc
219     {
220     checkStage();
221     if( id == null ) nullParam();
222
223     if( stage == STAGE_PRE_INIT ) {
224         // Initializer is not allowed to invoke this method during
225
// this stage.
226

227         // _REVISIT_ Spec issue: What exception should really be
228
// thrown here?
229
throw wrapper.rirInvalidPreInit() ;
230     }
231
232     org.omg.CORBA.Object JavaDoc objRef = null;
233     
234     try {
235         objRef = orb.resolve_initial_references( id );
236         }
237     catch( org.omg.CORBA.ORBPackage.InvalidName JavaDoc e ) {
238         // Convert PIDL to IDL exception:
239
throw new InvalidName JavaDoc();
240     }
241
242     return objRef;
243     }
244
245     // New method from CORBA 3.1
246
public void add_client_request_interceptor_with_policy (
247     ClientRequestInterceptor JavaDoc interceptor, Policy JavaDoc[] policies )
248         throws DuplicateName JavaDoc
249     {
250     // XXX ignore policies for now
251
add_client_request_interceptor( interceptor ) ;
252     }
253
254     /**
255      * This operation is used to add a client-side request Interceptor to
256      * the list of client-side request Interceptors.
257      * <p>
258      * If a client-side request Interceptor has already been registered
259      * with this Interceptor's name, DuplicateName is raised.
260      */

261     public void add_client_request_interceptor (
262     ClientRequestInterceptor JavaDoc interceptor)
263         throws DuplicateName JavaDoc
264     {
265     checkStage();
266     if( interceptor == null ) nullParam();
267
268     orb.getPIHandler().register_interceptor( interceptor,
269         InterceptorList.INTERCEPTOR_TYPE_CLIENT );
270     }
271
272     // New method from CORBA 3.1
273
public void add_server_request_interceptor_with_policy (
274     ServerRequestInterceptor JavaDoc interceptor, Policy JavaDoc[] policies )
275         throws DuplicateName JavaDoc, PolicyError JavaDoc
276     {
277     // XXX ignore policies for now
278
add_server_request_interceptor( interceptor ) ;
279     }
280
281     /**
282      * This operation is used to add a server-side request Interceptor to
283      * the list of server-side request Interceptors.
284      * <p>
285      * If a server-side request Interceptor has already been registered
286      * with this Interceptor's name, DuplicateName is raised.
287      */

288     public void add_server_request_interceptor (
289     ServerRequestInterceptor JavaDoc interceptor)
290         throws DuplicateName JavaDoc
291     {
292     checkStage();
293     if( interceptor == null ) nullParam();
294     
295     orb.getPIHandler().register_interceptor( interceptor,
296         InterceptorList.INTERCEPTOR_TYPE_SERVER );
297     }
298
299     // New method from CORBA 3.1
300
public void add_ior_interceptor_with_policy (
301     IORInterceptor JavaDoc interceptor, Policy JavaDoc[] policies )
302         throws DuplicateName JavaDoc, PolicyError JavaDoc
303     {
304     // XXX ignore policies for now
305
add_ior_interceptor( interceptor ) ;
306     }
307
308     /**
309      * This operation is used to add an IOR Interceptor to
310      * the list of IOR Interceptors.
311      * <p>
312      * If an IOR Interceptor has already been registered
313      * with this Interceptor's name, DuplicateName is raised.
314      */

315     public void add_ior_interceptor (
316     IORInterceptor JavaDoc interceptor )
317         throws DuplicateName JavaDoc
318     {
319     checkStage();
320     if( interceptor == null ) nullParam();
321
322     orb.getPIHandler().register_interceptor( interceptor,
323         InterceptorList.INTERCEPTOR_TYPE_IOR );
324     }
325
326     /**
327      * A service calls allocate_slot_id to allocate a slot on
328      * PortableInterceptor::Current.
329      *
330      * @return The index to the slot which has been allocated.
331      */

332     public int allocate_slot_id () {
333     checkStage();
334
335         return ((PICurrent)orb.getPIHandler().getPICurrent()).allocateSlotId( );
336
337     }
338
339     /**
340      * Register a PolicyFactory for the given PolicyType.
341      * <p>
342      * If a PolicyFactory already exists for the given PolicyType,
343      * BAD_INV_ORDER is raised with a minor code of TBD_BIO+2.
344      */

345     public void register_policy_factory( int type,
346                                      PolicyFactory JavaDoc policy_factory )
347     {
348     checkStage();
349     if( policy_factory == null ) nullParam();
350         orb.getPIHandler().registerPolicyFactory( type, policy_factory );
351     }
352
353
354     /**
355      * Called when an invalid null parameter was passed. Throws a
356      * BAD_PARAM with a minor code of 1
357      */

358     private void nullParam()
359         throws BAD_PARAM JavaDoc
360     {
361     throw orbutilWrapper.nullParam() ;
362     }
363 }
364
Popular Tags