1. /*
  2. * @(#)IntHolder.java 1.16 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package org.omg.CORBA;
  8. import org.omg.CORBA.portable.Streamable;
  9. import org.omg.CORBA.portable.InputStream;
  10. import org.omg.CORBA.portable.OutputStream;
  11. /**
  12. * A Holder class for an <code>int</code>
  13. * that is used to store "out" and "inout" parameters in IDL methods.
  14. * If an IDL method signature has an IDL <code>long</code> as an "out"
  15. * or "inout" parameter, the programmer must pass an instance of
  16. * <code>IntHolder</code> as the corresponding
  17. * parameter in the method invocation; for "inout" parameters, the programmer
  18. * must also fill the "in" value to be sent to the server.
  19. * Before the method invocation returns, the ORB will fill in the
  20. * value corresponding to the "out" value returned from the server.
  21. * <P>
  22. * If <code>myIntHolder</code> is an instance of <code>IntHolder</code>,
  23. * the value stored in its <code>value</code> field can be accessed with
  24. * <code>myIntHolder.value</code>.
  25. *
  26. * @version 1.14, 09/09/97
  27. * @since JDK1.2
  28. */
  29. public final class IntHolder implements Streamable {
  30. /**
  31. * The <code>int</code> value held by this <code>IntHolder</code>
  32. * object in its <code>value</code> field.
  33. */
  34. public int value;
  35. /**
  36. * Constructs a new <code>IntHolder</code> object with its
  37. * <code>value</code> field initialized to <code>0</code>.
  38. */
  39. public IntHolder() {
  40. }
  41. /**
  42. * Constructs a new <code>IntHolder</code> object with its
  43. * <code>value</code> field initialized to the given
  44. * <code>int</code>.
  45. * @param initial the <code>int</code> with which to initialize
  46. * the <code>value</code> field of the newly-created
  47. * <code>IntHolder</code> object
  48. */
  49. public IntHolder(int initial) {
  50. value = initial;
  51. }
  52. /**
  53. * Reads unmarshalled data from <code>input</code> and assigns it to
  54. * the <code>value</code> field in this <code>IntHolder</code> object.
  55. *
  56. * @param input the <code>InputStream</code> object containing CDR
  57. * formatted data from the wire
  58. */
  59. public void _read(InputStream input) {
  60. value = input.read_long();
  61. }
  62. /**
  63. * Marshals the value in this <code>IntHolder</code> object's
  64. * <code>value</code> field to the output stream <code>output</code>.
  65. *
  66. * @param output the <code>OutputStream</code> object that will contain
  67. * the CDR formatted data
  68. */
  69. public void _write(OutputStream output) {
  70. output.write_long(value);
  71. }
  72. /**
  73. * Retrieves the <code>TypeCode</code> object that corresponds
  74. * to the value held in this <code>IntHolder</code> object's
  75. * <code>value</code> field.
  76. *
  77. * @return the type code for the value held in this <code>IntHolder</code>
  78. * object
  79. */
  80. public org.omg.CORBA.TypeCode _type() {
  81. return ORB.init().get_primitive_tc(TCKind.tk_long);
  82. }
  83. }