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