1 /* _comTesterStub.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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
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
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. */
39 package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
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;
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
59 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
61 public class _comTesterStub
66 * A string array of comTester repository ids.
68 public static String[] _ids =
70 "IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/comTester:1.0"
74 * Return an array of comTester repository ids.
76 public String[] _ids()
82 * Passes wide (UTF-16) string and narrow (ISO8859_1) string.
83 * @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
86 public String passCharacters(String wide, String narrow)
88 InputStream in = null;
91 // Get the output stream.
92 OutputStream out = _request("passCharacters", true);
94 // Write the parameters.
96 // The first string is passed as "wide"
97 // (usually 16 bit UTF-16) string.
98 out.write_wstring(wide);
100 // The second string is passed as "narrow"
101 // (usually 8 bit ISO8859_1) string.
102 out.write_string(narrow);
104 // Do the invocation.
107 // Read the method return value.
108 String result = in.read_wstring();
111 catch (ApplicationException ex)
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());
118 catch (RemarshalException _rm)
120 // This exception means that the parameters must be re-written.
121 return passCharacters(wide, narrow);
125 // Release the resources, associated with the reply stream.
131 * Passes various parameters in both directions. The parameters that
132 * shoud also return the values are wrapped into holders.
134 public int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short,
135 StringHolder a_string, DoubleHolder a_double
138 InputStream in = null;
141 // Get the stream where the parameters must be written:
142 OutputStream out = _request("passSimple", true);
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);
150 // Invoke the method.
153 // Read the returned values.
154 int result = in.read_long();
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();
163 catch (ApplicationException ex)
165 // Handle excepion on remote side.
166 in = ex.getInputStream();
167 throw new MARSHAL(ex.getId());
169 catch (RemarshalException _rm)
171 // Handle instruction to resend the parameters.
172 return passSimple(an_octet, a_long, a_short, a_string, a_double);
181 Passes and returns the string sequence.
183 public String[] passStrings(String[] arg)
185 InputStream in = null;
188 // Get the stream where the parameters must be written:
189 OutputStream out = _request("passStrings", true);
191 // Wrap the string array using the string sequence helper.
192 StringSeqHelper.write(out, arg);
194 // Invoke the method.
197 // Read the returned result using the string sequence helper.
198 String[] result = StringSeqHelper.read(in);
201 catch (ApplicationException ex)
203 // Handle the exception, thrown on remote side.
204 in = ex.getInputStream();
205 throw new MARSHAL(ex.getId());
207 catch (RemarshalException _rm)
209 return passStrings(arg);
218 Passes and returns the structures.
220 public returnThis passStructure(passThis in_structure)
222 InputStream in = null;
225 // Get the stream where the parameters must be written.
226 OutputStream out = _request("passStructure", true);
228 // Write the structure, using its helper.
229 passThisHelper.write(out, in_structure);
231 // Invoke the method.
234 // Read the returned structer, using another helper.
235 returnThis result = returnThisHelper.read(in);
238 catch (ApplicationException ex)
240 in = ex.getInputStream();
241 throw new MARSHAL(ex.getId());
243 catch (RemarshalException _rm)
245 return passStructure(in_structure);
254 * Pass and return the tree structure
256 public void passTree(nodeHolder tree)
258 InputStream in = null;
261 // Get the stream where the parameters must be written.
262 OutputStream out = _request("passTree", true);
264 // Write the tree (node with its chilred, grandchildren and so on),
265 // using the appropriate helper.
266 nodeHelper.write(out, tree.value);
271 // Read the returned tree.
272 tree.value = nodeHelper.read(in);
274 catch (ApplicationException ex)
276 // Handle eception on remote side.
277 in = ex.getInputStream();
278 throw new MARSHAL(ex.getId());
280 catch (RemarshalException _rm)
291 * One way call of the remote method.
293 public void sayHello()
295 InputStream in = null;
298 // As we do not expect any response, the second
299 // parameter is 'false'.
300 OutputStream out = _request("sayHello", false);
303 catch (ApplicationException ex)
305 in = ex.getInputStream();
306 throw new MARSHAL(ex.getId());
308 catch (RemarshalException _rm)
319 * Get the field value.
321 public int theField()
323 InputStream in = null;
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);
331 int result = in.read_long();
334 catch (ApplicationException ex)
336 in = ex.getInputStream();
337 throw new MARSHAL(ex.getId());
339 catch (RemarshalException _rm)
350 * Set the field value.
352 public void theField(int newTheField)
354 InputStream in = null;
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);
363 catch (ApplicationException ex)
365 in = ex.getInputStream();
366 throw new MARSHAL(ex.getId());
368 catch (RemarshalException _rm)
370 theField(newTheField);
379 * The server side exception tests.
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.
385 * @throws ourUserException
387 public void throwException(int parameter)
388 throws ourUserException
390 InputStream in = null;
394 OutputStream out = _request("throwException", true);
397 out.write_long(parameter);
402 catch (ApplicationException ex)
404 in = ex.getInputStream();
406 // Get the exception id.
407 String id = ex.getId();
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")
413 throw ourUserExceptionHelper.read(in);
415 throw new MARSHAL(id);
417 catch (RemarshalException _rm)
419 throwException(parameter);