1. /*
  2. * @(#)ReplyMessage_1_1.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.1 Reply header.
  24. *
  25. * @author Ram Jeyaraman 05/14/2000
  26. * @version 1.0
  27. */
  28. public final class ReplyMessage_1_1 extends Message_1_1
  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_1(ORB orb) {
  42. this.orb = orb;
  43. this.wrapper = ORBUtilSystemException.get( orb,
  44. CORBALogDomains.RPC_PROTOCOL ) ;
  45. }
  46. ReplyMessage_1_1(ORB orb, ServiceContexts _service_contexts,
  47. int _request_id, int _reply_status, IOR _ior) {
  48. super(Message.GIOPBigMagic, GIOPVersion.V1_1, FLAG_NO_FRAG_BIG_ENDIAN,
  49. Message.GIOPReply, 0);
  50. this.orb = orb;
  51. this.wrapper = ORBUtilSystemException.get( orb,
  52. CORBALogDomains.RPC_PROTOCOL ) ;
  53. service_contexts = _service_contexts;
  54. request_id = _request_id;
  55. reply_status = _reply_status;
  56. ior = _ior;
  57. }
  58. // Accessor methods
  59. public int getRequestId() {
  60. return this.request_id;
  61. }
  62. public int getReplyStatus() {
  63. return this.reply_status;
  64. }
  65. public short getAddrDisposition() {
  66. return KeyAddr.value;
  67. }
  68. public ServiceContexts getServiceContexts() {
  69. return this.service_contexts;
  70. }
  71. public void setServiceContexts( ServiceContexts sc ) {
  72. this.service_contexts = sc;
  73. }
  74. public SystemException getSystemException(String message) {
  75. return MessageBase.getSystemException(
  76. exClassName, minorCode, completionStatus, message, wrapper);
  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 wrapper.badCompletionStatusInReply(
  111. CompletionStatus.COMPLETED_MAYBE, new Integer(status) );
  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 = IORFactories.makeIOR(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. ORBUtilSystemException localWrapper = ORBUtilSystemException.get(
  145. CORBALogDomains.RPC_PROTOCOL ) ;
  146. throw localWrapper.illegalReplyStatus( CompletionStatus.COMPLETED_MAYBE);
  147. }
  148. }
  149. public void callback(MessageHandler handler)
  150. throws java.io.IOException
  151. {
  152. handler.handleInput(this);
  153. }
  154. } //