AnyHolder.java revision 608:7e06bf1dcb09
1189251Ssam/*
2189251Ssam * Copyright (c) 1996, 2001, Oracle and/or its affiliates. All rights reserved.
3346981Scy * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4189251Ssam *
5252726Srpaulo * This code is free software; you can redistribute it and/or modify it
6252726Srpaulo * under the terms of the GNU General Public License version 2 only, as
7189251Ssam * published by the Free Software Foundation.  Oracle designates this
8189251Ssam * particular file as subject to the "Classpath" exception as provided
9189251Ssam * by Oracle in the LICENSE file that accompanied this code.
10189251Ssam *
11189251Ssam * This code is distributed in the hope that it will be useful, but WITHOUT
12337817Scy * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13346981Scy * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14337817Scy * version 2 for more details (a copy is included in the LICENSE file that
15346981Scy * accompanied this code).
16346981Scy *
17346981Scy * You should have received a copy of the GNU General Public License version
18346981Scy * 2 along with this work; if not, write to the Free Software Foundation,
19346981Scy * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20346981Scy *
21346981Scy * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22346981Scy * or visit www.oracle.com if you need additional information or have any
23289549Srpaulo * questions.
24289549Srpaulo */
25289549Srpaulo
26289549Srpaulopackage org.omg.CORBA;
27289549Srpaulo
28289549Srpauloimport org.omg.CORBA.portable.Streamable;
29289549Srpauloimport org.omg.CORBA.portable.InputStream;
30289549Srpauloimport org.omg.CORBA.portable.OutputStream;
31289549Srpaulo
32289549Srpaulo/**
33189251Ssam * The Holder for <tt>Any</tt>.  For more information on
34189251Ssam * Holder files, see <a href="doc-files/generatedfiles.html#holder">
35214734Srpaulo * "Generated Files: Holder Files"</a>.<P>
36214734Srpaulo * A Holder class for <code>Any</code> objects
37214734Srpaulo * that is used to store "out" and "inout" parameters in IDL methods.
38214734Srpaulo * If an IDL method signature has an IDL <code>any</code> as an "out"
39214734Srpaulo * or "inout" parameter, the programmer must pass an instance of
40214734Srpaulo * <code>AnyHolder</code> as the corresponding
41214734Srpaulo * parameter in the method invocation; for "inout" parameters, the programmer
42214734Srpaulo * must also fill the "in" value to be sent to the server.
43214734Srpaulo * Before the method invocation returns, the ORB will fill in the
44214734Srpaulo * value corresponding to the "out" value returned from the server.
45214734Srpaulo * <P>
46214734Srpaulo * If <code>myAnyHolder</code> is an instance of <code>AnyHolder</code>,
47214734Srpaulo * the value stored in its <code>value</code> field can be accessed with
48214734Srpaulo * <code>myAnyHolder.value</code>.
49214734Srpaulo *
50214734Srpaulo * @since       JDK1.2
51214734Srpaulo */
52281806Srpaulopublic final class AnyHolder implements  Streamable {
53281806Srpaulo    /**
54281806Srpaulo     * The <code>Any</code> value held by this <code>AnyHolder</code> object.
55252726Srpaulo     */
56252726Srpaulo
57281806Srpaulo    public Any value;
58214734Srpaulo
59281806Srpaulo    /**
60252726Srpaulo     * Constructs a new <code>AnyHolder</code> object with its
61252726Srpaulo     * <code>value</code> field initialized to <code>null</code>.
62252726Srpaulo     */
63252726Srpaulo    public AnyHolder() {
64281806Srpaulo    }
65252726Srpaulo
66252726Srpaulo    /**
67252726Srpaulo     * Constructs a new <code>AnyHolder</code> object for the given
68252726Srpaulo     * <code>Any</code> object.
69281806Srpaulo     * @param initial the <code>Any</code> object with which to initialize
70337817Scy     *                the <code>value</code> field of the new
71281806Srpaulo     *                <code>AnyHolder</code> object
72281806Srpaulo     */
73289549Srpaulo    public AnyHolder(Any initial) {
74337817Scy        value = initial;
75337817Scy    }
76346981Scy
77346981Scy    /**
78346981Scy     * Reads from <code>input</code> and initalizes the value in the Holder
79346981Scy     * with the unmarshalled data.
80346981Scy     *
81346981Scy     * @param input the InputStream containing CDR formatted data from the wire.
82346981Scy     */
83346981Scy    public void _read(InputStream input) {
84346981Scy        value = input.read_any();
85346981Scy    }
86346981Scy
87346981Scy    /**
88346981Scy     * Marshals to <code>output</code> the value in
89346981Scy     * this <code>AnyHolder</code> object.
90346981Scy     *
91346981Scy     * @param output the OutputStream which will contain the CDR formatted data.
92346981Scy     */
93346981Scy    public void _write(OutputStream output) {
94346981Scy        output.write_any(value);
95346981Scy    }
96346981Scy
97351611Scy    /**
98214734Srpaulo     * Returns the <code>TypeCode</code> object corresponding to the value
99189251Ssam     * held in this <code>AnyHolder</code> object.
100189251Ssam     *
101189251Ssam     * @return    the TypeCode of the value held in
102189251Ssam     *              this <code>AnyHolder</code> object
103189251Ssam     */
104189251Ssam    public TypeCode _type() {
105209158Srpaulo        return ORB.init().get_primitive_tc(TCKind.tk_any);
106209158Srpaulo    }
107189251Ssam}
108189251Ssam