1 /* _DemoTesterStub.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 * Following CORBA standards, the name of this class must start from
60 * underscore and end by the "Stub".
62 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
64 public class _DemoTesterStub
69 * A string array of DemoTester repository ids.
71 public static String[] _ids =
73 "IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/DemoTester:1.0"
77 * Return an array of DemoTester repository ids.
79 public String[] _ids()
85 * Passes wide (UTF-16) string and narrow (ISO8859_1) string.
86 * @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
89 public String passCharacters(String wide, String narrow)
91 InputStream in = null;
94 // Get the output stream.
95 OutputStream out = _request("passCharacters", true);
97 // Write the parameters.
99 // The first string is passed as "wide"
100 // (usually 16 bit UTF-16) string.
101 out.write_wstring(wide);
103 // The second string is passed as "narrow"
104 // (usually 8 bit ISO8859_1) string.
105 out.write_string(narrow);
107 // Do the invocation.
110 // Read the method return value.
111 String result = in.read_wstring();
114 catch (ApplicationException ex)
116 // The exception has been throws on remote side, but we
117 // do not expect any. Throw the MARSHAL exception.
118 in = ex.getInputStream();
119 throw new MARSHAL(ex.getId());
121 catch (RemarshalException _rm)
123 // This exception means that the parameters must be re-written.
124 return passCharacters(wide, narrow);
128 // Release the resources, associated with the reply stream.
134 * Passes various parameters in both directions. The parameters that
135 * shoud also return the values are wrapped into holders.
137 public int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short,
138 StringHolder a_string, DoubleHolder a_double
141 InputStream in = null;
144 // Get the stream where the parameters must be written:
145 OutputStream out = _request("passSimple", true);
147 // Write the parameters.
148 out.write_octet(an_octet.value);
149 out.write_long(a_long);
150 out.write_short(a_short.value);
151 out.write_string(a_string.value);
153 // Invoke the method.
156 // Read the returned values.
157 int result = in.read_long();
159 // Read the inout and out parameters.
160 an_octet.value = in.read_octet();
161 a_short.value = in.read_short();
162 a_string.value = in.read_string();
163 a_double.value = in.read_double();
166 catch (ApplicationException ex)
168 // Handle excepion on remote side.
169 in = ex.getInputStream();
170 throw new MARSHAL(ex.getId());
172 catch (RemarshalException _rm)
174 // Handle instruction to resend the parameters.
175 return passSimple(an_octet, a_long, a_short, a_string, a_double);
184 Passes and returns the string sequence.
186 public String[] passStrings(String[] arg)
188 InputStream in = null;
191 // Get the stream where the parameters must be written:
192 OutputStream out = _request("passStrings", true);
194 // Wrap the string array using the string sequence helper.
195 StringSeqHelper.write(out, arg);
197 // Invoke the method.
200 // Read the returned result using the string sequence helper.
201 String[] result = StringSeqHelper.read(in);
204 catch (ApplicationException ex)
206 // Handle the exception, thrown on remote side.
207 in = ex.getInputStream();
208 throw new MARSHAL(ex.getId());
210 catch (RemarshalException _rm)
212 return passStrings(arg);
221 Passes and returns the structures.
223 public StructureToReturn passStructure(StructureToPass in_structure)
225 InputStream in = null;
228 // Get the stream where the parameters must be written.
229 OutputStream out = _request("passStructure", true);
231 // Write the structure, using its helper.
232 StructureToPassHelper.write(out, in_structure);
234 // Invoke the method.
237 // Read the returned structer, using another helper.
238 StructureToReturn result = StructureToReturnHelper.read(in);
241 catch (ApplicationException ex)
243 in = ex.getInputStream();
244 throw new MARSHAL(ex.getId());
246 catch (RemarshalException _rm)
248 return passStructure(in_structure);
257 * Pass and return the tree structure
259 public void passTree(TreeNodeHolder tree)
261 InputStream in = null;
264 // Get the stream where the parameters must be written.
265 OutputStream out = _request("passTree", true);
267 // Write the tree (TreeNode with its chilred, grandchildren and so on),
268 // using the appropriate helper.
269 TreeNodeHelper.write(out, tree.value);
274 // Read the returned tree.
275 tree.value = TreeNodeHelper.read(in);
277 catch (ApplicationException ex)
279 // Handle eception on remote side.
280 in = ex.getInputStream();
281 throw new MARSHAL(ex.getId());
283 catch (RemarshalException _rm)
294 * One way call of the remote method.
296 public void sayHello()
298 InputStream in = null;
301 // As we do not expect any response, the second
302 // parameter is 'false'.
303 OutputStream out = _request("sayHello", false);
306 catch (ApplicationException ex)
308 in = ex.getInputStream();
309 throw new MARSHAL(ex.getId());
311 catch (RemarshalException _rm)
322 * Get the field value.
324 public int theField()
326 InputStream in = null;
329 // The special name of operation instructs just to get
330 // the field value rather than calling the method.
331 OutputStream out = _request("_get_theField", true);
334 int result = in.read_long();
337 catch (ApplicationException ex)
339 in = ex.getInputStream();
340 throw new MARSHAL(ex.getId());
342 catch (RemarshalException _rm)
353 * Set the field value.
355 public void theField(int newTheField)
357 InputStream in = null;
360 // The special name of operation instructs just to set
361 // the field value rather than calling the method.
362 OutputStream out = _request("_set_theField", true);
363 out.write_long(newTheField);
366 catch (ApplicationException ex)
368 in = ex.getInputStream();
369 throw new MARSHAL(ex.getId());
371 catch (RemarshalException _rm)
373 theField(newTheField);
382 * The server side exception tests.
384 * @param parameter the server throws the user exception in the case
385 * of the positive value of this argument, and system
386 * exception otherwise.
388 * @throws WeThrowThisException
390 public void throwException(int parameter)
391 throws WeThrowThisException
393 InputStream in = null;
397 OutputStream out = _request("throwException", true);
400 out.write_long(parameter);
405 catch (ApplicationException ex)
407 in = ex.getInputStream();
409 // Get the exception id.
410 String id = ex.getId();
412 // If this is the user exception we expect to catch, read and throw
413 // it here. The system exception, if thrown, is handled by _invoke.
414 if (id.equals("IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/WeThrowThisException:1.0")
416 throw WeThrowThisExceptionHelper.read(in);
418 throw new MARSHAL(id);
420 catch (RemarshalException _rm)
422 throwException(parameter);