38 |
|
|
39 |
package org.omg.CORBA_2_3.portable; |
package org.omg.CORBA_2_3.portable; |
40 |
|
|
41 |
import org.omg.CORBA.MARSHAL; |
import gnu.CORBA.CDR.Vio; |
42 |
import org.omg.CORBA.ValueBaseHelper; |
|
43 |
import org.omg.CORBA.portable.BoxedValueHelper; |
import org.omg.CORBA.portable.BoxedValueHelper; |
44 |
|
|
45 |
import java.io.Serializable; |
import java.io.Serializable; |
58 |
* derived class and the new methods are accessible after the casting |
* derived class and the new methods are accessible after the casting |
59 |
* operation. |
* operation. |
60 |
* |
* |
61 |
* OMG specification states the writing format of the value types |
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) |
|
* is outside the scope of GIOP definition. This implementation uses |
|
|
* java serialization mechanism, calling {@link ObjectInputStream#readObject}. |
|
|
* |
|
|
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
|
62 |
*/ |
*/ |
63 |
public abstract class InputStream |
public abstract class InputStream |
64 |
extends org.omg.CORBA.portable.InputStream |
extends org.omg.CORBA.portable.InputStream |
72 |
* boolean and then delegates either to {@link #read_Object()} (for false) |
* boolean and then delegates either to {@link #read_Object()} (for false) |
73 |
* or to {@link #read_Value()} (for true). |
* or to {@link #read_Value()} (for true). |
74 |
* |
* |
75 |
* @return an abstract interface, unmarshaled from the stream |
* @return an abstract interface, unmarshaled from the stream. |
76 |
*/ |
*/ |
77 |
public Object read_abstract_interface() |
public Object read_abstract_interface() |
78 |
{ |
{ |
108 |
} |
} |
109 |
|
|
110 |
/** |
/** |
111 |
* Read a value type structure from the stream. |
* Read a value type structure, extracting the repository id |
112 |
|
* from the input stream itself. The repository id is optional |
113 |
|
* in the value type record, but it must be present for this |
114 |
|
* method to succeed. The {@link OutputStream} of this |
115 |
|
* implementation always stores the repository id. |
116 |
|
* |
117 |
|
* The casts the streams ORB into a CORBA 2.3 ORB and then |
118 |
|
* searched for a suitable value factory, where it delegates |
119 |
|
* the functionality. |
120 |
|
* |
121 |
|
* If you know the exact class or can create an unitialised instance |
122 |
|
* of the value type, it is recommended (faster) to use |
123 |
|
* {@link #read_value(Class)} or {@link #read_value(Serializable)} |
124 |
|
* instead. |
125 |
* |
* |
126 |
* OMG specification states the writing format is outside the scope |
* @param repository_id a repository id of the value type. |
|
* of GIOP definition. This implementation uses java serialization |
|
|
* mechanism, calling {@link ObjectInputStream#readObject} |
|
127 |
* |
* |
128 |
* @return an value type structure, unmarshaled from the stream |
* @return an value type structure, unmarshaled from the stream |
129 |
*/ |
*/ |
130 |
public Serializable read_value() |
public Serializable read_value() |
131 |
{ |
{ |
132 |
return read_value((Class) null); |
return Vio.read(this); |
133 |
} |
} |
134 |
|
|
135 |
/** |
/** |
136 |
* Read a value type structure, corresponing to the passed type. |
* Read a value type structure, corresponing to the passed type. |
137 |
|
* As the type is known, the repository Id in the input stream is |
138 |
|
* optional an not required. The codebase, if present, is also ignored. |
139 |
* |
* |
140 |
* OMG specification states the writing format is outside the scope |
* The passed class must implement either {@link CustomMarshal} |
141 |
* of GIOP definition. This implementation uses java serialization |
* for the user-defined reading operations or {@link StreamableValue} |
142 |
* mechanism, calling {@link ObjectInputStream#readObject} |
* for the standard (generated by IDL compiler) reading operations. |
143 |
|
* Also, it must have the parameterless constructor to create a new |
144 |
|
* instance. |
145 |
* |
* |
146 |
* @param clz a base class for a value type. The class information |
* @param clz a base class for a value type. |
|
* is currently used for security check only. |
|
147 |
* |
* |
148 |
* @return an value type structure, unmarshaled from the stream |
* @return an value type structure, unmarshaled from the stream |
149 |
*/ |
*/ |
150 |
public Serializable read_value(Class clz) |
public Serializable read_value(Class clz) |
151 |
{ |
{ |
152 |
Serializable rt = (Serializable) ValueBaseHelper.read(this); |
return Vio.read(this, clz); |
|
|
|
|
if (rt != null && clz != null) |
|
|
{ |
|
|
if (!(clz.isAssignableFrom(rt.getClass()))) |
|
|
{ |
|
|
throw new MARSHAL(rt.getClass().getName() + |
|
|
" is not an instance of " + clz.getName() |
|
|
); |
|
|
} |
|
|
} |
|
|
return rt; |
|
153 |
} |
} |
154 |
|
|
155 |
/** |
/** |
156 |
* Read a value type structure content, when the unitialised |
* Read a value type structure content, when the unitialised |
157 |
* instance is passed as a parameter. |
* instance is passed as a parameter. It is a fastest method to read |
158 |
|
* a value type. |
159 |
* |
* |
160 |
* OMG specification states the writing format is outside the scope |
* As the type is known, the repository Id in the input stream is |
161 |
* of GIOP definition. This implementation uses java serialization |
* optional an not required. The codebase, if present, is also ignored. |
|
* mechanism, calling {@link ObjectInputStream#readObject} |
|
|
* and then compares the loaded instance with the given class |
|
|
* of the passed instance for equality. |
|
162 |
* |
* |
163 |
* @param unitialised_value, used for class check only. |
* The passed instance must implement either {@link CustomMarshal} |
164 |
|
* for the user-defined reading operations or {@link StreamableValue} |
165 |
|
* for the standard (generated by IDL compiler) reading operations. |
166 |
|
* |
167 |
|
* @param unitialised_value the unitialised value. |
168 |
* |
* |
169 |
* @return same value, filled in by the stream content. |
* @return same value, filled in by the stream content. |
170 |
*/ |
*/ |
171 |
public Serializable read_value(Serializable unitialised_value) |
public Serializable read_value(Serializable unitialised_value) |
172 |
{ |
{ |
173 |
return read_value(unitialised_value.getClass()); |
return Vio.read(this, unitialised_value); |
174 |
} |
} |
175 |
|
|
176 |
/** |
/** |
179 |
* searched for a suitable value factory, where it delegates |
* searched for a suitable value factory, where it delegates |
180 |
* the functionality. |
* the functionality. |
181 |
* |
* |
182 |
|
* If you know the exact class or can create an unitialised instance |
183 |
|
* of the value type, it is recommended (faster) to use |
184 |
|
* {@link #read_value(Class)} or {@link #read_value(Serializable)} |
185 |
|
* instead. |
186 |
|
* |
187 |
* @param repository_id a repository id of the value type. |
* @param repository_id a repository id of the value type. |
188 |
* |
* |
189 |
* @return an value type structure, unmarshaled from the stream |
* @return an value type structure, unmarshaled from the stream |
194 |
.read_value(this); |
.read_value(this); |
195 |
} |
} |
196 |
|
|
197 |
|
/** |
198 |
|
* Use the provided boxed value helper to read the value. |
199 |
|
* |
200 |
|
* @param helper a helper for reading the value from the stream. |
201 |
|
* |
202 |
|
* @return an value type structure, unmarshaled from the stream. |
203 |
|
*/ |
204 |
public Serializable read_value(BoxedValueHelper helper) |
public Serializable read_value(BoxedValueHelper helper) |
205 |
{ |
{ |
206 |
return helper.read_value(this); |
return helper.read_value(this); |