1. /*
  2. * @(#)StringHolder.java 1.24 00/02/02
  3. *
  4. * Copyright 1995-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 <code>String</code>
  16. * that is used to store "out" and "inout" parameters in IDL operations.
  17. * If an IDL operation signature has an IDL <code>string</code> as an "out"
  18. * or "inout" parameter, the programmer must pass an instance of
  19. * <code>StringHolder</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>myStringHolder</code> is an instance of <code>StringHolder</code>,
  26. * the value stored in its <code>value</code> field can be accessed with
  27. * <code>myStringHolder.value</code>.
  28. *
  29. * @version 1.14, 09/09/97
  30. * @since JDK1.2
  31. */
  32. public final class StringHolder implements Streamable {
  33. /**
  34. * The <code>String</code> value held by this <code>StringHolder</code>
  35. * object.
  36. */
  37. public String value;
  38. /**
  39. * Constructs a new <code>StringHolder</code> object with its
  40. * <code>value</code> field initialized to <code>null</code>.
  41. */
  42. public StringHolder() {
  43. }
  44. /**
  45. * Constructs a new <code>StringHolder</code> object with its
  46. * <code>value</code> field initialized to the given
  47. * <code>String</code>.
  48. * @param initial the <code>String</code> with which to initialize
  49. * the <code>value</code> field of the newly-created
  50. * <code>StringHolder</code> object
  51. */
  52. public StringHolder(String initial) {
  53. value = initial;
  54. }
  55. /**
  56. * Reads the unmarshalled data from <code>input</code> and assigns it to
  57. * the <code>value</code> field of this <code>StringHolder</code> object.
  58. *
  59. * @param input the InputStream containing CDR formatted data from the wire.
  60. */
  61. public void _read(InputStream input) {
  62. value = input.read_string();
  63. }
  64. /**
  65. * Marshals the value held by this <code>StringHolder</code> object
  66. * to the output stream <code>output</code>.
  67. *
  68. * @param output the OutputStream which will contain the CDR formatted data.
  69. */
  70. public void _write(OutputStream output) {
  71. output.write_string(value);
  72. }
  73. /**
  74. * Retreives the <code>TypeCode</code> object that corresponds to
  75. * the value held in this <code>StringHolder</code> object.
  76. *
  77. * @return the type code of the value held in this <code>StringHolder</code>
  78. * object
  79. */
  80. public org.omg.CORBA.TypeCode _type() {
  81. return ORB.init().get_primitive_tc(TCKind.tk_string);
  82. }
  83. }