1. /*
  2. * @(#)LocateReplyMessage_1_2.java 1.18 03/12/19
  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.SystemException;
  10. import org.omg.CORBA.CompletionStatus;
  11. import com.sun.corba.se.spi.orb.ORB;
  12. import com.sun.corba.se.spi.ior.IOR;
  13. import com.sun.corba.se.spi.ior.IORFactories;
  14. import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
  15. import com.sun.corba.se.impl.encoding.CDRInputStream;
  16. import com.sun.corba.se.impl.encoding.CDROutputStream;
  17. import com.sun.corba.se.impl.orbutil.ORBUtility;
  18. import com.sun.corba.se.impl.orbutil.ORBConstants;
  19. import com.sun.corba.se.impl.orbutil.ORBClassLoader;
  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.2 LocateReply header.
  24. *
  25. * @author Ram Jeyaraman 05/14/2000
  26. * @version 1.0
  27. */
  28. public final class LocateReplyMessage_1_2 extends Message_1_2
  29. implements LocateReplyMessage {
  30. // Instance variables
  31. private ORB orb = null;
  32. private ORBUtilSystemException wrapper = null ;
  33. private int reply_status = (int) 0;
  34. private IOR ior = null;
  35. private String exClassName = null;
  36. private int minorCode = (int) 0;
  37. private CompletionStatus completionStatus = null;
  38. private short addrDisposition = KeyAddr.value; // default;
  39. // Constructors
  40. LocateReplyMessage_1_2(ORB orb) {
  41. this.orb = orb;
  42. this.wrapper = ORBUtilSystemException.get( orb,
  43. CORBALogDomains.RPC_PROTOCOL ) ;
  44. }
  45. LocateReplyMessage_1_2(ORB orb, int _request_id,
  46. int _reply_status, IOR _ior) {
  47. super(Message.GIOPBigMagic, GIOPVersion.V1_2, FLAG_NO_FRAG_BIG_ENDIAN,
  48. Message.GIOPLocateReply, 0);
  49. this.orb = orb;
  50. this.wrapper = ORBUtilSystemException.get( orb,
  51. CORBALogDomains.RPC_PROTOCOL ) ;
  52. request_id = _request_id;
  53. reply_status = _reply_status;
  54. ior = _ior;
  55. }
  56. // Accessor methods
  57. public int getRequestId() {
  58. return this.request_id;
  59. }
  60. public int getReplyStatus() {
  61. return this.reply_status;
  62. }
  63. public short getAddrDisposition() {
  64. return this.addrDisposition;
  65. }
  66. public SystemException getSystemException(String message) {
  67. return MessageBase.getSystemException(
  68. exClassName, minorCode, completionStatus, message, wrapper);
  69. }
  70. public IOR getIOR() {
  71. return this.ior;
  72. }
  73. // IO methods
  74. public void read(org.omg.CORBA.portable.InputStream istream) {
  75. super.read(istream);
  76. this.request_id = istream.read_ulong();
  77. this.reply_status = istream.read_long();
  78. isValidReplyStatus(this.reply_status); // raises exception on error
  79. // GIOP 1.2 LocateReply message bodies are not aligned on
  80. // 8 byte boundaries.
  81. // The code below reads the reply body in some cases
  82. // LOC_SYSTEM_EXCEPTION & OBJECT_FORWARD & OBJECT_FORWARD_PERM &
  83. // LOC_NEEDS_ADDRESSING_MODE
  84. if (this.reply_status == LOC_SYSTEM_EXCEPTION) {
  85. String reposId = istream.read_string();
  86. this.exClassName = ORBUtility.classNameOf(reposId);
  87. this.minorCode = istream.read_long();
  88. int status = istream.read_long();
  89. switch (status) {
  90. case CompletionStatus._COMPLETED_YES:
  91. this.completionStatus = CompletionStatus.COMPLETED_YES;
  92. break;
  93. case CompletionStatus._COMPLETED_NO:
  94. this.completionStatus = CompletionStatus.COMPLETED_NO;
  95. break;
  96. case CompletionStatus._COMPLETED_MAYBE:
  97. this.completionStatus = CompletionStatus.COMPLETED_MAYBE;
  98. break;
  99. default:
  100. throw wrapper.badCompletionStatusInLocateReply(
  101. CompletionStatus.COMPLETED_MAYBE, new Integer(status) );
  102. }
  103. } else if ( (this.reply_status == OBJECT_FORWARD) ||
  104. (this.reply_status == OBJECT_FORWARD_PERM) ){
  105. CDRInputStream cdr = (CDRInputStream) istream;
  106. this.ior = IORFactories.makeIOR( cdr ) ;
  107. } else if (this.reply_status == LOC_NEEDS_ADDRESSING_MODE) {
  108. // read GIOP::AddressingDisposition from body and resend the
  109. // original request using the requested addressing mode. The
  110. // resending is transparent to the caller.
  111. this.addrDisposition = AddressingDispositionHelper.read(istream);
  112. }
  113. }
  114. // Note, this writes only the header information. SystemException or
  115. // IOR or GIOP::AddressingDisposition may be written afterwards into the
  116. // reply mesg body.
  117. public void write(org.omg.CORBA.portable.OutputStream ostream) {
  118. super.write(ostream);
  119. ostream.write_ulong(this.request_id);
  120. ostream.write_long(this.reply_status);
  121. // GIOP 1.2 LocateReply message bodies are not aligned on
  122. // 8 byte boundaries.
  123. }
  124. // Static methods
  125. public static void isValidReplyStatus(int replyStatus) {
  126. switch (replyStatus) {
  127. case UNKNOWN_OBJECT :
  128. case OBJECT_HERE :
  129. case OBJECT_FORWARD :
  130. case OBJECT_FORWARD_PERM :
  131. case LOC_SYSTEM_EXCEPTION :
  132. case LOC_NEEDS_ADDRESSING_MODE :
  133. break;
  134. default :
  135. ORBUtilSystemException localWrapper = ORBUtilSystemException.get(
  136. CORBALogDomains.RPC_PROTOCOL ) ;
  137. throw localWrapper.illegalReplyStatus( CompletionStatus.COMPLETED_MAYBE);
  138. }
  139. }
  140. public void callback(MessageHandler handler)
  141. throws java.io.IOException
  142. {
  143. handler.handleInput(this);
  144. }
  145. } // class LocateReplyMessage_1_2