b71cd8e863f7b0c3c94ec423e3e52f7cefb5b2f2
[gcc.git] /
1 /* _comTesterStub.java --
2 Copyright (C) 2005 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 gnu.classpath.examples.CORBA.SimpleCommunication.communication;
40
41 import org.omg.CORBA.ByteHolder;
42 import org.omg.CORBA.DoubleHolder;
43 import org.omg.CORBA.MARSHAL;
44 import org.omg.CORBA.ShortHolder;
45 import org.omg.CORBA.StringHolder;
46 import org.omg.CORBA.StringSeqHelper;
47 import org.omg.CORBA.portable.ApplicationException;
48 import org.omg.CORBA.portable.InputStream;
49 import org.omg.CORBA.portable.ObjectImpl;
50 import org.omg.CORBA.portable.OutputStream;
51 import org.omg.CORBA.portable.RemarshalException;
52
53 /**
54 * The stub (proxy) class, representing the remote object on the client
55 * side. It has all the same methods as the actual implementation
56 * on the server side. These methods contain the code for remote
57 * invocation.
58 *
59 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
60 */
61 public class _comTesterStub
62 extends ObjectImpl
63 implements comTester
64 {
65 /**
66 * A string array of comTester repository ids.
67 */
68 public static String[] _ids =
69 {
70 "IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/comTester:1.0"
71 };
72
73 /**
74 * Return an array of comTester repository ids.
75 */
76 public String[] _ids()
77 {
78 return _ids;
79 }
80
81 /**
82 * Passes wide (UTF-16) string and narrow (ISO8859_1) string.
83 * @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
84 * encodings.
85 */
86 public String passCharacters(String wide, String narrow)
87 {
88 InputStream in = null;
89 try
90 {
91 // Get the output stream.
92 OutputStream out = _request("passCharacters", true);
93
94 // Write the parameters.
95
96 // The first string is passed as "wide"
97 // (usually 16 bit UTF-16) string.
98 out.write_wstring(wide);
99
100 // The second string is passed as "narrow"
101 // (usually 8 bit ISO8859_1) string.
102 out.write_string(narrow);
103
104 // Do the invocation.
105 in = _invoke(out);
106
107 // Read the method return value.
108 String result = in.read_wstring();
109 return result;
110 }
111 catch (ApplicationException ex)
112 {
113 // The exception has been throws on remote side, but we
114 // do not expect any. Throw the MARSHAL exception.
115 in = ex.getInputStream();
116 throw new MARSHAL(ex.getId());
117 }
118 catch (RemarshalException _rm)
119 {
120 // This exception means that the parameters must be re-written.
121 return passCharacters(wide, narrow);
122 }
123 finally
124 {
125 // Release the resources, associated with the reply stream.
126 _releaseReply(in);
127 }
128 }
129
130 /**
131 * Passes various parameters in both directions. The parameters that
132 * shoud also return the values are wrapped into holders.
133 */
134 public int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short,
135 StringHolder a_string, DoubleHolder a_double
136 )
137 {
138 InputStream in = null;
139 try
140 {
141 // Get the stream where the parameters must be written:
142 OutputStream out = _request("passSimple", true);
143
144 // Write the parameters.
145 out.write_octet(an_octet.value);
146 out.write_long(a_long);
147 out.write_short(a_short.value);
148 out.write_string(a_string.value);
149
150 // Invoke the method.
151 in = _invoke(out);
152
153 // Read the returned values.
154 int result = in.read_long();
155
156 // Read the inout and out parameters.
157 an_octet.value = in.read_octet();
158 a_short.value = in.read_short();
159 a_string.value = in.read_string();
160 a_double.value = in.read_double();
161 return result;
162 }
163 catch (ApplicationException ex)
164 {
165 // Handle excepion on remote side.
166 in = ex.getInputStream();
167 throw new MARSHAL(ex.getId());
168 }
169 catch (RemarshalException _rm)
170 {
171 // Handle instruction to resend the parameters.
172 return passSimple(an_octet, a_long, a_short, a_string, a_double);
173 }
174 finally
175 {
176 _releaseReply(in);
177 }
178 }
179
180 /**
181 Passes and returns the string sequence.
182 */
183 public String[] passStrings(String[] arg)
184 {
185 InputStream in = null;
186 try
187 {
188 // Get the stream where the parameters must be written:
189 OutputStream out = _request("passStrings", true);
190
191 // Wrap the string array using the string sequence helper.
192 StringSeqHelper.write(out, arg);
193
194 // Invoke the method.
195 in = _invoke(out);
196
197 // Read the returned result using the string sequence helper.
198 String[] result = StringSeqHelper.read(in);
199 return result;
200 }
201 catch (ApplicationException ex)
202 {
203 // Handle the exception, thrown on remote side.
204 in = ex.getInputStream();
205 throw new MARSHAL(ex.getId());
206 }
207 catch (RemarshalException _rm)
208 {
209 return passStrings(arg);
210 }
211 finally
212 {
213 _releaseReply(in);
214 }
215 }
216
217 /**
218 Passes and returns the structures.
219 */
220 public returnThis passStructure(passThis in_structure)
221 {
222 InputStream in = null;
223 try
224 {
225 // Get the stream where the parameters must be written.
226 OutputStream out = _request("passStructure", true);
227
228 // Write the structure, using its helper.
229 passThisHelper.write(out, in_structure);
230
231 // Invoke the method.
232 in = _invoke(out);
233
234 // Read the returned structer, using another helper.
235 returnThis result = returnThisHelper.read(in);
236 return result;
237 }
238 catch (ApplicationException ex)
239 {
240 in = ex.getInputStream();
241 throw new MARSHAL(ex.getId());
242 }
243 catch (RemarshalException _rm)
244 {
245 return passStructure(in_structure);
246 }
247 finally
248 {
249 _releaseReply(in);
250 }
251 }
252
253 /**
254 * Pass and return the tree structure
255 */
256 public void passTree(nodeHolder tree)
257 {
258 InputStream in = null;
259 try
260 {
261 // Get the stream where the parameters must be written.
262 OutputStream out = _request("passTree", true);
263
264 // Write the tree (node with its chilred, grandchildren and so on),
265 // using the appropriate helper.
266 nodeHelper.write(out, tree.value);
267
268 // Call the method.
269 in = _invoke(out);
270
271 // Read the returned tree.
272 tree.value = nodeHelper.read(in);
273 }
274 catch (ApplicationException ex)
275 {
276 // Handle eception on remote side.
277 in = ex.getInputStream();
278 throw new MARSHAL(ex.getId());
279 }
280 catch (RemarshalException _rm)
281 {
282 passTree(tree);
283 }
284 finally
285 {
286 _releaseReply(in);
287 }
288 }
289
290 /**
291 * One way call of the remote method.
292 */
293 public void sayHello()
294 {
295 InputStream in = null;
296 try
297 {
298 // As we do not expect any response, the second
299 // parameter is 'false'.
300 OutputStream out = _request("sayHello", false);
301 in = _invoke(out);
302 }
303 catch (ApplicationException ex)
304 {
305 in = ex.getInputStream();
306 throw new MARSHAL(ex.getId());
307 }
308 catch (RemarshalException _rm)
309 {
310 sayHello();
311 }
312 finally
313 {
314 _releaseReply(in);
315 }
316 }
317
318 /**
319 * Get the field value.
320 */
321 public int theField()
322 {
323 InputStream in = null;
324 try
325 {
326 // The special name of operation instructs just to get
327 // the field value rather than calling the method.
328 OutputStream out = _request("_get_theField", true);
329 in = _invoke(out);
330
331 int result = in.read_long();
332 return result;
333 }
334 catch (ApplicationException ex)
335 {
336 in = ex.getInputStream();
337 throw new MARSHAL(ex.getId());
338 }
339 catch (RemarshalException _rm)
340 {
341 return theField();
342 }
343 finally
344 {
345 _releaseReply(in);
346 }
347 }
348
349 /**
350 * Set the field value.
351 */
352 public void theField(int newTheField)
353 {
354 InputStream in = null;
355 try
356 {
357 // The special name of operation instructs just to set
358 // the field value rather than calling the method.
359 OutputStream out = _request("_set_theField", true);
360 out.write_long(newTheField);
361 in = _invoke(out);
362 }
363 catch (ApplicationException ex)
364 {
365 in = ex.getInputStream();
366 throw new MARSHAL(ex.getId());
367 }
368 catch (RemarshalException _rm)
369 {
370 theField(newTheField);
371 }
372 finally
373 {
374 _releaseReply(in);
375 }
376 }
377
378 /**
379 * The server side exception tests.
380 *
381 * @param parameter the server throws the user exception in the case
382 * of the positive value of this argument, and system
383 * exception otherwise.
384 *
385 * @throws ourUserException
386 */
387 public void throwException(int parameter)
388 throws ourUserException
389 {
390 InputStream in = null;
391 try
392 {
393 // Get stream.
394 OutputStream out = _request("throwException", true);
395
396 // Write parameter.
397 out.write_long(parameter);
398
399 // Call method.
400 in = _invoke(out);
401 }
402 catch (ApplicationException ex)
403 {
404 in = ex.getInputStream();
405
406 // Get the exception id.
407 String id = ex.getId();
408
409 // If this is the user exception we expect to catch, read and throw
410 // it here. The system exception, if thrown, is handled by _invoke.
411 if (id.equals("IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/ourUserException:1.0")
412 )
413 throw ourUserExceptionHelper.read(in);
414 else
415 throw new MARSHAL(id);
416 }
417 catch (RemarshalException _rm)
418 {
419 throwException(parameter);
420 }
421 finally
422 {
423 _releaseReply(in);
424 }
425 }
426 }