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