1 |
775 |
jeremybenn |
/* InputStream.java --
|
2 |
|
|
Copyright (C) 2005, 2006 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is part of GNU Classpath.
|
5 |
|
|
|
6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
7 |
|
|
it under the terms of the GNU General Public License as published by
|
8 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
9 |
|
|
any later version.
|
10 |
|
|
|
11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
18 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
|
|
02110-1301 USA.
|
20 |
|
|
|
21 |
|
|
Linking this library statically or dynamically with other modules is
|
22 |
|
|
making a combined work based on this library. Thus, the terms and
|
23 |
|
|
conditions of the GNU General Public License cover the whole
|
24 |
|
|
combination.
|
25 |
|
|
|
26 |
|
|
As a special exception, the copyright holders of this library give you
|
27 |
|
|
permission to link this library with independent modules to produce an
|
28 |
|
|
executable, regardless of the license terms of these independent
|
29 |
|
|
modules, and to copy and distribute the resulting executable under
|
30 |
|
|
terms of your choice, provided that you also meet, for each linked
|
31 |
|
|
independent module, the terms and conditions of the license of that
|
32 |
|
|
module. An independent module is a module which is not derived from
|
33 |
|
|
or based on this library. If you modify this library, you may extend
|
34 |
|
|
this exception to your version of the library, but you are not
|
35 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
36 |
|
|
exception statement from your version. */
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
package org.omg.CORBA_2_3.portable;
|
40 |
|
|
|
41 |
|
|
import gnu.CORBA.CDR.Vio;
|
42 |
|
|
|
43 |
|
|
import org.omg.CORBA.CustomMarshal;
|
44 |
|
|
import org.omg.CORBA.portable.BoxedValueHelper;
|
45 |
|
|
import org.omg.CORBA.portable.StreamableValue;
|
46 |
|
|
|
47 |
|
|
import java.io.Serializable;
|
48 |
|
|
|
49 |
|
|
/**
|
50 |
|
|
* This class defines a new CDR input stream methods, added since
|
51 |
|
|
* CORBA 2.3.
|
52 |
|
|
*
|
53 |
|
|
* This class is abstract; no direct instances can be instantiated.
|
54 |
|
|
* Also, up till v 1.4 inclusive there are no methods that would
|
55 |
|
|
* return it, and only one unimplemented interface,
|
56 |
|
|
* {@link org.omg.CORBA.portable.ValueFactory }, needs it as a parameter.
|
57 |
|
|
*
|
58 |
|
|
* However since 1.3 all methods, declared as returning an
|
59 |
|
|
* org.omg.CORBA.portable.InputStream actually return the instance of this
|
60 |
|
|
* derived class and the new methods are accessible after the casting
|
61 |
|
|
* operation.
|
62 |
|
|
*
|
63 |
|
|
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
64 |
|
|
*/
|
65 |
|
|
public abstract class InputStream
|
66 |
|
|
extends org.omg.CORBA.portable.InputStream
|
67 |
|
|
{
|
68 |
|
|
/**
|
69 |
|
|
* Read the abstract interface. An abstract interface can be either
|
70 |
|
|
* CORBA value type or CORBA object and is returned as an abstract
|
71 |
|
|
* java.lang.Object.
|
72 |
|
|
*
|
73 |
|
|
* As specified in OMG specification, this reads a single
|
74 |
|
|
* boolean and then delegates either to {@link #read_Object()} (for false)
|
75 |
|
|
* or to {@link #read_value()} (for true).
|
76 |
|
|
*
|
77 |
|
|
* @return an abstract interface, unmarshaled from the stream.
|
78 |
|
|
*/
|
79 |
|
|
public Object read_abstract_interface()
|
80 |
|
|
{
|
81 |
|
|
boolean isObject = read_boolean();
|
82 |
|
|
|
83 |
|
|
if (isObject)
|
84 |
|
|
return read_Object();
|
85 |
|
|
else
|
86 |
|
|
return read_value();
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
/**
|
90 |
|
|
* Read the abstract interface, corresponding to the passed type.
|
91 |
|
|
* An abstract interface can be either CORBA value type or CORBA
|
92 |
|
|
* object and is returned as an abstract java.lang.Object.
|
93 |
|
|
*
|
94 |
|
|
* As specified in OMG specification, this reads a single
|
95 |
|
|
* boolean and then delegates either to {@link #read_Object(Class)} (for false)
|
96 |
|
|
* or to {@link #read_value(Class)} (for true).
|
97 |
|
|
*
|
98 |
|
|
* @param clz a base class for the abstract interface.
|
99 |
|
|
*
|
100 |
|
|
* @return an abstract interface, unmarshaled from the stream
|
101 |
|
|
*/
|
102 |
|
|
@SuppressWarnings("unchecked") // Needed for API compatibility
|
103 |
|
|
public Object read_abstract_interface(Class clz)
|
104 |
|
|
{
|
105 |
|
|
boolean isValue = read_boolean();
|
106 |
|
|
|
107 |
|
|
if (isValue)
|
108 |
|
|
return read_value(clz);
|
109 |
|
|
else
|
110 |
|
|
return read_Object(clz);
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
/**
|
114 |
|
|
* Read a value type structure, extracting the repository id
|
115 |
|
|
* from the input stream itself. The repository id is optional
|
116 |
|
|
* in the value type record, but it must be present for this
|
117 |
|
|
* method to succeed. The {@link OutputStream} of this
|
118 |
|
|
* implementation always stores the repository id.
|
119 |
|
|
*
|
120 |
|
|
* The casts the streams ORB into a CORBA 2.3 ORB and then
|
121 |
|
|
* searched for a suitable value factory, where it delegates
|
122 |
|
|
* the functionality.
|
123 |
|
|
*
|
124 |
|
|
* If you know the exact class or can create an unitialised instance
|
125 |
|
|
* of the value type, it is recommended (faster) to use
|
126 |
|
|
* {@link #read_value(Class)} or {@link #read_value(Serializable)}
|
127 |
|
|
* instead.
|
128 |
|
|
*
|
129 |
|
|
* @return an value type structure, unmarshaled from the stream
|
130 |
|
|
*/
|
131 |
|
|
public Serializable read_value()
|
132 |
|
|
{
|
133 |
|
|
return Vio.read(this);
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
/**
|
137 |
|
|
* Read a value type structure, corresponing to the passed type.
|
138 |
|
|
* As the type is known, the repository Id in the input stream is
|
139 |
|
|
* optional an not required. The codebase, if present, is also ignored.
|
140 |
|
|
*
|
141 |
|
|
* The passed class must implement either {@link CustomMarshal}
|
142 |
|
|
* for the user-defined reading operations or {@link StreamableValue}
|
143 |
|
|
* for the standard (generated by IDL compiler) reading operations.
|
144 |
|
|
* Also, it must have the parameterless constructor to create a new
|
145 |
|
|
* instance.
|
146 |
|
|
*
|
147 |
|
|
* @param clz a base class for a value type.
|
148 |
|
|
*
|
149 |
|
|
* @return an value type structure, unmarshaled from the stream
|
150 |
|
|
*/
|
151 |
|
|
@SuppressWarnings("unchecked") // Needed for API compatibility
|
152 |
|
|
public Serializable read_value(Class clz)
|
153 |
|
|
{
|
154 |
|
|
return Vio.read(this, clz);
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
/**
|
158 |
|
|
* Read a value type structure content, when the unitialised
|
159 |
|
|
* instance is passed as a parameter. It is a fastest method to read
|
160 |
|
|
* a value type.
|
161 |
|
|
*
|
162 |
|
|
* As the type is known, the repository Id in the input stream is
|
163 |
|
|
* optional an not required. The codebase, if present, is also ignored.
|
164 |
|
|
*
|
165 |
|
|
* The passed instance must implement either {@link CustomMarshal}
|
166 |
|
|
* for the user-defined reading operations or {@link StreamableValue}
|
167 |
|
|
* for the standard (generated by IDL compiler) reading operations.
|
168 |
|
|
*
|
169 |
|
|
* @param unitialised_value the unitialised value.
|
170 |
|
|
*
|
171 |
|
|
* @return same value, filled in by the stream content.
|
172 |
|
|
*/
|
173 |
|
|
public Serializable read_value(Serializable unitialised_value)
|
174 |
|
|
{
|
175 |
|
|
return (Serializable) Vio.read(this, unitialised_value, null);
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
/**
|
179 |
|
|
* Read a value type structure, having the given repository id.
|
180 |
|
|
* The casts the streams ORB into a CORBA 2.3 ORB and then
|
181 |
|
|
* searched for a suitable value factory, where it delegates
|
182 |
|
|
* the functionality.
|
183 |
|
|
*
|
184 |
|
|
* If you know the exact class or can create an unitialised instance
|
185 |
|
|
* of the value type, it is recommended (faster) to use
|
186 |
|
|
* {@link #read_value(Class)} or {@link #read_value(Serializable)}
|
187 |
|
|
* instead.
|
188 |
|
|
*
|
189 |
|
|
* @param repository_id a repository id of the value type.
|
190 |
|
|
*
|
191 |
|
|
* @return an value type structure, unmarshaled from the stream
|
192 |
|
|
*/
|
193 |
|
|
public Serializable read_value(String repository_id)
|
194 |
|
|
{
|
195 |
|
|
return Vio.read(this, repository_id);
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
/**
|
199 |
|
|
* Use the provided boxed value helper to read the value.
|
200 |
|
|
*
|
201 |
|
|
* @param helper a helper for reading the value from the stream.
|
202 |
|
|
*
|
203 |
|
|
* @return an value type structure, unmarshaled from the stream.
|
204 |
|
|
*/
|
205 |
|
|
public Serializable read_value(BoxedValueHelper helper)
|
206 |
|
|
{
|
207 |
|
|
return Vio.read(this, helper);
|
208 |
|
|
}
|
209 |
|
|
}
|