RequestHeader.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* RequestHeader.java -- The GIOP 1.0 request message.
  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;
  32. import gnu.CORBA.CDR.AbstractCdrInput;
  33. import gnu.CORBA.CDR.AbstractCdrOutput;
  34. import gnu.java.lang.CPStringBuilder;
  35. import org.omg.CORBA.portable.IDLEntity;
  36. /**
  37. * The GIOP request message.
  38. *
  39. * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
  40. */
  41. public abstract class RequestHeader
  42. extends ContextHandler
  43. implements IDLEntity
  44. {
  45. /**
  46. * The currently free request id. This field is incremented each time the new
  47. * request header is constructed. To facilitate error detection, the first
  48. * free id is equal to 0x01234567 (19088743).
  49. */
  50. private static int freeId = 0x01234567;
  51. /**
  52. * The operation being invoked (IDL scope name).
  53. */
  54. public String operation;
  55. /**
  56. * Identifies the object that is the target of the invocation.
  57. */
  58. public byte[] object_key;
  59. /**
  60. * A value identifying the requesting principal. Initialised into a single
  61. * zero byte.
  62. *
  63. * @deprecated by CORBA 2.2.
  64. */
  65. public byte[] requesting_principal;
  66. /**
  67. * This is used to associate the reply message with the previous request
  68. * message. Initialised each time by the different value, increasing form 1 to
  69. * Integer.MAX_VALUE.
  70. */
  71. public int request_id = getNextId();
  72. /**
  73. * If true, the response from the server is expected.
  74. */
  75. protected boolean response_expected = true;
  76. /**
  77. * Get next free request id. The value of the free request id starts from
  78. * 0x02345678, it is incremented each time this function is called and is
  79. * reset to 1 after reaching Integer.MAX_VALUE.
  80. *
  81. * @return the next free request id.
  82. */
  83. public static synchronized int getNextId()
  84. {
  85. int f = freeId;
  86. if (freeId == Integer.MAX_VALUE)
  87. freeId = 1;
  88. else
  89. freeId++;
  90. return f;
  91. }
  92. /**
  93. * Set if the sender expects any response to this message.
  94. */
  95. public abstract void setResponseExpected(boolean expected);
  96. /**
  97. * Return true if response is expected.
  98. */
  99. public abstract boolean isResponseExpected();
  100. /**
  101. * Converts an byte array into hexadecimal string values. Used in various
  102. * toString() methods.
  103. */
  104. public String bytes(byte[] array)
  105. {
  106. CPStringBuilder b = new CPStringBuilder();
  107. for (int i = 0; i < array.length; i++)
  108. {
  109. b.append(Integer.toHexString(array[i] & 0xFF));
  110. b.append(" ");
  111. }
  112. return b.toString();
  113. }
  114. /**
  115. * Reads the header from the stream.
  116. *
  117. * @param in a stream to read from.
  118. */
  119. public abstract void read(AbstractCdrInput in);
  120. /**
  121. * Return a string representation.
  122. */
  123. public abstract String toString();
  124. /**
  125. * Writes the header to the stream.
  126. *
  127. * @param out a stream to write into.
  128. */
  129. public abstract void write(AbstractCdrOutput out);
  130. }