KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)ClientRequestInfoImpl.java 1.45 04/06/21
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 java.util.HashMap JavaDoc ;
11
12 import org.omg.CORBA.Any JavaDoc;
13 import org.omg.CORBA.BAD_INV_ORDER JavaDoc;
14 import org.omg.CORBA.BAD_PARAM JavaDoc;
15 import org.omg.CORBA.CompletionStatus JavaDoc;
16 import org.omg.CORBA.Context JavaDoc;
17 import org.omg.CORBA.ContextList JavaDoc;
18 import org.omg.CORBA.CTX_RESTRICT_SCOPE JavaDoc;
19 import org.omg.CORBA.ExceptionList JavaDoc;
20 import org.omg.CORBA.LocalObject JavaDoc;
21 import org.omg.CORBA.NamedValue JavaDoc;
22 import org.omg.CORBA.NO_IMPLEMENT JavaDoc;
23 import org.omg.CORBA.NO_RESOURCES JavaDoc;
24 import org.omg.CORBA.NVList JavaDoc;
25 import org.omg.CORBA.Object JavaDoc;
26 import org.omg.CORBA.ParameterMode JavaDoc;
27 import org.omg.CORBA.Policy JavaDoc;
28 import org.omg.CORBA.SystemException JavaDoc;
29 import org.omg.CORBA.TypeCode JavaDoc;
30 import org.omg.CORBA.INTERNAL JavaDoc;
31 import org.omg.CORBA.UserException JavaDoc;
32 import org.omg.CORBA.portable.ApplicationException JavaDoc;
33 import org.omg.CORBA.portable.InputStream JavaDoc;
34 import com.sun.corba.se.spi.servicecontext.ServiceContexts;
35 import com.sun.corba.se.spi.servicecontext.UnknownServiceContext;
36
37 import org.omg.IOP.ServiceContext JavaDoc;
38 import org.omg.IOP.ServiceContextHelper JavaDoc;
39 import org.omg.IOP.TaggedProfile JavaDoc;
40 import org.omg.IOP.TaggedProfileHelper JavaDoc;
41 import org.omg.IOP.TaggedComponent JavaDoc;
42 import org.omg.IOP.TaggedComponentHelper JavaDoc;
43 import org.omg.IOP.TAG_INTERNET_IOP JavaDoc;
44 import org.omg.Dynamic.Parameter JavaDoc;
45 import org.omg.PortableInterceptor.ClientRequestInfo JavaDoc;
46 import org.omg.PortableInterceptor.LOCATION_FORWARD JavaDoc;
47 import org.omg.PortableInterceptor.SUCCESSFUL JavaDoc;
48 import org.omg.PortableInterceptor.SYSTEM_EXCEPTION JavaDoc;
49 import org.omg.PortableInterceptor.TRANSPORT_RETRY JavaDoc;
50 import org.omg.PortableInterceptor.USER_EXCEPTION JavaDoc;
51
52 import com.sun.corba.se.pept.protocol.MessageMediator;
53
54 import com.sun.corba.se.spi.ior.IOR;
55 import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate;
56 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
57 import com.sun.corba.se.spi.orb.ORB;
58 import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
59 import com.sun.corba.se.spi.transport.CorbaContactInfo;
60 import com.sun.corba.se.spi.transport.CorbaContactInfoList;
61 import com.sun.corba.se.spi.transport.CorbaContactInfoListIterator;
62
63 import com.sun.corba.se.impl.encoding.CDROutputStream;
64 import com.sun.corba.se.impl.encoding.CDRInputStream_1_0;
65 import com.sun.corba.se.impl.orbutil.ORBUtility;
66 import com.sun.corba.se.impl.protocol.CorbaInvocationInfo;
67 import com.sun.corba.se.impl.util.RepositoryId;
68
69 /**
70  * Implementation of the ClientRequestInfo interface as specified in
71  * orbos/99-12-02 section 5.4.2.
72  */

73 public final class ClientRequestInfoImpl
74     extends RequestInfoImpl
75     implements ClientRequestInfo JavaDoc
76 {
77
78     // The available constants for startingPointCall
79
static final int CALL_SEND_REQUEST = 0;
80     static final int CALL_SEND_POLL = 1;
81     
82     // The available constants for endingPointCall
83
static final int CALL_RECEIVE_REPLY = 0;
84     static final int CALL_RECEIVE_EXCEPTION = 1;
85     static final int CALL_RECEIVE_OTHER = 2;
86
87     //////////////////////////////////////////////////////////////////////
88
//
89
// NOTE: IF AN ATTRIBUTE IS ADDED, PLEASE UPDATE RESET();
90
//
91
//////////////////////////////////////////////////////////////////////
92

93     // The current retry request status. True if this request is being
94
// retried and this info object is to be reused, or false otherwise.
95
private boolean retryRequest;
96     
97     // The number of times this info object has been (re)used. This is
98
// incremented every time a request is retried, and decremented every
99
// time a request is complete. When this reaches zero, the info object
100
// is popped from the ClientRequestInfoImpl ThreadLocal stack in the ORB.
101
private int entryCount = 0;
102
103     // The RequestImpl is set when the call is DII based.
104
// The DII query calls like ParameterList, ExceptionList,
105
// ContextList will be delegated to RequestImpl.
106
private org.omg.CORBA.Request JavaDoc request;
107
108     // Sources of client request information
109
private boolean diiInitiate;
110     private CorbaMessageMediator messageMediator;
111
112     // Cached information:
113
private org.omg.CORBA.Object JavaDoc cachedTargetObject;
114     private org.omg.CORBA.Object JavaDoc cachedEffectiveTargetObject;
115     private Parameter JavaDoc[] cachedArguments;
116     private TypeCode JavaDoc[] cachedExceptions;
117     private String JavaDoc[] cachedContexts;
118     private String JavaDoc[] cachedOperationContext;
119     private String JavaDoc cachedReceivedExceptionId;
120     private Any JavaDoc cachedResult;
121     private Any JavaDoc cachedReceivedException;
122     private TaggedProfile JavaDoc cachedEffectiveProfile;
123     // key = Integer, value = IOP.ServiceContext.
124
private HashMap JavaDoc cachedRequestServiceContexts;
125     // key = Integer, value = IOP.ServiceContext.
126
private HashMap JavaDoc cachedReplyServiceContexts;
127     // key = Integer, value = TaggedComponent
128
private HashMap JavaDoc cachedEffectiveComponents;
129
130
131     protected boolean piCurrentPushed;
132     
133     //////////////////////////////////////////////////////////////////////
134
//
135
// NOTE: IF AN ATTRIBUTE IS ADDED, PLEASE UPDATE RESET();
136
//
137
//////////////////////////////////////////////////////////////////////
138

139     /**
140      * Reset the info object so that it can be reused for a retry,
141      * for example.
142      */

143     void reset() {
144         super.reset();
145
146     // Please keep these in the same order that they're declared above.
147

148         retryRequest = false;
149
150         // Do not reset entryCount because we need to know when to pop this
151
// from the stack.
152

153         request = null;
154     diiInitiate = false;
155     messageMediator = null;
156
157     // Clear cached attributes:
158
cachedTargetObject = null;
159     cachedEffectiveTargetObject = null;
160     cachedArguments = null;
161     cachedExceptions = null;
162     cachedContexts = null;
163     cachedOperationContext = null;
164     cachedReceivedExceptionId = null;
165     cachedResult = null;
166     cachedReceivedException = null;
167     cachedEffectiveProfile = null;
168     cachedRequestServiceContexts = null;
169     cachedReplyServiceContexts = null;
170         cachedEffectiveComponents = null;
171
172     piCurrentPushed = false;
173
174         startingPointCall = CALL_SEND_REQUEST;
175         endingPointCall = CALL_RECEIVE_REPLY;
176
177     }
178     
179     /*
180      **********************************************************************
181      * Access protection
182      **********************************************************************/

183     
184     // Method IDs for all methods in ClientRequestInfo. This allows for a
185
// convenient O(1) lookup for checkAccess().
186
protected static final int MID_TARGET = MID_RI_LAST + 1;
187     protected static final int MID_EFFECTIVE_TARGET = MID_RI_LAST + 2;
188     protected static final int MID_EFFECTIVE_PROFILE = MID_RI_LAST + 3;
189     protected static final int MID_RECEIVED_EXCEPTION = MID_RI_LAST + 4;
190     protected static final int MID_RECEIVED_EXCEPTION_ID = MID_RI_LAST + 5;
191     protected static final int MID_GET_EFFECTIVE_COMPONENT = MID_RI_LAST + 6;
192     protected static final int MID_GET_EFFECTIVE_COMPONENTS
193                                                            = MID_RI_LAST + 7;
194     protected static final int MID_GET_REQUEST_POLICY = MID_RI_LAST + 8;
195     protected static final int MID_ADD_REQUEST_SERVICE_CONTEXT
196                                                            = MID_RI_LAST + 9;
197     
198     // ClientRequestInfo validity table (see ptc/00-08-06 table 21-1).
199
// Note: These must be in the same order as specified in contants.
200
protected static final boolean validCall[][] = {
201         // LEGEND:
202
// s_req = send_request r_rep = receive_reply
203
// s_pol = send_poll r_exc = receive_exception
204
// r_oth = receive_other
205
//
206
// A true value indicates call is valid at specified point.
207
// A false value indicates the call is invalid.
208
//
209
//
210
// NOTE: If the order or number of columns change, update
211
// checkAccess() accordingly.
212
//
213
// { s_req, s_pol, r_rep, r_exc, r_oth }
214
// RequestInfo methods:
215
/*request_id*/ { true , true , true , true , true },
216         /*operation*/ { true , true , true , true , true },
217         /*arguments*/ { true , false, true , false, false },
218         /*exceptions*/ { true , false, true , true , true },
219         /*contexts*/ { true , false, true , true , true },
220         /*operation_context*/ { true , false, true , true , true },
221         /*result*/ { false, false, true , false, false },
222         /*response_expected*/ { true , true , true , true , true },
223         /*sync_scope*/ { true , false, true , true , true },
224         /*reply_status*/ { false, false, true , true , true },
225         /*forward_reference*/ { false, false, false, false, true },
226         /*get_slot*/ { true , true , true , true , true },
227         /*get_request_service_context*/ { true , false, true , true , true },
228         /*get_reply_service_context*/ { false, false, true , true , true },
229         //
230
// ClientRequestInfo methods::
231
/*target*/ { true , true , true , true , true },
232         /*effective_target*/ { true , true , true , true , true },
233         /*effective_profile*/ { true , true , true , true , true },
234         /*received_exception*/ { false, false, false, true , false },
235         /*received_exception_id*/ { false, false, false, true , false },
236         /*get_effective_component*/ { true , false, true , true , true },
237         /*get_effective_components*/ { true , false, true , true , true },
238         /*get_request_policy*/ { true , false, true , true , true },
239         /*add_request_service_context*/ { true , false, false, false, false }
240     };
241     
242
243     /*
244      **********************************************************************
245      * Public ClientRequestInfo interfaces
246      **********************************************************************/

247     
248     /**
249      * Creates a new ClientRequestInfo implementation.
250      * The constructor is package scope since no other package need create
251      * an instance of this class.
252      */

253     protected ClientRequestInfoImpl( ORB myORB ) {
254         super( myORB );
255         startingPointCall = CALL_SEND_REQUEST;
256         endingPointCall = CALL_RECEIVE_REPLY;
257     }
258     
259     /**
260      * The object which the client called to perform the operation.
261      */

262     public org.omg.CORBA.Object JavaDoc target (){
263     // access is currently valid for all states:
264
//checkAccess( MID_TARGET );
265
if (cachedTargetObject == null) {
266         CorbaContactInfo corbaContactInfo = (CorbaContactInfo)
267         messageMediator.getContactInfo();
268         cachedTargetObject =
269         iorToObject(corbaContactInfo.getTargetIOR());
270     }
271     return cachedTargetObject;
272     }
273     
274     /**
275      * The actual object on which the operation will be invoked. If the
276      * reply_status is LOCATION_FORWARD, then on subsequent requests,
277      * effective_target will contain the forwarded IOR while target will
278      * remain unchanged.
279      */

280     public org.omg.CORBA.Object JavaDoc effective_target() {
281     // access is currently valid for all states:
282
//checkAccess( MID_EFFECTIVE_TARGET );
283

284         // Note: This is not necessarily the same as locatedIOR.
285
// Reason: See the way we handle COMM_FAILURES in
286
// ClientRequestDispatcher.createRequest, v1.32
287

288     if (cachedEffectiveTargetObject == null) {
289         CorbaContactInfo corbaContactInfo = (CorbaContactInfo)
290         messageMediator.getContactInfo();
291         // REVISIT - get through chain like getLocatedIOR helper below.
292
cachedEffectiveTargetObject =
293         iorToObject(corbaContactInfo.getEffectiveTargetIOR());
294     }
295     return cachedEffectiveTargetObject;
296     }
297     
298     /**
299      * The profile that will be used to send the request. If a location
300      * forward has occurred for this operation's object and that object's
301      * profile change accordingly, then this profile will be that located
302      * profile.
303      */

304     public TaggedProfile JavaDoc effective_profile (){
305         // access is currently valid for all states:
306
//checkAccess( MID_EFFECTIVE_PROFILE );
307

308     if( cachedEffectiveProfile == null ) {
309         CorbaContactInfo corbaContactInfo = (CorbaContactInfo)
310         messageMediator.getContactInfo();
311         cachedEffectiveProfile =
312         corbaContactInfo.getEffectiveProfile().getIOPProfile();
313     }
314
315     // Good citizen: In the interest of efficiency, we assume interceptors
316
// will not modify the returned TaggedProfile in any way so we need
317
// not make a deep copy of it.
318

319     return cachedEffectiveProfile;
320     }
321     
322     /**
323      * Contains the exception to be returned to the client.
324      */

325     public Any JavaDoc received_exception (){
326         checkAccess( MID_RECEIVED_EXCEPTION );
327
328     if( cachedReceivedException == null ) {
329         cachedReceivedException = exceptionToAny( exception );
330     }
331
332     // Good citizen: In the interest of efficiency, we assume interceptors
333
// will not modify the returned Any in any way so we need
334
// not make a deep copy of it.
335

336     return cachedReceivedException;
337     }
338     
339     /**
340      * The CORBA::RepositoryId of the exception to be returned to the client.
341      */

342     public String JavaDoc received_exception_id (){
343         checkAccess( MID_RECEIVED_EXCEPTION_ID );
344
345     if( cachedReceivedExceptionId == null ) {
346         String JavaDoc result = null;
347         
348         if( exception == null ) {
349         // Note: exception should never be null here since we will
350
// throw a BAD_INV_ORDER if this is not called from
351
// receive_exception.
352
throw wrapper.exceptionWasNull() ;
353         } else if( exception instanceof SystemException JavaDoc ) {
354         String JavaDoc name = exception.getClass().getName();
355         result = ORBUtility.repositoryIdOf(name);
356         } else if( exception instanceof ApplicationException JavaDoc ) {
357         result = ((ApplicationException JavaDoc)exception).getId();
358         }
359
360         // _REVISIT_ We need to be able to handle a UserException in the
361
// DII case. How do we extract the ID from a UserException?
362

363         cachedReceivedExceptionId = result;
364     }
365
366     return cachedReceivedExceptionId;
367     }
368     
369     /**
370      * Returns the IOP::TaggedComponent with the given ID from the profile
371      * selected for this request. IF there is more than one component for a
372      * given component ID, it is undefined which component this operation
373      * returns (get_effective_component should be called instead).
374      */

375     public TaggedComponent JavaDoc get_effective_component (int id){
376         checkAccess( MID_GET_EFFECTIVE_COMPONENT );
377         
378         return get_effective_components( id )[0];
379     }
380     
381     /**
382      * Returns all the tagged components with the given ID from the profile
383      * selected for this request.
384      */

385     public TaggedComponent JavaDoc[] get_effective_components (int id){
386         checkAccess( MID_GET_EFFECTIVE_COMPONENTS );
387     Integer JavaDoc integerId = new Integer JavaDoc( id );
388     TaggedComponent JavaDoc[] result = null;
389     boolean justCreatedCache = false;
390
391     if( cachedEffectiveComponents == null ) {
392         cachedEffectiveComponents = new HashMap JavaDoc();
393         justCreatedCache = true;
394     }
395     else {
396         // Look in cache:
397
result = (TaggedComponent JavaDoc[])cachedEffectiveComponents.get(
398         integerId );
399     }
400         
401     // null could mean we cached null or not in cache.
402
if( (result == null) &&
403         (justCreatedCache ||
404         !cachedEffectiveComponents.containsKey( integerId ) ) )
405     {
406         // Not in cache. Get it from the profile:
407
CorbaContactInfo corbaContactInfo = (CorbaContactInfo)
408         messageMediator.getContactInfo();
409         IIOPProfileTemplate ptemp =
410         (IIOPProfileTemplate)corbaContactInfo.getEffectiveProfile().
411         getTaggedProfileTemplate();
412         result = ptemp.getIOPComponents(myORB, id);
413         cachedEffectiveComponents.put( integerId, result );
414     }
415         
416         // As per ptc/00-08-06, section 21.3.13.6., If not found, raise
417
// BAD_PARAM with minor code INVALID_COMPONENT_ID.
418
if( (result == null) || (result.length == 0) ) {
419         throw stdWrapper.invalidComponentId( integerId ) ;
420         }
421
422     // Good citizen: In the interest of efficiency, we will assume
423
// interceptors will not modify the returned TaggedCompoent[], or
424
// the TaggedComponents inside of it. Otherwise, we would need to
425
// clone the array and make a deep copy of its contents.
426

427         return result;
428     }
429     
430     /**
431      * Returns the given policy in effect for this operation.
432      */

433     public Policy JavaDoc get_request_policy (int type){
434         checkAccess( MID_GET_REQUEST_POLICY );
435     // _REVISIT_ Our ORB is not policy-based at this time.
436
throw wrapper.piOrbNotPolicyBased() ;
437     }
438     
439     /**
440      * Allows interceptors to add service contexts to the request.
441      * <p>
442      * There is no declaration of the order of the service contexts. They
443      * may or may not appear in the order they are added.
444      */

445     public void add_request_service_context (ServiceContext service_context,
446                                              boolean replace)
447     {
448         checkAccess( MID_ADD_REQUEST_SERVICE_CONTEXT );
449
450     if( cachedRequestServiceContexts == null ) {
451         cachedRequestServiceContexts = new HashMap JavaDoc();
452     }
453
454     addServiceContext( cachedRequestServiceContexts,
455                messageMediator.getRequestServiceContexts(),
456                service_context, replace );
457     }
458     
459     // NOTE: When adding a method, be sure to:
460
// 1. Add a MID_* constant for that method
461
// 2. Call checkAccess at the start of the method
462
// 3. Define entries in the validCall[][] table for interception points.
463

464     /*
465      **********************************************************************
466      * Public RequestInfo interfaces
467      *
468      * These are implemented here because they have differing
469      * implementations depending on whether this is a client or a server
470      * request info object.
471      **********************************************************************/

472    
473     /**
474      * See RequestInfoImpl for javadoc.
475      */

476     public int request_id (){
477         // access is currently valid for all states:
478
//checkAccess( MID_REQUEST_ID );
479
/*
480      * NOTE: The requestId in client interceptors is the same as the
481      * GIOP request id. This works because both interceptors and
482      * request ids are scoped by the ORB on the client side.
483      */

484     return messageMediator.getRequestId();
485     }
486
487     /**
488      * See RequestInfoImpl for javadoc.
489      */

490     public String JavaDoc operation (){
491         // access is currently valid for all states:
492
//checkAccess( MID_OPERATION );
493
return messageMediator.getOperationName();
494     }
495
496     /**
497      * See RequestInfoImpl for javadoc.
498      */

499     public Parameter JavaDoc[] arguments (){
500         checkAccess( MID_ARGUMENTS );
501
502     if( cachedArguments == null ) {
503         if( request == null ) {
504         throw stdWrapper.piOperationNotSupported1() ;
505         }
506
507         // If it is DII request then get the arguments from the DII req
508
// and convert that into parameters.
509
cachedArguments = nvListToParameterArray( request.arguments() );
510     }
511
512         // Good citizen: In the interest of efficiency, we assume
513
// interceptors will be "good citizens" in that they will not
514
// modify the contents of the Parameter[] array. We also assume
515
// they will not change the values of the containing Anys.
516

517     return cachedArguments;
518     }
519
520     /**
521      * See RequestInfoImpl for javadoc.
522      */

523     public TypeCode JavaDoc[] exceptions (){
524         checkAccess( MID_EXCEPTIONS );
525
526     if( cachedExceptions == null ) {
527         if( request == null ) {
528            throw stdWrapper.piOperationNotSupported2() ;
529         }
530
531         // Get the list of exceptions from DII request data, If there are
532
// no exceptions raised then this method will return null.
533
ExceptionList JavaDoc excList = request.exceptions( );
534         int count = excList.count();
535         TypeCode JavaDoc[] excTCList = new TypeCode JavaDoc[count];
536         try {
537         for( int i = 0; i < count; i++ ) {
538             excTCList[i] = excList.item( i );
539         }
540         } catch( Exception JavaDoc e ) {
541         throw wrapper.exceptionInExceptions( e ) ;
542         }
543
544         cachedExceptions = excTCList;
545     }
546
547         // Good citizen: In the interest of efficiency, we assume
548
// interceptors will be "good citizens" in that they will not
549
// modify the contents of the TypeCode[] array. We also assume
550
// they will not change the values of the containing TypeCodes.
551

552     return cachedExceptions;
553     }
554
555     /**
556      * See RequestInfoImpl for javadoc.
557      */

558     public String JavaDoc[] contexts (){
559         checkAccess( MID_CONTEXTS );
560
561     if( cachedContexts == null ) {
562         if( request == null ) {
563         throw stdWrapper.piOperationNotSupported3() ;
564         }
565
566         // Get the list of contexts from DII request data, If there are
567
// no contexts then this method will return null.
568
ContextList JavaDoc ctxList = request.contexts( );
569         int count = ctxList.count();
570         String JavaDoc[] ctxListToReturn = new String JavaDoc[count];
571         try {
572         for( int i = 0; i < count; i++ ) {
573             ctxListToReturn[i] = ctxList.item( i );
574         }
575         } catch( Exception JavaDoc e ) {
576         throw wrapper.exceptionInContexts( e ) ;
577         }
578
579             cachedContexts = ctxListToReturn;
580     }
581
582         // Good citizen: In the interest of efficiency, we assume
583
// interceptors will be "good citizens" in that they will not
584
// modify the contents of the String[] array.
585

586     return cachedContexts;
587     }
588
589     /**
590      * See RequestInfoImpl for javadoc.
591      */

592     public String JavaDoc[] operation_context (){
593         checkAccess( MID_OPERATION_CONTEXT );
594
595     if( cachedOperationContext == null ) {
596         if( request == null ) {
597         throw stdWrapper.piOperationNotSupported4() ;
598         }
599
600         // Get the list of contexts from DII request data, If there are
601
// no contexts then this method will return null.
602
Context JavaDoc ctx = request.ctx( );
603         // _REVISIT_ The API for get_values is not compliant with the spec,
604
// Revisit this code once it's fixed.
605
// _REVISIT_ Our ORB doesn't support Operation Context, This code
606
// will not be excerscised until it's supported.
607
// The first parameter in get_values is the start_scope which
608
// if blank makes it as a global scope.
609
// The second parameter is op_flags which is set to RESTRICT_SCOPE
610
// As there is only one defined in the spec.
611
// The Third param is the pattern which is '*' requiring it to
612
// get all the contexts.
613
NVList JavaDoc nvList = ctx.get_values( "", CTX_RESTRICT_SCOPE.value,"*" );
614         String JavaDoc[] context = new String JavaDoc[(nvList.count() * 2) ];
615         if( ( nvList != null ) &&( nvList.count() != 0 ) ) {
616         // The String[] array will contain Name and Value for each
617
// context and hence double the size in the array.
618
int index = 0;
619         for( int i = 0; i < nvList.count(); i++ ) {
620             NamedValue JavaDoc nv;
621             try {
622             nv = nvList.item( i );
623             }
624             catch (Exception JavaDoc e ) {
625             return (String JavaDoc[]) null;
626             }
627             context[index] = nv.name();
628             index++;
629             context[index] = nv.value().extract_string();
630             index++;
631         }
632         }
633
634         cachedOperationContext = context;
635     }
636
637         // Good citizen: In the interest of efficiency, we assume
638
// interceptors will be "good citizens" in that they will not
639
// modify the contents of the String[] array.
640

641     return cachedOperationContext;
642     }
643
644     /**
645      * See RequestInfoImpl for javadoc.
646      */

647     public Any JavaDoc result (){
648         checkAccess( MID_RESULT );
649
650     if( cachedResult == null ) {
651         if( request == null ) {
652         throw stdWrapper.piOperationNotSupported5() ;
653         }
654         // Get the result from the DII request data.
655
NamedValue JavaDoc nvResult = request.result( );
656
657         if( nvResult == null ) {
658         throw wrapper.piDiiResultIsNull() ;
659         }
660
661         cachedResult = nvResult.value();
662     }
663
664     // Good citizen: In the interest of efficiency, we assume that
665
// interceptors will not modify the contents of the result Any.
666
// Otherwise, we would need to create a deep copy of the Any.
667

668         return cachedResult;
669     }
670
671     /**
672      * See RequestInfoImpl for javadoc.
673      */

674     public boolean response_expected (){
675     // access is currently valid for all states:
676
//checkAccess( MID_RESPONSE_EXPECTED );
677
return ! messageMediator.isOneWay();
678     }
679
680     /**
681      * See RequestInfoImpl for javadoc.
682      */

683     public Object JavaDoc forward_reference (){
684         checkAccess( MID_FORWARD_REFERENCE );
685         // Check to make sure we are in LOCATION_FORWARD
686
// state as per ptc/00-08-06, table 21-1
687
// footnote 2.
688
if( replyStatus != LOCATION_FORWARD.value ) {
689         throw stdWrapper.invalidPiCall1() ;
690         }
691
692     // Do not cache this value since if an interceptor raises
693
// forward request then the next interceptor in the
694
// list should see the new value.
695
IOR ior = getLocatedIOR();
696     return iorToObject(ior);
697     }
698
699     private IOR getLocatedIOR()
700     {
701     IOR ior;
702     CorbaContactInfoList contactInfoList = (CorbaContactInfoList)
703         messageMediator.getContactInfo().getContactInfoList();
704     ior = contactInfoList.getEffectiveTargetIOR();
705     return ior;
706     }
707
708     protected void setLocatedIOR(IOR ior)
709     {
710     ORB orb = (ORB) messageMediator.getBroker();
711
712     CorbaContactInfoListIterator iterator = (CorbaContactInfoListIterator)
713         ((CorbaInvocationInfo)orb.getInvocationInfo())
714         .getContactInfoListIterator();
715
716     // REVISIT - this most likely causes reportRedirect to happen twice.
717
// Once here and once inside the request dispatcher.
718
iterator.reportRedirect(
719         (CorbaContactInfo)messageMediator.getContactInfo(),
720         ior);
721     }
722
723     /**
724      * See RequestInfoImpl for javadoc.
725      */

726     public org.omg.IOP.ServiceContext JavaDoc get_request_service_context( int id ) {
727         checkAccess( MID_GET_REQUEST_SERVICE_CONTEXT );
728
729     if( cachedRequestServiceContexts == null ) {
730         cachedRequestServiceContexts = new HashMap JavaDoc();
731     }
732
733     return getServiceContext(cachedRequestServiceContexts,
734                   messageMediator.getRequestServiceContexts(),
735                   id);
736     }
737
738     /**
739      * does not contain an etry for that ID, BAD_PARAM with a minor code of
740      * TBD_BP is raised.
741      */

742     public org.omg.IOP.ServiceContext JavaDoc get_reply_service_context( int id ) {
743         checkAccess( MID_GET_REPLY_SERVICE_CONTEXT );
744
745     if( cachedReplyServiceContexts == null ) {
746         cachedReplyServiceContexts = new HashMap JavaDoc();
747     }
748
749     // In the event this is called from a oneway, we will have no
750
// response object.
751
//
752
// In the event this is called after a IIOPConnection.purgeCalls,
753
// we will have a response object, but that object will
754
// not contain a header (which would hold the service context
755
// container). See bug 4624102.
756
//
757
// REVISIT: this is the only thing used
758
// from response at this time. However, a more general solution
759
// would avoid accessing other parts of response's header.
760
//
761
// Instead of throwing a NullPointer, we will
762
// "gracefully" handle these with a BAD_PARAM with minor code 25.
763

764     try {
765         ServiceContexts serviceContexts =
766         messageMediator.getReplyServiceContexts();
767         if (serviceContexts == null) {
768         throw new NullPointerException JavaDoc();
769         }
770         return getServiceContext(cachedReplyServiceContexts,
771                      serviceContexts, id);
772     } catch (NullPointerException JavaDoc e) {
773         // REVISIT how this is programmed - not what it does.
774
// See purge calls test. The waiter is woken up by the
775
// call to purge calls - but there is no reply containing
776
// service contexts.
777
throw stdWrapper.invalidServiceContextId( e ) ;
778     }
779     }
780
781     //
782
// REVISIT
783
// Override RequestInfoImpl connection to work in framework.
784
//
785

786     public com.sun.corba.se.spi.legacy.connection.Connection connection()
787     {
788     return (com.sun.corba.se.spi.legacy.connection.Connection)
789         messageMediator.getConnection();
790     }
791     
792
793
794     /*
795      **********************************************************************
796      * Package-scope interfaces
797      **********************************************************************/

798
799     protected void setInfo(MessageMediator messageMediator)
800     {
801     this.messageMediator = (CorbaMessageMediator)messageMediator;
802     // REVISIT - so mediator can handle DII in subcontract.
803
this.messageMediator.setDIIInfo(request);
804     }
805     
806     /**
807      * Set or reset the retry request flag.
808      */

809     void setRetryRequest( boolean retryRequest ) {
810         this.retryRequest = retryRequest;
811     }
812     
813     /**
814      * Retrieve the current retry request status.
815      */

816     boolean getRetryRequest() {
817         return this.retryRequest;
818     }
819     
820     /**
821      * Increases the entry count by 1.
822      */

823     void incrementEntryCount() {
824         this.entryCount++;
825     }
826     
827     /**
828      * Decreases the entry count by 1.
829      */

830     void decrementEntryCount() {
831         this.entryCount--;
832     }
833     
834     /**
835      * Retrieve the current entry count
836      */

837     int getEntryCount() {
838         return this.entryCount;
839     }
840     
841     /**
842      * Overridden from RequestInfoImpl. Calls the super class, then
843      * sets the ending point call depending on the reply status.
844      */

845     protected void setReplyStatus( short replyStatus ) {
846         super.setReplyStatus( replyStatus );
847         switch( replyStatus ) {
848         case SUCCESSFUL.value:
849             endingPointCall = CALL_RECEIVE_REPLY;
850             break;
851         case SYSTEM_EXCEPTION.value:
852         case USER_EXCEPTION.value:
853             endingPointCall = CALL_RECEIVE_EXCEPTION;
854             break;
855         case LOCATION_FORWARD.value:
856         case TRANSPORT_RETRY.value:
857             endingPointCall = CALL_RECEIVE_OTHER;
858             break;
859         }
860     }
861
862     /**
863      * Sets DII request object in the RequestInfoObject.
864      */

865     protected void setDIIRequest(org.omg.CORBA.Request JavaDoc req) {
866          request = req;
867     }
868
869     /**
870      * Keeps track of whether initiate was called for a DII request. The ORB
871      * needs to know this so it knows whether to ignore a second call to
872      * initiateClientPIRequest or not.
873      */

874     protected void setDIIInitiate( boolean diiInitiate ) {
875     this.diiInitiate = diiInitiate;
876     }
877
878     /**
879      * See comment for setDIIInitiate
880      */

881     protected boolean isDIIInitiate() {
882     return this.diiInitiate;
883     }
884
885     /**
886      * The PICurrent stack should only be popped if it was pushed.
887      * This is generally the case. But exceptions which occur
888      * after the stub's entry to _request but before the push
889      * end up in _releaseReply which will try to pop unless told not to.
890      */

891     protected void setPICurrentPushed( boolean piCurrentPushed ) {
892     this.piCurrentPushed = piCurrentPushed;
893     }
894
895     protected boolean isPICurrentPushed() {
896     return this.piCurrentPushed;
897     }
898
899     /**
900      * Overridden from RequestInfoImpl.
901      */

902     protected void setException( Exception JavaDoc exception ) {
903         super.setException( exception );
904
905     // Clear cached values:
906
cachedReceivedException = null;
907     cachedReceivedExceptionId = null;
908     }
909
910     protected boolean getIsOneWay() {
911     return ! response_expected();
912     }
913
914     /**
915      * See description for RequestInfoImpl.checkAccess
916      */

917     protected void checkAccess( int methodID )
918         throws BAD_INV_ORDER JavaDoc
919     {
920         // Make sure currentPoint matches the appropriate index in the
921
// validCall table:
922
int validCallIndex = 0;
923         switch( currentExecutionPoint ) {
924         case EXECUTION_POINT_STARTING:
925             switch( startingPointCall ) {
926             case CALL_SEND_REQUEST:
927                 validCallIndex = 0;
928                 break;
929             case CALL_SEND_POLL:
930                 validCallIndex = 1;
931                 break;
932             }
933             break;
934         case EXECUTION_POINT_ENDING:
935             switch( endingPointCall ) {
936             case CALL_RECEIVE_REPLY:
937                 validCallIndex = 2;
938                 break;
939             case CALL_RECEIVE_EXCEPTION:
940                 validCallIndex = 3;
941                 break;
942             case CALL_RECEIVE_OTHER:
943                 validCallIndex = 4;
944                 break;
945             }
946             break;
947         }
948         
949         // Check the validCall table:
950
if( !validCall[methodID][validCallIndex] ) {
951         throw stdWrapper.invalidPiCall2() ;
952         }
953     }
954     
955 }
956
957 // End of file.
958
Popular Tags