1 /*
   2  * Copyright (c) 1996, 2001, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package org.omg.CORBA;
  27 
  28 import org.omg.CORBA.portable.Streamable;
  29 import org.omg.CORBA.portable.InputStream;
  30 import org.omg.CORBA.portable.OutputStream;
  31 
  32 
  33 /**
  34  * The Holder for {@code Object}. For more information on
  35  * Holder files, see <a href="doc-files/generatedfiles.html#holder">
  36  * "Generated Files: Holder Files"</a>.<P>
  37  * A Holder class for a CORBA object reference (a value of type
  38  * {@code org.omg.CORBA.Object}).  It is usually
  39  * used to store "out" and "inout" parameters in IDL methods.
  40  * If an IDL method signature has a CORBA Object reference as an "out"
  41  * or "inout" parameter, the programmer must pass an instance of
  42  * {@code ObjectHolder} as the corresponding
  43  * parameter in the method invocation; for "inout" parameters, the programmer
  44  * must also fill the "in" value to be sent to the server.
  45  * Before the method invocation returns, the ORB will fill in the
  46  * value corresponding to the "out" value returned from the server.
  47  * <P>
  48  * If {@code myObjectHolder} is an instance of {@code ObjectHolder},
  49  * the value stored in its {@code value} field can be accessed with
  50  * {@code myObjectHolder.value}.
  51  *
  52  * @since       JDK1.2
  53  */
  54 public final class ObjectHolder implements Streamable {
  55     /**
  56      * The {@code Object} value held by this {@code ObjectHolder}
  57      * object.
  58      */
  59     public Object value;
  60 
  61     /**
  62      * Constructs a new {@code ObjectHolder} object with its
  63      * {@code value} field initialized to {@code null}.
  64      */
  65     public ObjectHolder() {
  66     }
  67 
  68     /**
  69      * Constructs a new {@code ObjectHolder} object with its
  70      * {@code value} field initialized to the given
  71      * {@code Object}.
  72      * @param initial the {@code Object} with which to initialize
  73      *                the {@code value} field of the newly-created
  74      *                {@code ObjectHolder} object
  75      */
  76     public ObjectHolder(Object initial) {
  77         value = initial;
  78     }
  79 
  80     /**
  81      * Reads from {@code input} and initalizes the value in
  82      * this {@code ObjectHolder} object
  83      * with the unmarshalled data.
  84      *
  85      * @param input the InputStream containing CDR formatted data from the wire.
  86      */
  87     public void _read(InputStream input) {
  88         value = input.read_Object();
  89     }
  90 
  91     /**
  92      * Marshals to {@code output} the value in
  93      * this {@code ObjectHolder} object.
  94      *
  95      * @param output the OutputStream which will contain the CDR formatted data.
  96      */
  97     public void _write(OutputStream output) {
  98         output.write_Object(value);
  99     }
 100 
 101     /**
 102      * Returns the TypeCode corresponding to the value held in
 103      * this {@code ObjectHolder} object
 104      *
 105      * @return    the TypeCode of the value held in
 106      *            this {@code ObjectHolder} object
 107      */
 108     public org.omg.CORBA.TypeCode _type() {
 109         return org.omg.CORBA.ORB.init().get_primitive_tc(TCKind.tk_objref);
 110     }
 111 }