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