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