1. /*
  2. * @(#)Message_1_1.java 1.9 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 com.sun.corba.se.internal.core.GIOPVersion;
  11. import com.sun.corba.se.internal.orbutil.MinorCodes;
  12. /*
  13. * This implements the GIOP 1.1 & 1.2 Message header.
  14. *
  15. * @author Ram Jeyaraman 05/14/2000
  16. * @version 1.0
  17. */
  18. public class Message_1_1
  19. extends com.sun.corba.se.internal.iiop.messages.MessageBase {
  20. // Instance variables
  21. int magic = (int) 0;
  22. GIOPVersion GIOP_version = null;
  23. byte flags = (byte) 0;
  24. byte message_type = (byte) 0;
  25. int message_size = (int) 0;
  26. // Constructor
  27. Message_1_1() {}
  28. Message_1_1(int _magic, GIOPVersion _GIOP_version, byte _flags,
  29. byte _message_type, int _message_size) {
  30. magic = _magic;
  31. GIOP_version = _GIOP_version;
  32. flags = _flags;
  33. message_type = _message_type;
  34. message_size = _message_size;
  35. }
  36. // Accessor methods
  37. public GIOPVersion getGIOPVersion() {
  38. return this.GIOP_version;
  39. }
  40. public int getType() {
  41. return this.message_type;
  42. }
  43. public int getSize() {
  44. return this.message_size;
  45. }
  46. public boolean isLittleEndian() {
  47. return ((this.flags & LITTLE_ENDIAN_BIT) == LITTLE_ENDIAN_BIT);
  48. }
  49. public boolean moreFragmentsToFollow() {
  50. return ( (this.flags & MORE_FRAGMENTS_BIT) == MORE_FRAGMENTS_BIT );
  51. }
  52. // Mutator methods
  53. public void setSize(byte[] buf, int size) {
  54. this.message_size = size;
  55. //
  56. // Patch the size field in the header.
  57. //
  58. int patch = size - GIOPMessageHeaderLength;
  59. if (!isLittleEndian()) {
  60. buf[8] = (byte)((patch >>> 24) & 0xFF);
  61. buf[9] = (byte)((patch >>> 16) & 0xFF);
  62. buf[10] = (byte)((patch >>> 8) & 0xFF);
  63. buf[11] = (byte)((patch >>> 0) & 0xFF);
  64. } else {
  65. buf[8] = (byte)((patch >>> 0) & 0xFF);
  66. buf[9] = (byte)((patch >>> 8) & 0xFF);
  67. buf[10] = (byte)((patch >>> 16) & 0xFF);
  68. buf[11] = (byte)((patch >>> 24) & 0xFF);
  69. }
  70. }
  71. /**
  72. * Allows us to create a fragment message from any message type.
  73. */
  74. public FragmentMessage createFragmentMessage() {
  75. // check for message type validity
  76. switch (this.message_type) {
  77. case GIOPCancelRequest :
  78. case GIOPCloseConnection :
  79. case GIOPMessageError :
  80. throw new INTERNAL(MinorCodes.FRAGMENTATION_DISALLOWED,
  81. CompletionStatus.COMPLETED_MAYBE);
  82. case GIOPLocateRequest :
  83. case GIOPLocateReply :
  84. if (this.GIOP_version.equals(GIOPVersion.V1_1)) {
  85. throw new INTERNAL(MinorCodes.FRAGMENTATION_DISALLOWED,
  86. CompletionStatus.COMPLETED_MAYBE);
  87. }
  88. break;
  89. }
  90. /*
  91. // A fragmented mesg can be created only if the current mesg' fragment
  92. // bit is set. Otherwise, raise error
  93. // too stringent check
  94. if ( (this.flags & MORE_FRAGMENTS_BIT) != MORE_FRAGMENTS_BIT ) {
  95. throw new INTERNAL(MinorCodes.FRAGMENTATION_DISALLOWED,
  96. CompletionStatus.COMPLETED_MAYBE);
  97. }
  98. */
  99. if (this.GIOP_version.equals(GIOPVersion.V1_1)) {
  100. return new FragmentMessage_1_1(this);
  101. } else if (this.GIOP_version.equals(GIOPVersion.V1_2)) {
  102. return new FragmentMessage_1_2(this);
  103. }
  104. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  105. CompletionStatus.COMPLETED_MAYBE);
  106. }
  107. // IO methods
  108. // This should do nothing even if it is called. The Message Header is read
  109. // off a java.io.InputStream (not a CDRInputStream) by IIOPConnection
  110. // in order to choose the correct CDR Version , msg_type, and msg_size.
  111. // So, we would never need to read the Message Header off a CDRInputStream.
  112. public void read(org.omg.CORBA.portable.InputStream istream) {
  113. /*
  114. this.magic = istream.read_long();
  115. this.GIOP_version = (new GIOPVersion()).read(istream);
  116. this.flags = istream.read_octet();
  117. this.message_type = istream.read_octet();
  118. this.message_size = istream.read_ulong();
  119. */
  120. }
  121. public void write(org.omg.CORBA.portable.OutputStream ostream) {
  122. ostream.write_long(this.magic);
  123. nullCheck(this.GIOP_version);
  124. this.GIOP_version.write(ostream);
  125. ostream.write_octet(this.flags);
  126. ostream.write_octet(this.message_type);
  127. ostream.write_ulong(this.message_size);
  128. }
  129. } // class Message_1_1