1. /*
  2. * @(#)Message_1_1.java 1.12 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 java.nio.ByteBuffer;
  9. import org.omg.CORBA.INTERNAL;
  10. import org.omg.CORBA.CompletionStatus;
  11. import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
  12. import com.sun.corba.se.spi.logging.CORBALogDomains ;
  13. import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
  14. /*
  15. * This implements the GIOP 1.1 & 1.2 Message header.
  16. *
  17. * @author Ram Jeyaraman 05/14/2000
  18. * @version 1.0
  19. */
  20. public class Message_1_1
  21. extends com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase {
  22. // Constants
  23. final static int UPPER_THREE_BYTES_OF_INT_MASK = 0xFF;
  24. private static ORBUtilSystemException wrapper =
  25. ORBUtilSystemException.get( CORBALogDomains.RPC_PROTOCOL ) ;
  26. // Instance variables
  27. int magic = (int) 0;
  28. GIOPVersion GIOP_version = null;
  29. byte flags = (byte) 0;
  30. byte message_type = (byte) 0;
  31. int message_size = (int) 0;
  32. // Constructor
  33. Message_1_1() {
  34. }
  35. Message_1_1(int _magic, GIOPVersion _GIOP_version, byte _flags,
  36. byte _message_type, int _message_size) {
  37. magic = _magic;
  38. GIOP_version = _GIOP_version;
  39. flags = _flags;
  40. message_type = _message_type;
  41. message_size = _message_size;
  42. }
  43. // Accessor methods
  44. public GIOPVersion getGIOPVersion() {
  45. return this.GIOP_version;
  46. }
  47. public int getType() {
  48. return this.message_type;
  49. }
  50. public int getSize() {
  51. return this.message_size;
  52. }
  53. public boolean isLittleEndian() {
  54. return ((this.flags & LITTLE_ENDIAN_BIT) == LITTLE_ENDIAN_BIT);
  55. }
  56. public boolean moreFragmentsToFollow() {
  57. return ( (this.flags & MORE_FRAGMENTS_BIT) == MORE_FRAGMENTS_BIT );
  58. }
  59. // Mutator methods
  60. // NOTE: This is a SUN PROPRIETARY EXTENSION
  61. // Add the poolToUse to the upper 6 bits of byte 6 of the GIOP header.
  62. // this.flags represents byte 6 here.
  63. public void setThreadPoolToUse(int poolToUse) {
  64. // IMPORTANT: Bitwise operations will promote
  65. // byte types to int before performing
  66. // bitwise operations. And, Java
  67. // types are signed.
  68. int tmpFlags = poolToUse << 2;
  69. tmpFlags &= UPPER_THREE_BYTES_OF_INT_MASK;
  70. tmpFlags |= flags;
  71. flags = (byte)tmpFlags;
  72. }
  73. public void setSize(ByteBuffer byteBuffer, int size) {
  74. this.message_size = size;
  75. //
  76. // Patch the size field in the header.
  77. //
  78. int patch = size - GIOPMessageHeaderLength;
  79. if (!isLittleEndian()) {
  80. byteBuffer.put(8, (byte)((patch >>> 24) & 0xFF));
  81. byteBuffer.put(9, (byte)((patch >>> 16) & 0xFF));
  82. byteBuffer.put(10, (byte)((patch >>> 8) & 0xFF));
  83. byteBuffer.put(11, (byte)((patch >>> 0) & 0xFF));
  84. } else {
  85. byteBuffer.put(8, (byte)((patch >>> 0) & 0xFF));
  86. byteBuffer.put(9, (byte)((patch >>> 8) & 0xFF));
  87. byteBuffer.put(10, (byte)((patch >>> 16) & 0xFF));
  88. byteBuffer.put(11, (byte)((patch >>> 24) & 0xFF));
  89. }
  90. }
  91. /**
  92. * Allows us to create a fragment message from any message type.
  93. */
  94. public FragmentMessage createFragmentMessage() {
  95. // check for message type validity
  96. switch (this.message_type) {
  97. case GIOPCancelRequest :
  98. case GIOPCloseConnection :
  99. case GIOPMessageError :
  100. throw wrapper.fragmentationDisallowed(
  101. CompletionStatus.COMPLETED_MAYBE);
  102. case GIOPLocateRequest :
  103. case GIOPLocateReply :
  104. if (this.GIOP_version.equals(GIOPVersion.V1_1)) {
  105. throw wrapper.fragmentationDisallowed(
  106. CompletionStatus.COMPLETED_MAYBE);
  107. }
  108. break;
  109. }
  110. /*
  111. // A fragmented mesg can be created only if the current mesg' fragment
  112. // bit is set. Otherwise, raise error
  113. // too stringent check
  114. if ( (this.flags & MORE_FRAGMENTS_BIT) != MORE_FRAGMENTS_BIT ) {
  115. throw wrapper.fragmentationDisallowed( CompletionStatus.COMPLETED_MAYBE);
  116. }
  117. */
  118. if (this.GIOP_version.equals(GIOPVersion.V1_1)) {
  119. return new FragmentMessage_1_1(this);
  120. } else if (this.GIOP_version.equals(GIOPVersion.V1_2)) {
  121. return new FragmentMessage_1_2(this);
  122. }
  123. throw wrapper.giopVersionError( CompletionStatus.COMPLETED_MAYBE);
  124. }
  125. // IO methods
  126. // This should do nothing even if it is called. The Message Header is read
  127. // off a java.io.InputStream (not a CDRInputStream) by IIOPConnection
  128. // in order to choose the correct CDR Version , msg_type, and msg_size.
  129. // So, we would never need to read the Message Header off a CDRInputStream.
  130. public void read(org.omg.CORBA.portable.InputStream istream) {
  131. /*
  132. this.magic = istream.read_long();
  133. this.GIOP_version = (new GIOPVersion()).read(istream);
  134. this.flags = istream.read_octet();
  135. this.message_type = istream.read_octet();
  136. this.message_size = istream.read_ulong();
  137. */
  138. }
  139. public void write(org.omg.CORBA.portable.OutputStream ostream) {
  140. ostream.write_long(this.magic);
  141. nullCheck(this.GIOP_version);
  142. this.GIOP_version.write(ostream);
  143. ostream.write_octet(this.flags);
  144. ostream.write_octet(this.message_type);
  145. ostream.write_ulong(this.message_size);
  146. }
  147. } // class Message_1_1