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