001: /*
002: * Copyright 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package org.omg.CORBA;
027:
028: import org.omg.CORBA.portable.Streamable;
029: import org.omg.CORBA.portable.InputStream;
030: import org.omg.CORBA.portable.OutputStream;
031:
032: /**
033: * The Holder for <tt>Any</tt>. For more information on
034: * Holder files, see <a href="doc-files/generatedfiles.html#holder">
035: * "Generated Files: Holder Files"</a>.<P>
036: * A Holder class for <code>Any</code> objects
037: * that is used to store "out" and "inout" parameters in IDL methods.
038: * If an IDL method signature has an IDL <code>any</code> as an "out"
039: * or "inout" parameter, the programmer must pass an instance of
040: * <code>AnyHolder</code> as the corresponding
041: * parameter in the method invocation; for "inout" parameters, the programmer
042: * must also fill the "in" value to be sent to the server.
043: * Before the method invocation returns, the ORB will fill in the
044: * value corresponding to the "out" value returned from the server.
045: * <P>
046: * If <code>myAnyHolder</code> is an instance of <code>AnyHolder</code>,
047: * the value stored in its <code>value</code> field can be accessed with
048: * <code>myAnyHolder.value</code>.
049: *
050: * @version 1.14, 09/09/97
051: * @since JDK1.2
052: */
053: public final class AnyHolder implements Streamable {
054: /**
055: * The <code>Any</code> value held by this <code>AnyHolder</code> object.
056: */
057:
058: public Any value;
059:
060: /**
061: * Constructs a new <code>AnyHolder</code> object with its
062: * <code>value</code> field initialized to <code>null</code>.
063: */
064: public AnyHolder() {
065: }
066:
067: /**
068: * Constructs a new <code>AnyHolder</code> object for the given
069: * <code>Any</code> object.
070: * @param initial the <code>Any</code> object with which to initialize
071: * the <code>value</code> field of the new
072: * <code>AnyHolder</code> object
073: */
074: public AnyHolder(Any initial) {
075: value = initial;
076: }
077:
078: /**
079: * Reads from <code>input</code> and initalizes the value in the Holder
080: * with the unmarshalled data.
081: *
082: * @param input the InputStream containing CDR formatted data from the wire.
083: */
084: public void _read(InputStream input) {
085: value = input.read_any();
086: }
087:
088: /**
089: * Marshals to <code>output</code> the value in
090: * this <code>AnyHolder</code> object.
091: *
092: * @param output the OutputStream which will contain the CDR formatted data.
093: */
094: public void _write(OutputStream output) {
095: output.write_any(value);
096: }
097:
098: /**
099: * Returns the <code>TypeCode</code> object corresponding to the value
100: * held in this <code>AnyHolder</code> object.
101: *
102: * @return the TypeCode of the value held in
103: * this <code>AnyHolder</code> object
104: */
105: public TypeCode _type() {
106: return ORB.init().get_primitive_tc(TCKind.tk_any);
107: }
108: }
|