1. /*
  2. * @(#)ReplyMessage_1_0.java 1.20 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.protocol.giopmsgheaders;
  8. import org.omg.CORBA.INTERNAL;
  9. import org.omg.CORBA.CompletionStatus;
  10. import org.omg.CORBA.SystemException;
  11. import com.sun.corba.se.spi.ior.IOR;
  12. import com.sun.corba.se.spi.ior.IORFactories;
  13. import com.sun.corba.se.spi.orb.ORB;
  14. import com.sun.corba.se.spi.servicecontext.ServiceContexts;
  15. import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
  16. import com.sun.corba.se.impl.orbutil.ORBUtility;
  17. import com.sun.corba.se.impl.orbutil.ORBClassLoader;
  18. import com.sun.corba.se.spi.ior.IOR;
  19. import com.sun.corba.se.impl.encoding.CDRInputStream;
  20. import com.sun.corba.se.spi.logging.CORBALogDomains ;
  21. import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
  22. /**
  23. * This implements the GIOP 1.0 Reply header.
  24. *
  25. * @author Ram Jeyaraman 05/14/2000
  26. * @version 1.0
  27. */
  28. public final class ReplyMessage_1_0 extends Message_1_0
  29. implements ReplyMessage {
  30. // Instance variables
  31. private ORB orb = null;
  32. private ORBUtilSystemException wrapper = null ;
  33. private ServiceContexts service_contexts = null;
  34. private int request_id = (int) 0;
  35. private int reply_status = (int) 0;
  36. private IOR ior = null;
  37. private String exClassName = null;
  38. private int minorCode = (int) 0;
  39. private CompletionStatus completionStatus = null;
  40. // Constructors
  41. ReplyMessage_1_0(ORB orb) {
  42. this.orb = orb;
  43. this.wrapper = ORBUtilSystemException.get( orb,
  44. CORBALogDomains.RPC_PROTOCOL ) ;
  45. }
  46. ReplyMessage_1_0(ORB orb, ServiceContexts _service_contexts,
  47. int _request_id, int _reply_status, IOR _ior) {
  48. super(Message.GIOPBigMagic, false, Message.GIOPReply, 0);
  49. this.orb = orb;
  50. this.wrapper = ORBUtilSystemException.get( orb,
  51. CORBALogDomains.RPC_PROTOCOL ) ;
  52. service_contexts = _service_contexts;
  53. request_id = _request_id;
  54. reply_status = _reply_status;
  55. ior = _ior;
  56. }
  57. // Accessor methods
  58. public int getRequestId() {
  59. return this.request_id;
  60. }
  61. public int getReplyStatus() {
  62. return this.reply_status;
  63. }
  64. public short getAddrDisposition() {
  65. return KeyAddr.value;
  66. }
  67. public ServiceContexts getServiceContexts() {
  68. return this.service_contexts;
  69. }
  70. public void setServiceContexts( ServiceContexts sc ) {
  71. this.service_contexts = sc;
  72. }
  73. public SystemException getSystemException(String message) {
  74. return MessageBase.getSystemException(
  75. exClassName, minorCode, completionStatus, message, wrapper);
  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 wrapper.badCompletionStatusInReply(
  110. CompletionStatus.COMPLETED_MAYBE, new Integer(status) );
  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 = IORFactories.makeIOR( 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. ORBUtilSystemException localWrapper = ORBUtilSystemException.get(
  144. CORBALogDomains.RPC_PROTOCOL ) ;
  145. throw localWrapper.illegalReplyStatus( CompletionStatus.COMPLETED_MAYBE);
  146. }
  147. }
  148. public void callback(MessageHandler handler)
  149. throws java.io.IOException
  150. {
  151. handler.handleInput(this);
  152. }
  153. } //