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