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