KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)RequestInfoImpl.java 1.46 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 package com.sun.corba.se.impl.interceptors;
8
9 import java.io.IOException JavaDoc ;
10
11 import java.lang.reflect.Method JavaDoc ;
12 import java.lang.reflect.InvocationTargetException JavaDoc ;
13
14 import java.util.HashMap JavaDoc ;
15
16 import org.omg.PortableInterceptor.ForwardRequest JavaDoc;
17 import org.omg.PortableInterceptor.InvalidSlot JavaDoc;
18 import org.omg.PortableInterceptor.RequestInfo JavaDoc;
19 import org.omg.PortableInterceptor.LOCATION_FORWARD JavaDoc;
20 import org.omg.IOP.TaggedProfile JavaDoc;
21 import org.omg.IOP.TaggedComponent JavaDoc;
22 import org.omg.IOP.ServiceContextHelper JavaDoc;
23 import org.omg.Messaging.SYNC_WITH_TRANSPORT JavaDoc;
24 import org.omg.CORBA.ParameterMode JavaDoc;
25
26 import org.omg.CORBA.Any JavaDoc;
27 import org.omg.CORBA.BAD_INV_ORDER JavaDoc;
28 import org.omg.CORBA.BAD_PARAM JavaDoc;
29 import org.omg.CORBA.CompletionStatus JavaDoc;
30 import org.omg.CORBA.Context JavaDoc;
31 import org.omg.CORBA.ContextList JavaDoc;
32 import org.omg.CORBA.CTX_RESTRICT_SCOPE JavaDoc;
33 import org.omg.CORBA.ExceptionList JavaDoc;
34 import org.omg.CORBA.INTERNAL JavaDoc;
35 import org.omg.CORBA.LocalObject JavaDoc;
36 import org.omg.CORBA.NamedValue JavaDoc;
37 import org.omg.CORBA.NO_IMPLEMENT JavaDoc;
38 import org.omg.CORBA.NO_RESOURCES JavaDoc;
39 import org.omg.CORBA.NVList JavaDoc;
40 import org.omg.CORBA.Object JavaDoc;
41 import org.omg.CORBA.Policy JavaDoc;
42 import org.omg.CORBA.SystemException JavaDoc;
43 import org.omg.CORBA.TypeCode JavaDoc;
44 import org.omg.CORBA.UNKNOWN JavaDoc;
45 import org.omg.CORBA.UserException JavaDoc;
46 import org.omg.CORBA.portable.ApplicationException JavaDoc;
47 import org.omg.CORBA.portable.Delegate JavaDoc;
48 import org.omg.CORBA.portable.InputStream JavaDoc;
49              
50 import org.omg.Dynamic.Parameter JavaDoc;
51
52 import com.sun.corba.se.spi.legacy.connection.Connection;
53
54 import com.sun.corba.se.spi.legacy.interceptor.RequestInfoExt;
55
56 import com.sun.corba.se.spi.ior.IOR;
57
58 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
59
60 import com.sun.corba.se.spi.orb.ORB;
61
62 import com.sun.corba.se.spi.logging.CORBALogDomains;
63
64 import com.sun.corba.se.spi.servicecontext.ServiceContexts;
65 import com.sun.corba.se.spi.servicecontext.UnknownServiceContext;
66
67 import com.sun.corba.se.impl.encoding.CDRInputStream_1_0;
68 import com.sun.corba.se.impl.encoding.EncapsOutputStream;
69
70 import com.sun.corba.se.impl.orbutil.ORBUtility;
71 import com.sun.corba.se.impl.orbutil.ORBClassLoader;
72
73 import com.sun.corba.se.impl.util.RepositoryId;
74
75 import com.sun.corba.se.impl.logging.InterceptorsSystemException;
76 import com.sun.corba.se.impl.logging.OMGSystemException;
77
78 /**
79  * Implementation of the RequestInfo interface as specified in
80  * orbos/99-12-02 section 5.4.1.
81  */

82 public abstract class RequestInfoImpl
83     extends LocalObject JavaDoc
84     implements RequestInfo JavaDoc, RequestInfoExt
85 {
86     //////////////////////////////////////////////////////////////////////
87
//
88
// NOTE: IF AN ATTRIBUTE IS ADDED, PLEASE UPDATE RESET();
89
//
90
//////////////////////////////////////////////////////////////////////
91

92     // The ORB from which to get PICurrent and other info
93
protected ORB myORB;
94     protected InterceptorsSystemException wrapper ;
95     protected OMGSystemException stdWrapper ;
96
97     // The number of interceptors actually invoked for this client request.
98
// See setFlowStackIndex for a detailed description.
99
protected int flowStackIndex = 0;
100
101     // The type of starting point call to make to the interceptors
102
// See ClientRequestInfoImpl and ServerRequestInfoImpl for a list of
103
// appropriate constants.
104
protected int startingPointCall;
105     
106     // The type of intermediate point call to make to the interceptors
107
// See ServerRequestInfoImpl for a list of appropriate constants.
108
// This does not currently apply to client request interceptors but is
109
// here in case intermediate points are introduced in the future.
110
protected int intermediatePointCall;
111     
112     // The type of ending point call to make to the interceptors
113
// See ClientRequestInfoImpl and ServerRequestInfoImpl for a list of
114
// appropriate constants.
115
protected int endingPointCall;
116     
117     // The reply status to return in reply_status. This is initialized
118
// to UNINITIALIZED so that we can tell if this has been set or not.
119
protected short replyStatus = UNINITIALIZED;
120     
121     // Constant for an uninitizlied reply status.
122
protected static final short UNINITIALIZED = -1;
123     
124     // Which points we are currently executing (so we can implement the
125
// validity table).
126
protected int currentExecutionPoint;
127     protected static final int EXECUTION_POINT_STARTING = 0;
128     protected static final int EXECUTION_POINT_INTERMEDIATE = 1;
129     protected static final int EXECUTION_POINT_ENDING = 2;
130     
131     // Set to true if all interceptors have had all their points
132
// executed.
133
protected boolean alreadyExecuted;
134     
135     // Sources of request information
136
protected Connection connection;
137     protected ServiceContexts serviceContexts;
138     
139     // The ForwardRequest object if this request is being forwarded.
140
// Either the forwardRequest or the forwardRequestIOR field is set.
141
// When set, the other field is set to null initially. If the other
142
// field is queried, it is lazily calculated and cached. These
143
// two attributes are always kept in sync.
144
protected ForwardRequest JavaDoc forwardRequest;
145     protected IOR forwardRequestIOR;
146
147     // PICurrent's SlotTable
148
protected SlotTable slotTable;
149
150     // The exception to be returned by received_exception and
151
// received_exception_id
152
protected Exception JavaDoc exception;
153     
154     //////////////////////////////////////////////////////////////////////
155
//
156
// NOTE: IF AN ATTRIBUTE IS ADDED, PLEASE UPDATE RESET();
157
//
158
//////////////////////////////////////////////////////////////////////
159

160     /**
161      * Reset the info object so that it can be reused for a retry,
162      * for example.
163      */

164     void reset() {
165
166     // Please keep these in the same order as declared above.
167

168         flowStackIndex = 0;
169         startingPointCall = 0;
170         intermediatePointCall = 0;
171         endingPointCall = 0;
172         replyStatus = UNINITIALIZED;
173         currentExecutionPoint = EXECUTION_POINT_STARTING;
174         alreadyExecuted = false;
175     connection = null;
176         serviceContexts = null;
177         forwardRequest = null;
178     forwardRequestIOR = null;
179         exception = null;
180
181         // We don't need to reset the Slots because they are
182
// already in the clean state after recieve_<point> interceptor
183
// are called.
184
}
185
186     /*
187      **********************************************************************
188      * Access protection
189      **********************************************************************/

190
191     // Method IDs for all methods in RequestInfo. This allows for a
192
// convenient O(1) lookup for checkAccess().
193
protected static final int MID_REQUEST_ID = 0;
194     protected static final int MID_OPERATION = 1;
195     protected static final int MID_ARGUMENTS = 2;
196     protected static final int MID_EXCEPTIONS = 3;
197     protected static final int MID_CONTEXTS = 4;
198     protected static final int MID_OPERATION_CONTEXT = 5;
199     protected static final int MID_RESULT = 6;
200     protected static final int MID_RESPONSE_EXPECTED = 7;
201     protected static final int MID_SYNC_SCOPE = 8;
202     protected static final int MID_REPLY_STATUS = 9;
203     protected static final int MID_FORWARD_REFERENCE = 10;
204     protected static final int MID_GET_SLOT = 11;
205     protected static final int MID_GET_REQUEST_SERVICE_CONTEXT = 12;
206     protected static final int MID_GET_REPLY_SERVICE_CONTEXT = 13;
207     // The last value from RequestInfo (be sure to update this):
208
protected static final int MID_RI_LAST = 13;
209     
210     /*
211      **********************************************************************
212      * Public interfaces
213      **********************************************************************/

214          
215     /**
216      * Creates a new RequestInfoImpl object.
217      */

218     public RequestInfoImpl( ORB myORB ) {
219         super();
220         
221         this.myORB = myORB;
222     wrapper = InterceptorsSystemException.get( myORB,
223         CORBALogDomains.RPC_PROTOCOL ) ;
224     stdWrapper = OMGSystemException.get( myORB,
225         CORBALogDomains.RPC_PROTOCOL ) ;
226
227         // Capture the current TSC and make it the RSC of this request.
228
PICurrent current = (PICurrent)(myORB.getPIHandler().getPICurrent());
229         slotTable = current.getSlotTable( );
230     }
231
232     /**
233      * Implementation for request_id() differs for client and server
234      * implementations.
235      *
236      * Uniquely identifies an active request/reply sequence. Once a
237      * request/reply sequence is concluded this ID may be reused. (this
238      * is NOT necessarily the same as the GIOP request_id).
239      */

240     abstract public int request_id ();
241
242     /**
243      * Implementation for operation() differs for client and server
244      * implementations.
245      *
246      * The name of the operation being invoked.
247      */

248     abstract public String JavaDoc operation ();
249
250
251     /**
252      * This method returns the list of arguments for the operation that was
253      * invoked. It raises NO_RESOURCES exception if the operation is not invoked
254      * by using DII mechanism.
255      */

256     abstract public Parameter JavaDoc[] arguments ();
257     
258     /**
259      * This method returns the list of exceptios that was raised when the
260      * operation was invoked. It raises NO_RESOURCES exception if the operation
261      * is not invoked by using DII mechanism.
262      */

263     abstract public TypeCode JavaDoc[] exceptions ();
264     
265     /**
266      * This method returns the list of contexts for the DII operation.
267      * It raises NO_RESOURCES exception if the operation is not invoked by
268      * using DII mechanism.
269      */

270     abstract public String JavaDoc[] contexts ();
271     
272     /**
273      * This method returns the list of operation_context for the DII operation.
274      * It raises NO_RESOURCES exception if the operation is not invoked by
275      * using DII mechanism.
276      */

277     abstract public String JavaDoc[] operation_context ();
278
279     /**
280      * This method returns the result from the invoked DII operation.
281      * It raises NO_RESOURCES exception if the operation is not invoked by
282      * using DII mechanism.
283      */

284     abstract public Any JavaDoc result ();
285     
286     /**
287      * Implementation for response_expected() differs for client and server
288      * implementations.
289      *
290      * Indicates whether a response is expected. On the client, a reply is
291      * not returned when response_expected is false, so receive_reply cannot
292      * be called. receive_other is called unless an exception occurs, in
293      * which case receive_exception is called. On the client, within
294      * send_poll, this attribute is true.
295      */

296     abstract public boolean response_expected ();
297     
298     /**
299      * Defined in the Messaging specification. Pertinent only when
300      * response_expected is false. If response_expected is true, the value
301      * of sync_scope is undefined. It defines how far the request shall
302      * progress before control is returned to the client. This attribute may
303      * have one of the follwing values:
304      * <ul>
305      * <li>Messaging::SYNC_NONE</li>
306      * <li>Messaging::SYNC_WITH_TRANSPORT</li>
307      * <li>Messaging::SYNC_WITH_SERVER</li>
308      * <li>Messaging::SYNC_WITH_TARGET</li>
309      * </ul>
310      */

311     public short sync_scope (){
312         checkAccess( MID_SYNC_SCOPE );
313         return SYNC_WITH_TRANSPORT.value; // REVISIT - get from MessageMediator
314
}
315     
316     /**
317      * Describes the state of the result of the operation invocation. Its
318      * value can be one of the following:
319      * <ul>
320      * <li>PortableInterceptor::SUCCESSFUL</li>
321      * <li>PortableInterceptor::SYSTEM_EXCEPTION</li>
322      * <li>PortableInterceptor::USER_EXCEPTION</li>
323      * <li>PortableInterceptor::LOCATION_FORWARD</li>
324      * <li>PortableInterceptor::TRANSPORT_RETRY</li>
325      * </ul>
326      */

327     public short reply_status (){
328         checkAccess( MID_REPLY_STATUS );
329         return replyStatus;
330     }
331     
332     /**
333      * Implementation for forward_reference() differs for client and server
334      * implementations.
335      *
336      * If the reply_status attribute is LOCATION_FORWARD
337      * then this attribute will contain the object
338      * to which the request will be forwarded. It is indeterminate whether a
339      * forwarded request will actually occur.
340      */

341     abstract public Object JavaDoc forward_reference ();
342
343     
344     /**
345      * Returns the data from the given slot of the PortableInterceptor::Current
346      * that is in the scope of the request.
347      * <p>
348      * If the given slot has not been set, then an any containing a type code
349      * with a TCKind value of tk_null is returned.
350      * <p>
351      * If the ID does not define an allocated slot, InvalidSlot is raised.
352      */

353     public Any JavaDoc get_slot (int id)
354         throws InvalidSlot JavaDoc
355     {
356     // access is currently valid for all states:
357
//checkAccess( MID_GET_SLOT );
358
// Delegate the call to the slotTable which was set when RequestInfo was
359
// created.
360
return slotTable.get_slot( id );
361     }
362
363     /**
364      * Implementation for get_request_service_context() differs for client
365      * and server implementations.
366      *
367      * This operation returns a copy of the service context with the given ID
368      * that is associated with the request. If the request's service context
369      * does not contain an etry for that ID, BAD_PARAM with a minor code of
370      * TBD_BP is raised.
371      */

372     abstract public org.omg.IOP.ServiceContext JavaDoc
373         get_request_service_context(int id);
374
375     /**
376      * Implementation for get_reply_service_context() differs for client
377      * and server implementations.
378      *
379      * This operation returns a copy of the service context with the given ID
380      * that is associated with the reply. IF the request's service context
381      * does not contain an entry for that ID, BAD_PARAM with a minor code of
382      * TBD_BP is raised.
383      */

384     abstract public org.omg.IOP.ServiceContext JavaDoc
385         get_reply_service_context (int id);
386
387     
388     // NOTE: When adding a method, be sure to:
389
// 1. Add a MID_* constant for that method
390
// 2. Call checkAccess at the start of the method
391
// 3. Define entries in the validCall[][] table for interception points
392
// in both ClientRequestInfoImpl and ServerRequestInfoImpl.
393

394
395     
396     /*
397      **********************************************************************
398      * Proprietary methods
399      **********************************************************************/

400
401     /**
402      * @return The connection on which the request is made.
403      *
404      * Note: we store the connection as an internal type but
405      * expose it here as an external type.
406      */

407     public com.sun.corba.se.spi.legacy.connection.Connection connection()
408     {
409     return connection;
410     }
411
412     /*
413      **********************************************************************
414      * Private utility methods
415      **********************************************************************/

416
417     /**
418      * Inserts the UserException inside the given ApplicationException
419      * into the given Any. Throws an UNKNOWN with minor code
420      * OMGSYstemException.UNKNOWN_USER_EXCEPTION if the Helper class could not be
421      * found to insert it with.
422      */

423     private void insertApplicationException( ApplicationException JavaDoc appException,
424                                              Any JavaDoc result )
425         throws UNKNOWN JavaDoc
426     {
427         try {
428             // Extract the UserException from the ApplicationException.
429
// Look up class name from repository id:
430
RepositoryId repId = RepositoryId.cache.getId(
431                 appException.getId() );
432             String JavaDoc className = repId.getClassName();
433            
434             // Find the read method on the helper class:
435
String JavaDoc helperClassName = className + "Helper";
436             Class JavaDoc helperClass = ORBClassLoader.loadClass( helperClassName );
437             Class JavaDoc[] readParams = new Class JavaDoc[1];
438             readParams[0] = org.omg.CORBA.portable.InputStream JavaDoc.class;
439             Method JavaDoc readMethod = helperClass.getMethod( "read", readParams );
440            
441             // Invoke the read method, passing in the input stream to
442
// retrieve the user exception. Mark and reset the stream
443
// as to not disturb it.
444
InputStream JavaDoc ueInputStream = appException.getInputStream();
445             ueInputStream.mark( 0 );
446             UserException JavaDoc userException = null;
447             try {
448                 java.lang.Object JavaDoc[] readArguments = new java.lang.Object JavaDoc[1];
449                 readArguments[0] = ueInputStream;
450                 userException = (UserException JavaDoc)readMethod.invoke(
451                     null, readArguments );
452             }
453             finally {
454                 try {
455                     ueInputStream.reset();
456                 }
457                 catch( IOException JavaDoc e ) {
458             throw wrapper.markAndResetFailed( e ) ;
459                 }
460             }
461
462             // Insert this UserException into the provided Any using the
463
// helper class.
464
insertUserException( userException, result );
465         } catch( ClassNotFoundException JavaDoc e ) {
466         throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ) ;
467         } catch( NoSuchMethodException JavaDoc e ) {
468         throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ) ;
469         } catch( SecurityException JavaDoc e ) {
470         throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ) ;
471         } catch( IllegalAccessException JavaDoc e ) {
472         throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ) ;
473         } catch( IllegalArgumentException JavaDoc e ) {
474         throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ) ;
475         } catch( InvocationTargetException JavaDoc e ) {
476         throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ) ;
477         }
478     }
479
480     /**
481      * Inserts the UserException into the given Any.
482      * Throws an UNKNOWN with minor code
483      * OMGSYstemException.UNKNOWN_USER_EXCEPTION if the Helper class could not be
484      * found to insert it with.
485      */

486     private void insertUserException( UserException JavaDoc userException, Any JavaDoc result )
487         throws UNKNOWN JavaDoc
488     {
489         try {
490             // Insert this UserException into the provided Any using the
491
// helper class.
492
if( userException != null ) {
493         Class JavaDoc exceptionClass = userException.getClass();
494         String JavaDoc className = exceptionClass.getName();
495         String JavaDoc helperClassName = className + "Helper";
496         Class JavaDoc helperClass = ORBClassLoader.loadClass( helperClassName );
497            
498                 // Find insert( Any, class ) method
499
Class JavaDoc[] insertMethodParams = new Class JavaDoc[2];
500                 insertMethodParams[0] = org.omg.CORBA.Any JavaDoc.class;
501                 insertMethodParams[1] = exceptionClass;
502                 Method JavaDoc insertMethod = helperClass.getMethod(
503                     "insert", insertMethodParams );
504
505                 // Call helper.insert( result, userException ):
506
java.lang.Object JavaDoc[] insertMethodArguments =
507                     new java.lang.Object JavaDoc[2];
508                 insertMethodArguments[0] = result;
509                 insertMethodArguments[1] = userException;
510                 insertMethod.invoke( null, insertMethodArguments );
511             }
512         } catch( ClassNotFoundException JavaDoc e ) {
513         throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e );
514         } catch( NoSuchMethodException JavaDoc e ) {
515         throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e );
516         } catch( SecurityException JavaDoc e ) {
517         throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e );
518         } catch( IllegalAccessException JavaDoc e ) {
519         throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e );
520         } catch( IllegalArgumentException JavaDoc e ) {
521         throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e );
522         } catch( InvocationTargetException JavaDoc e ) {
523         throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e );
524         }
525     }
526
527     /*
528      **********************************************************************
529      * Protected utility methods
530      **********************************************************************/

531
532     /**
533      * Internal utility method to convert an NVList into a PI Parameter[]
534      */

535     protected Parameter JavaDoc[] nvListToParameterArray( NVList JavaDoc parNVList ) {
536
537     // _REVISIT_ This utility method should probably be doing a deep
538
// copy so interceptor can't accidentally change the arguments.
539

540         int count = parNVList.count();
541         Parameter JavaDoc[] plist = new Parameter JavaDoc[count];
542         try {
543             for( int i = 0; i < count; i++ ) {
544                 Parameter JavaDoc p = new Parameter JavaDoc();
545                 plist[i] = p;
546                 NamedValue JavaDoc nv = parNVList.item( i );
547                 plist[i].argument = nv.value();
548                 // ParameterMode spec can be found in 99-10-07.pdf
549
// Section:10.5.22
550
// nv.flags spec can be found in 99-10-07.pdf
551
// Section 7.1.1
552
// nv.flags has ARG_IN as 1, ARG_OUT as 2 and ARG_INOUT as 3
553
// To convert this into enum PARAM_IN, PARAM_OUT and
554
// PARAM_INOUT the value is subtracted by 1.
555
plist[i].mode = ParameterMode.from_int( nv.flags() - 1 );
556             }
557         } catch ( Exception JavaDoc e ) {
558         throw wrapper.exceptionInArguments( e ) ;
559         }
560
561         return plist;
562     }
563
564     /**
565      * Utility to wrap the given Exception in an Any object and return it.
566      * If the exception is a UserException which cannot be inserted into
567      * an any, then this returns an Any containing the system exception
568      * UNKNOWN.
569      */

570     protected Any JavaDoc exceptionToAny( Exception JavaDoc exception ){
571         Any JavaDoc result = myORB.create_any();
572
573         if( exception == null ) {
574             // Note: exception should never be null here since we will throw
575
// a BAD_INV_ORDER if this is not called from receive_exception.
576
throw wrapper.exceptionWasNull2() ;
577         } else if( exception instanceof SystemException JavaDoc ) {
578             ORBUtility.insertSystemException(
579                 (SystemException JavaDoc)exception, result );
580         } else if( exception instanceof ApplicationException JavaDoc ) {
581             // Use the Helper class for this exception to insert it into an
582
// Any.
583
try {
584                 // Insert the user exception inside the application exception
585
// into the Any result:
586
ApplicationException JavaDoc appException =
587                     (ApplicationException JavaDoc)exception;
588                 insertApplicationException( appException, result );
589             } catch( UNKNOWN JavaDoc e ) {
590                 // As per ptc/00-08-06, 21.3.13.4. if we cannot find the
591
// appropriate class, then return an any containing UNKNOWN,
592
// with a minor code of 1. This is conveniently the same
593
// exception that is returned from the
594
// insertApplicationException utility method.
595
ORBUtility.insertSystemException( e, result );
596             }
597         } else if( exception instanceof UserException JavaDoc ) {
598         try {
599         UserException JavaDoc userException = (UserException JavaDoc)exception;
600         insertUserException( userException, result );
601         } catch( UNKNOWN JavaDoc e ) {
602                 ORBUtility.insertSystemException( e, result );
603         }
604     }
605
606
607         return result;
608     }
609
610     /**
611      * Utility method to look up a service context with the given id and
612      * convert it to an IOP.ServiceContext. Uses the given HashMap as
613      * a cache. If not found in cache, the result is inserted in the cache.
614      */

615     protected org.omg.IOP.ServiceContext JavaDoc
616         getServiceContext ( HashMap JavaDoc cachedServiceContexts,
617                 ServiceContexts serviceContexts, int id )
618     {
619         org.omg.IOP.ServiceContext JavaDoc result = null;
620         Integer JavaDoc integerId = new Integer JavaDoc( id );
621
622     // Search cache first:
623
result = (org.omg.IOP.ServiceContext JavaDoc)
624         cachedServiceContexts.get( integerId );
625
626     // null could normally mean that either we cached the value null
627
// or it's not in the cache. However, there is no way for us to
628
// cache the value null in the following code.
629
if( result == null ) {
630         // Not in cache. Find it and put in cache.
631
// Get the desired "core" service context.
632
com.sun.corba.se.spi.servicecontext.ServiceContext context =
633         serviceContexts.get( id );
634         if (context == null)
635         throw stdWrapper.invalidServiceContextId() ;
636
637         // Convert the "core" service context to an
638
// "IOP" ServiceContext by writing it to a
639
// CDROutputStream and reading it back.
640
EncapsOutputStream out = new EncapsOutputStream(myORB);
641
642         context.write( out, GIOPVersion.V1_2 );
643         InputStream JavaDoc inputStream = out.create_input_stream();
644         result = ServiceContextHelper.read( inputStream );
645
646         cachedServiceContexts.put( integerId, result );
647     }
648
649     // Good citizen: For increased efficiency, we assume that interceptors
650
// will not modify the returned ServiceContext. Otherwise, we would
651
// have to make a deep copy.
652

653         return result;
654     }
655
656
657     /**
658      * Utility method to add an IOP.ServiceContext to a core.ServiceContexts
659      * object. If replace is true, any service context with the given id
660      * is replaced.
661      * <p>
662      * Raises BAD_INV_ORDER if replace is false and a service context with
663      * the given id already exists.
664      * <p>
665      * Uses the given HashMap as a cache. If a service context is placed
666      * in the container, it goes in the HashMap as well.
667      */

668     protected void addServiceContext(
669     HashMap JavaDoc cachedServiceContexts,
670     ServiceContexts serviceContexts,
671     org.omg.IOP.ServiceContext JavaDoc service_context,
672     boolean replace )
673     {
674     int id = 0 ;
675     // Convert IOP.service_context to core.ServiceContext:
676
EncapsOutputStream outputStream = new EncapsOutputStream(
677         myORB );
678     InputStream JavaDoc inputStream = null;
679     UnknownServiceContext coreServiceContext = null;
680     ServiceContextHelper.write( outputStream, service_context );
681     inputStream = outputStream.create_input_stream();
682
683     // Constructor expects id to already have been read from stream.
684
coreServiceContext = new UnknownServiceContext(
685         inputStream.read_long(),
686         (org.omg.CORBA_2_3.portable.InputStream JavaDoc)inputStream );
687
688     id = coreServiceContext.getId();
689
690     if (serviceContexts.get(id) != null)
691         if (replace)
692         serviceContexts.delete( id );
693         else
694         throw stdWrapper.serviceContextAddFailed( new Integer JavaDoc(id) ) ;
695
696     serviceContexts.put( coreServiceContext );
697
698     // Place IOP.ServiceContext in cache as well:
699
cachedServiceContexts.put( new Integer JavaDoc( id ), service_context );
700     }
701
702     /**
703      * Sets the number of interceptors whose starting interception
704      * points were successfully invoked on this client call. As specified
705      * in orbos/99-12-02, section 5.2.1., not all interceptors will
706      * be invoked if a ForwardRequest exception or a system exception
707      * is raised. This keeps track of how many were successfully executed
708      * so we know not to execute the corresponding ending interception
709      * points for the interceptors whose starting interception points
710      * were not completed. This simulates the "Flow Stack Visual Model"
711      * presented in section 5.1.3.*/

712     protected void setFlowStackIndex(int num ) {
713         this.flowStackIndex = num;
714     }
715
716     /**
717      * Returns the number of interceptors whose starting interception
718      * points were actually invoked on this client request. See
719      * setFlowStackIndex for more details.
720      */

721     protected int getFlowStackIndex() {
722         return this.flowStackIndex;
723     }
724
725     /**
726      * Sets which ending interception point should be called
727      * for each interceptor in the virtual flow stack.
728      */

729     protected void setEndingPointCall( int call ) {
730         this.endingPointCall = call;
731     }
732
733     /**
734      * Retrieves the current ending point call type (see
735      * setEndingPointCall for more details).
736      */

737     protected int getEndingPointCall() {
738         return this.endingPointCall;
739     }
740
741     /**
742      * Sets which intermediate interception point should be called
743      * for each interceptor in the virtual flow stack.
744      */

745     protected void setIntermediatePointCall( int call ) {
746         this.intermediatePointCall = call;
747     }
748
749     /**
750      * Retrieves the current intermediate point call type (see
751      * setEndingPointCall for more details).
752      */

753     protected int getIntermediatePointCall() {
754         return this.intermediatePointCall;
755     }
756     
757     /**
758      * Sets which starting interception point should be called
759      * for each interceptor in the virtual flow stack.
760      */

761     protected void setStartingPointCall( int call ) {
762         this.startingPointCall = call;
763     }
764
765     /**
766      * Retrieves the current starting point call type (see
767      * setStartingPointCall for more details).
768      */

769     protected int getStartingPointCall() {
770         return this.startingPointCall;
771     }
772     
773     /**
774      * Returns true if all interceptors' starting and ending points
775      * have already executed to completion, or false if not yet.
776      */

777     protected boolean getAlreadyExecuted() {
778         return this.alreadyExecuted;
779     }
780     
781     /**
782      * Sets whether all interceotrs' starting and ending points
783      * have already been executed to completion.
784      */

785     protected void setAlreadyExecuted( boolean alreadyExecuted ) {
786         this.alreadyExecuted = alreadyExecuted;
787     }
788     
789     /**
790      * Sets the value to be returned by reply_status
791      */

792     protected void setReplyStatus( short replyStatus ) {
793         this.replyStatus = replyStatus;
794     }
795     
796     /**
797      * Gets the current reply_status without doing an access check
798      * (available only to package and subclasses)
799      */

800     protected short getReplyStatus() {
801         return this.replyStatus;
802     }
803     
804     /**
805      * Stores the given ForwardRequest object for later analysis.
806      * This version supplements setForwardRequest( IOR );
807      */

808     protected void setForwardRequest( ForwardRequest JavaDoc forwardRequest ) {
809         this.forwardRequest = forwardRequest;
810     this.forwardRequestIOR = null;
811     }
812
813     /**
814      * Stores the given IOR for later forward request analysis.
815      * This version supplements setForwardRequest( ForwardRequest );
816      */

817     protected void setForwardRequest( IOR ior ) {
818     this.forwardRequestIOR = ior;
819     this.forwardRequest = null;
820     }
821     
822     /**
823      * Retrieves the ForwardRequest object as a ForwardRequest exception.
824      */

825     protected ForwardRequest JavaDoc getForwardRequestException() {
826     if( this.forwardRequest == null ) {
827         if( this.forwardRequestIOR != null ) {
828         // Convert the internal IOR to a forward request exception
829
// by creating an object reference.
830
org.omg.CORBA.Object JavaDoc obj = iorToObject(this.forwardRequestIOR);
831         this.forwardRequest = new ForwardRequest JavaDoc( obj );
832         }
833     }
834
835         return this.forwardRequest;
836     }
837
838     /**
839      * Retrieves the IOR of the ForwardRequest exception.
840      */

841     protected IOR getForwardRequestIOR() {
842     if( this.forwardRequestIOR == null ) {
843         if( this.forwardRequest != null ) {
844         this.forwardRequestIOR = ORBUtility.getIOR(
845             this.forwardRequest.forward ) ;
846         }
847     }
848
849     return this.forwardRequestIOR;
850     }
851     
852     /**
853      * Sets the exception to be returned by received_exception and
854      * received_exception_id.
855      */

856     protected void setException( Exception JavaDoc exception ) {
857         this.exception = exception;
858     }
859     
860     /**
861      * Returns the exception to be returned by received_exception and
862      * received_exception_id.
863      */

864     Exception JavaDoc getException() {
865         return this.exception;
866     }
867    
868     /**
869      * Sets the execution point that we are currently executing
870      * (starting points, intermediate points, or ending points).
871      * This allows us to enforce the validity table.
872      */

873     protected void setCurrentExecutionPoint( int executionPoint ) {
874         this.currentExecutionPoint = executionPoint;
875     }
876
877     /**
878      * Check whether the caller is allowed to access this method at
879      * this particular time. This is overridden in subclasses to implement
880      * the validity table specified in ptc/00-04-05, table 21-1 and 21-2.
881      * The currentExecutionPoint attribute is checked, and if access is
882      * forbidden at this time, BAD_INV_ORDER is raised with a minor code of
883      * TBD_BIO.
884      *
885      * @param methodID The ID of this method, one of the MID_* constants.
886      * This allows us to easily look up the method access in a table.
887      * Note that method ids may overlap between subclasses.
888      */

889     protected abstract void checkAccess( int methodID )
890         throws BAD_INV_ORDER JavaDoc;
891
892     /**
893      * The server side does an explicit set rather than taking the
894      * current PICurrent table as is done in the general RequestInfoImpl
895      * constructor.
896      */

897     void setSlotTable(SlotTable slotTable)
898     {
899     this.slotTable = slotTable;
900     }
901
902     protected org.omg.CORBA.Object JavaDoc iorToObject( IOR ior )
903     {
904     return ORBUtility.makeObjectReference( ior ) ;
905     }
906 }
907
Popular Tags