1. /*
  2. * @(#)SubcontractResponseHandler.java 1.20 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. // Mortazavi 99/05/25
  8. package com.sun.corba.se.internal.POA;
  9. import org.omg.PortableServer.*;
  10. import org.omg.CORBA.portable.*;
  11. import org.omg.CORBA.INTERNAL ;
  12. import com.sun.corba.se.internal.core.ServerRequest;
  13. import com.sun.corba.se.internal.core.ServiceContext;
  14. import com.sun.corba.se.internal.core.DuplicateServiceContext;
  15. import com.sun.corba.se.internal.core.SendingContextServiceContext;
  16. import com.sun.corba.se.internal.core.ORBVersionServiceContext;
  17. import com.sun.corba.se.internal.core.ORBVersionFactory;
  18. import com.sun.corba.se.internal.core.ServiceContexts;
  19. import com.sun.corba.se.internal.core.ServerResponse;
  20. import com.sun.corba.se.internal.core.MarshalOutputStream;
  21. import com.sun.corba.se.internal.iiop.Connection;
  22. import com.sun.corba.se.internal.orbutil.ORBUtility;
  23. import com.sun.corba.se.internal.ior.ObjectKey ;
  24. import com.sun.corba.se.internal.ior.ObjectKeyFactory ;
  25. public class SubcontractResponseHandler
  26. implements org.omg.CORBA.portable.ResponseHandler
  27. {
  28. private com.sun.corba.se.internal.core.ServerRequest serverRequest;
  29. private org.omg.CORBA.ORB orb;
  30. public
  31. SubcontractResponseHandler(com.sun.corba.se.internal.core.ServerRequest req, org.omg.CORBA.ORB scOrb)
  32. {
  33. serverRequest = req;
  34. orb = scOrb;
  35. }
  36. public
  37. org.omg.CORBA.portable.OutputStream
  38. createReply()
  39. {
  40. return (org.omg.CORBA.portable.OutputStream)
  41. serverRequest.createResponse(
  42. getServiceContextsForReply(
  43. serverRequest.getConnection()));
  44. }
  45. public
  46. org.omg.CORBA.portable.OutputStream
  47. createExceptionReply()
  48. {
  49. return
  50. (org.omg.CORBA.portable.OutputStream)
  51. serverRequest.createUserExceptionResponse(
  52. getServiceContextsForReply(
  53. serverRequest.getConnection()));
  54. }
  55. private
  56. ServiceContexts
  57. getServiceContextsForReply(Connection c)
  58. {
  59. com.sun.corba.se.internal.corba.ORB theOrb = (com.sun.corba.se.internal.corba.ORB)orb ;
  60. /*
  61. if (theOrb.subcontractDebugFlag)
  62. dprint( "getServiceContextsReply called with connection " + c ) ;
  63. */
  64. ServiceContexts contexts = new ServiceContexts( theOrb ) ;
  65. // NOTE : We only want to send the runtime context the first time
  66. if (c!=null && !c.isPostInitialContexts()) {
  67. /*
  68. if (theOrb.subcontractDebugFlag)
  69. dprint( "Adding SendingContextServiceContext" ) ;
  70. */
  71. c.setPostInitialContexts();
  72. SendingContextServiceContext scsc =
  73. new SendingContextServiceContext(theOrb.getServantIOR()) ; //d11638
  74. try {
  75. contexts.put( scsc ) ;
  76. } catch (DuplicateServiceContext dsc) {
  77. }
  78. }
  79. // send ORBVersion servicecontext as part of the Reply
  80. ORBVersionServiceContext ovsc = new ORBVersionServiceContext(
  81. ORBVersionFactory.getORBVersion());
  82. try {
  83. contexts.put( ovsc ) ;
  84. } catch (DuplicateServiceContext dsc) {
  85. throw new INTERNAL() ;
  86. }
  87. /*
  88. if (theOrb.subcontractDebugFlag)
  89. dprint( "Checking for transaction support" ) ;
  90. */
  91. com.sun.corba.se.internal.POA.POAORB myorb ;
  92. try {
  93. myorb = (com.sun.corba.se.internal.POA.POAORB)orb;
  94. } catch (ClassCastException cce) {
  95. /*
  96. if (theOrb.subcontractDebugFlag)
  97. dprint( "Non-POA ORB: returning normally" ) ;
  98. */
  99. // This is not the POA ORB, so it can't be transactional:
  100. // just return the current contexts.
  101. return contexts ;
  102. }
  103. ObjectKey okey = serverRequest.getObjectKey();
  104. int tscid = okey.getTemplate().getSubcontractId() ;
  105. myorb.getServiceSpecificServiceContexts(tscid, serverRequest, contexts);
  106. try {
  107. ((com.sun.corba.se.internal.POA.POAORB)theOrb).
  108. sendingReplyServiceContexts(contexts);
  109. } catch (Throwable ex) {
  110. ; //Do not let hook errors escape.
  111. }
  112. /*
  113. if (theOrb.subcontractDebugFlag)
  114. dprint( "getServiceContextsReply completed successfuly" ) ;
  115. */
  116. return contexts;
  117. }
  118. }