1. /*
  2. * @(#)ReplyMessage_1_2.java 1.19 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. package com.sun.corba.se.internal.iiop.messages;
  8. import org.omg.CORBA.INTERNAL;
  9. import org.omg.CORBA.SystemException;
  10. import org.omg.CORBA.CompletionStatus;
  11. import com.sun.corba.se.internal.core.ServiceContexts;
  12. import com.sun.corba.se.internal.core.GIOPVersion;
  13. import com.sun.corba.se.internal.orbutil.MinorCodes;
  14. import com.sun.corba.se.internal.orbutil.ORBUtility;
  15. import com.sun.corba.se.internal.orbutil.ORBClassLoader;
  16. import com.sun.corba.se.internal.core.IOR;
  17. import com.sun.corba.se.internal.iiop.CDRInputStream;
  18. import com.sun.corba.se.internal.iiop.CDROutputStream;
  19. import com.sun.corba.se.internal.iiop.ORB;
  20. import com.sun.corba.se.internal.orbutil.ORBConstants;
  21. /**
  22. * This implements the GIOP 1.2 Reply header.
  23. *
  24. * @author Ram Jeyaraman 05/14/2000
  25. * @version 1.0
  26. */
  27. public final class ReplyMessage_1_2 extends Message_1_2
  28. implements ReplyMessage {
  29. // Instance variables
  30. private ORB orb = null;
  31. private int reply_status = (int) 0;
  32. private ServiceContexts service_contexts = null;
  33. private IOR ior = null;
  34. private String exClassName = null;
  35. private int minorCode = (int) 0;
  36. private CompletionStatus completionStatus = null;
  37. private short addrDisposition = KeyAddr.value; // default;
  38. // Constructors
  39. ReplyMessage_1_2(ORB orb) {
  40. this.orb = orb;
  41. }
  42. ReplyMessage_1_2(ORB orb, int _request_id, int _reply_status,
  43. ServiceContexts _service_contexts, IOR _ior) {
  44. super(Message.GIOPBigMagic, GIOPVersion.V1_2, FLAG_NO_FRAG_BIG_ENDIAN,
  45. Message.GIOPReply, 0);
  46. this.orb = orb;
  47. request_id = _request_id;
  48. reply_status = _reply_status;
  49. service_contexts = _service_contexts;
  50. ior = _ior;
  51. }
  52. // Accessor methods
  53. public int getRequestId() {
  54. return this.request_id;
  55. }
  56. public int getReplyStatus() {
  57. return this.reply_status;
  58. }
  59. public short getAddrDisposition() {
  60. return this.addrDisposition;
  61. }
  62. public ServiceContexts getServiceContexts() {
  63. return this.service_contexts;
  64. }
  65. public void setServiceContexts( ServiceContexts sc ) {
  66. this.service_contexts = sc;
  67. }
  68. public SystemException getSystemException() {
  69. SystemException sysEx = null;
  70. try {
  71. sysEx = (SystemException) ORBClassLoader.loadClass(exClassName).newInstance();
  72. } catch (Exception someEx) {
  73. throw new INTERNAL("BAD SystemException: " + exClassName,
  74. 0, CompletionStatus.COMPLETED_MAYBE);
  75. }
  76. sysEx.minor = minorCode;
  77. sysEx.completed = completionStatus;
  78. return sysEx;
  79. }
  80. public IOR getIOR() {
  81. return this.ior;
  82. }
  83. public void setIOR( IOR ior ) {
  84. this.ior = ior;
  85. }
  86. // IO methods
  87. public void read(org.omg.CORBA.portable.InputStream istream) {
  88. super.read(istream);
  89. this.request_id = istream.read_ulong();
  90. this.reply_status = istream.read_long();
  91. isValidReplyStatus(this.reply_status); // raises exception on error
  92. this.service_contexts
  93. = new ServiceContexts((org.omg.CORBA_2_3.portable.InputStream) istream);
  94. // CORBA formal 00-11-0 15.4.2.2 GIOP 1.2 body must be
  95. // aligned on an 8 octet boundary.
  96. ((CDRInputStream)istream).alignOnBoundary(ORBConstants.GIOP_12_MSG_BODY_ALIGNMENT);
  97. // The code below reads the reply body in some cases
  98. // SYSTEM_EXCEPTION & LOCATION_FORWARD & LOCATION_FORWARD_PERM &
  99. // NEEDS_ADDRESSING_MODE
  100. if (this.reply_status == SYSTEM_EXCEPTION) {
  101. String reposId = istream.read_string();
  102. this.exClassName = ORBUtility.classNameOf(reposId);
  103. this.minorCode = istream.read_long();
  104. int status = istream.read_long();
  105. switch (status) {
  106. case CompletionStatus._COMPLETED_YES:
  107. this.completionStatus = CompletionStatus.COMPLETED_YES;
  108. break;
  109. case CompletionStatus._COMPLETED_NO:
  110. this.completionStatus = CompletionStatus.COMPLETED_NO;
  111. break;
  112. case CompletionStatus._COMPLETED_MAYBE:
  113. this.completionStatus = CompletionStatus.COMPLETED_MAYBE;
  114. break;
  115. default:
  116. throw new INTERNAL("BAD completion status: " + status,
  117. 0, CompletionStatus.COMPLETED_MAYBE);
  118. }
  119. } else if (this.reply_status == USER_EXCEPTION) {
  120. // do nothing. The client stub will read the exception from body.
  121. } else if ( (this.reply_status == LOCATION_FORWARD) ||
  122. (this.reply_status == LOCATION_FORWARD_PERM) ){
  123. CDRInputStream cdr = (CDRInputStream) istream;
  124. this.ior = new IOR( cdr ) ;
  125. } else if (this.reply_status == NEEDS_ADDRESSING_MODE) {
  126. // read GIOP::AddressingDisposition from body and resend the
  127. // original request using the requested addressing mode. The
  128. // resending is transparent to the client program.
  129. this.addrDisposition = AddressingDispositionHelper.read(istream);
  130. }
  131. }
  132. // Note, this writes only the header information. SystemException or
  133. // IOR or GIOP::AddressingDisposition may be written afterwards into the
  134. // reply mesg body.
  135. public void write(org.omg.CORBA.portable.OutputStream ostream) {
  136. super.write(ostream);
  137. ostream.write_ulong(this.request_id);
  138. ostream.write_long(this.reply_status);
  139. if (this.service_contexts != null) {
  140. service_contexts.write(
  141. (org.omg.CORBA_2_3.portable.OutputStream) ostream,
  142. GIOPVersion.V1_2);
  143. } else {
  144. ServiceContexts.writeNullServiceContext(
  145. (org.omg.CORBA_2_3.portable.OutputStream) ostream);
  146. }
  147. // CORBA formal 00-11-0 15.4.2.2 GIOP 1.2 body must be
  148. // aligned on an 8 octet boundary.
  149. ((CDROutputStream)ostream).alignOnBoundary(ORBConstants.GIOP_12_MSG_BODY_ALIGNMENT);
  150. }
  151. // Static methods
  152. public static void isValidReplyStatus(int replyStatus) {
  153. switch (replyStatus) {
  154. case NO_EXCEPTION :
  155. case USER_EXCEPTION :
  156. case SYSTEM_EXCEPTION :
  157. case LOCATION_FORWARD :
  158. case LOCATION_FORWARD_PERM :
  159. case NEEDS_ADDRESSING_MODE :
  160. break;
  161. default :
  162. throw new INTERNAL(MinorCodes.ILLEGAL_REPLY_STATUS,
  163. CompletionStatus.COMPLETED_MAYBE);
  164. }
  165. }
  166. public final void callback(com.sun.corba.se.internal.iiop.MessageMediator m)
  167. throws java.io.IOException
  168. {
  169. m.handleInput(this);
  170. }
  171. } // class ReplyMessage_1_2