RequestHeader.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* RequestHeader.java --
  2. Copyright (C) 2005 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package gnu.CORBA.GIOP.v1_2;
  32. import gnu.CORBA.Minor;
  33. import gnu.CORBA.CDR.AbstractCdrInput;
  34. import gnu.CORBA.CDR.AbstractCdrOutput;
  35. import gnu.CORBA.GIOP.ServiceContext;
  36. import gnu.CORBA.GIOP.CodeSetServiceContext;
  37. import java.io.IOException;
  38. import org.omg.CORBA.MARSHAL;
  39. import org.omg.CORBA.NO_IMPLEMENT;
  40. /**
  41. * The GIOP 1.2 request header. The GIOP 1.1 request header
  42. * is the same as GIOP 1.0 request header, if taking the
  43. * alignment into consideration.
  44. *
  45. * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
  46. */
  47. public class RequestHeader
  48. extends gnu.CORBA.GIOP.v1_0.RequestHeader
  49. {
  50. /**
  51. * Use serialVersionUID for interoperability.
  52. */
  53. private static final long serialVersionUID = 1;
  54. /**
  55. * Indicates that the object is addressed by the object key.
  56. */
  57. public static final short KeyAddr = 0;
  58. /**
  59. * Indicates that the object is addressed by the IOP tagged profile.
  60. */
  61. public static final short ProfileAddr = 1;
  62. /**
  63. * Indicates that the objec is addressed by IOR addressing info.
  64. */
  65. public static final short ReferenceAddr = 2;
  66. /**
  67. * The response flags of the header. By default, the flags are initialised
  68. * by value 0x3 (response expected).
  69. */
  70. public byte response_flags = 3;
  71. /**
  72. * The used addressing method.
  73. */
  74. public short AddressingDisposition;
  75. /**
  76. * Adds the standard encoding context.
  77. */
  78. public RequestHeader()
  79. {
  80. service_context = new ServiceContext[] { CodeSetServiceContext.STANDARD };
  81. }
  82. /**
  83. * Set if the sender expects any response to this message.
  84. * Clears or sets the 2 lower bits of flags
  85. * (0 - not expected, 0x3 - expected).
  86. */
  87. public void setResponseExpected(boolean expected)
  88. {
  89. response_expected = expected;
  90. if (expected)
  91. response_flags = (byte) (response_flags | 0x3);
  92. else
  93. response_flags = (byte) (response_flags & (~0x3));
  94. }
  95. /**
  96. * Return true if response is expected.
  97. *
  98. * @return true if the two lowest bits of the flags are set or
  99. * the response expected is explicitly set to true.
  100. */
  101. public boolean isResponseExpected()
  102. {
  103. return response_expected || ((response_flags & 0x3) == 0x3);
  104. }
  105. /**
  106. * Read the header from the given stream.
  107. *
  108. * @param in a stream to read from.
  109. */
  110. public void read(AbstractCdrInput in)
  111. {
  112. try
  113. {
  114. request_id = in.read_ulong();
  115. response_flags = (byte) in.read();
  116. // Skip 3 reserved octets:
  117. in.skip(3);
  118. // Read target address.
  119. AddressingDisposition = in.read_ushort();
  120. switch (AddressingDisposition)
  121. {
  122. case KeyAddr :
  123. object_key = in.read_sequence();
  124. break;
  125. // TODO FIXME add other addressing methods.
  126. case ProfileAddr :
  127. throw new NO_IMPLEMENT("Object addressing by IOP tagged profile");
  128. case ReferenceAddr :
  129. throw new NO_IMPLEMENT("Object addressing by IOR addressing info");
  130. default :
  131. MARSHAL m = new MARSHAL("Unknow addressing method in request, " +
  132. AddressingDisposition
  133. );
  134. m.minor = Minor.UnsupportedAddressing;
  135. throw m;
  136. }
  137. operation = in.read_string();
  138. service_context = gnu.CORBA.GIOP.ServiceContext.readSequence(in);
  139. // No requesting principal in this new format.
  140. in.setCodeSet(CodeSetServiceContext.find(service_context));
  141. }
  142. catch (IOException ex)
  143. {
  144. MARSHAL t = new MARSHAL();
  145. t.minor = Minor.Header;
  146. t.initCause(ex);
  147. throw t;
  148. }
  149. }
  150. /**
  151. * Return a string representation.
  152. */
  153. public String toString()
  154. {
  155. return "Request " + request_id + ", call '" + operation + "' on " +
  156. bytes(object_key) + ", " +
  157. (response_expected ? "wait response" : "one way") +
  158. " addressed by " + " method " + AddressingDisposition + "." +
  159. contexts();
  160. }
  161. /**
  162. * Write the header to the given stream.
  163. *
  164. * @param out a stream to write into.
  165. */
  166. public void write(AbstractCdrOutput out)
  167. {
  168. out.write_ulong(request_id);
  169. out.write(response_flags);
  170. // Skip 3 reserved octets:
  171. out.write(0);
  172. out.write(0);
  173. out.write(0);
  174. // Write addressing disposition from IOR.
  175. // TODO FIXME add other addressing methods.
  176. out.write_ushort(KeyAddr);
  177. out.write_sequence(object_key);
  178. out.write_string(operation);
  179. ServiceContext.writeSequence(out, service_context);
  180. // No requesting principal in this new format.
  181. out.setCodeSet(CodeSetServiceContext.find(service_context));
  182. }
  183. }