OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / classpath / examples / gnu / classpath / examples / CORBA / SimpleCommunication / communication / _DemoTesterStub.java
1 /* _DemoTesterStub.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  * Following CORBA standards, the name of this class must start from
60  * underscore and end by the "Stub".
61  *
62  * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
63  */
64 public class _DemoTesterStub
65   extends ObjectImpl
66   implements DemoTester
67 {
68   /**
69    * A string array of DemoTester repository ids.
70    */
71   public static String[] _ids =
72     {
73       "IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/DemoTester:1.0"
74     };
75
76   /**
77    * Return an array of DemoTester repository ids.
78    */
79   public String[] _ids()
80   {
81     return _ids;
82   }
83
84   /**
85    * Passes wide (UTF-16) string and narrow (ISO8859_1) string.
86    * @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
87    * encodings.
88    */
89   public String passCharacters(String wide, String narrow)
90   {
91     InputStream in = null;
92     try
93       {
94         // Get the output stream.
95         OutputStream out = _request("passCharacters", true);
96
97         // Write the parameters.
98
99         // The first string is passed as "wide"
100         // (usually 16 bit UTF-16) string.
101         out.write_wstring(wide);
102
103         // The second string is passed as "narrow"
104         // (usually 8 bit ISO8859_1) string.
105         out.write_string(narrow);
106
107         // Do the invocation.
108         in = _invoke(out);
109
110         // Read the method return value.
111         String result = in.read_wstring();
112         return result;
113       }
114     catch (ApplicationException ex)
115       {
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());
120       }
121     catch (RemarshalException _rm)
122       {
123         // This exception means that the parameters must be re-written.
124         return passCharacters(wide, narrow);
125       }
126     finally
127       {
128         // Release the resources, associated with the reply stream.
129         _releaseReply(in);
130       }
131   }
132
133   /**
134    * Passes various parameters in both directions. The parameters that
135    * shoud also return the values are wrapped into holders.
136    */
137   public int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short,
138                         StringHolder a_string, DoubleHolder a_double
139                        )
140   {
141     InputStream in = null;
142     try
143       {
144         // Get the stream where the parameters must be written:
145         OutputStream out = _request("passSimple", true);
146
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);
152
153         // Invoke the method.
154         in = _invoke(out);
155
156         // Read the returned values.
157         int result = in.read_long();
158
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();
164         return result;
165       }
166     catch (ApplicationException ex)
167       {
168         // Handle excepion on remote side.
169         in = ex.getInputStream();
170         throw new MARSHAL(ex.getId());
171       }
172     catch (RemarshalException _rm)
173       {
174         // Handle instruction to resend the parameters.
175         return passSimple(an_octet, a_long, a_short, a_string, a_double);
176       }
177     finally
178       {
179         _releaseReply(in);
180       }
181   }
182
183   /**
184     Passes and returns the string sequence.
185     */
186   public String[] passStrings(String[] arg)
187   {
188     InputStream in = null;
189     try
190       {
191         // Get the stream where the parameters must be written:
192         OutputStream out = _request("passStrings", true);
193
194         // Wrap the string array using the string sequence helper.
195         StringSeqHelper.write(out, arg);
196
197         // Invoke the method.
198         in = _invoke(out);
199
200         // Read the returned result using the string sequence helper.
201         String[] result = StringSeqHelper.read(in);
202         return result;
203       }
204     catch (ApplicationException ex)
205       {
206         // Handle the exception, thrown on remote side.
207         in = ex.getInputStream();
208         throw new MARSHAL(ex.getId());
209       }
210     catch (RemarshalException _rm)
211       {
212         return passStrings(arg);
213       }
214     finally
215       {
216         _releaseReply(in);
217       }
218   }
219
220   /**
221     Passes and returns the structures.
222     */
223   public StructureToReturn passStructure(StructureToPass in_structure)
224   {
225     InputStream in = null;
226     try
227       {
228         // Get the stream where the parameters must be written.
229         OutputStream out = _request("passStructure", true);
230
231         // Write the structure, using its helper.
232         StructureToPassHelper.write(out, in_structure);
233
234         // Invoke the method.
235         in = _invoke(out);
236
237         // Read the returned structer, using another helper.
238         StructureToReturn result = StructureToReturnHelper.read(in);
239         return result;
240       }
241     catch (ApplicationException ex)
242       {
243         in = ex.getInputStream();
244         throw new MARSHAL(ex.getId());
245       }
246     catch (RemarshalException _rm)
247       {
248         return passStructure(in_structure);
249       }
250     finally
251       {
252         _releaseReply(in);
253       }
254   }
255
256   /**
257    * Pass and return the tree structure
258    */
259   public void passTree(TreeNodeHolder tree)
260   {
261     InputStream in = null;
262     try
263       {
264         // Get the stream where the parameters must be written.
265         OutputStream out = _request("passTree", true);
266
267         // Write the tree (TreeNode with its chilred, grandchildren and so on),
268         // using the appropriate helper.
269         TreeNodeHelper.write(out, tree.value);
270
271         // Call the method.
272         in = _invoke(out);
273
274         // Read the returned tree.
275         tree.value = TreeNodeHelper.read(in);
276       }
277     catch (ApplicationException ex)
278       {
279         // Handle eception on remote side.
280         in = ex.getInputStream();
281         throw new MARSHAL(ex.getId());
282       }
283     catch (RemarshalException _rm)
284       {
285         passTree(tree);
286       }
287     finally
288       {
289         _releaseReply(in);
290       }
291   }
292
293   /**
294    * One way call of the remote method.
295    */
296   public void sayHello()
297   {
298     InputStream in = null;
299     try
300       {
301         // As we do not expect any response, the second
302         // parameter is 'false'.
303         OutputStream out = _request("sayHello", false);
304         in = _invoke(out);
305       }
306     catch (ApplicationException ex)
307       {
308         in = ex.getInputStream();
309         throw new MARSHAL(ex.getId());
310       }
311     catch (RemarshalException _rm)
312       {
313         sayHello();
314       }
315     finally
316       {
317         _releaseReply(in);
318       }
319   }
320
321   /**
322    * Get the field value.
323    */
324   public int theField()
325   {
326     InputStream in = null;
327     try
328       {
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);
332         in = _invoke(out);
333
334         int result = in.read_long();
335         return result;
336       }
337     catch (ApplicationException ex)
338       {
339         in = ex.getInputStream();
340         throw new MARSHAL(ex.getId());
341       }
342     catch (RemarshalException _rm)
343       {
344         return theField();
345       }
346     finally
347       {
348         _releaseReply(in);
349       }
350   }
351
352   /**
353    * Set the field value.
354    */
355   public void theField(int newTheField)
356   {
357     InputStream in = null;
358     try
359       {
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);
364         in = _invoke(out);
365       }
366     catch (ApplicationException ex)
367       {
368         in = ex.getInputStream();
369         throw new MARSHAL(ex.getId());
370       }
371     catch (RemarshalException _rm)
372       {
373         theField(newTheField);
374       }
375     finally
376       {
377         _releaseReply(in);
378       }
379   }
380
381   /**
382    * The server side exception tests.
383    *
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.
387    *
388    * @throws WeThrowThisException
389    */
390   public void throwException(int parameter)
391                       throws WeThrowThisException
392   {
393     InputStream in = null;
394     try
395       {
396         // Get stream.
397         OutputStream out = _request("throwException", true);
398
399         // Write parameter.
400         out.write_long(parameter);
401
402         // Call method.
403         in = _invoke(out);
404       }
405     catch (ApplicationException ex)
406       {
407         in = ex.getInputStream();
408
409         // Get the exception id.
410         String id = ex.getId();
411
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")
415            )
416           throw WeThrowThisExceptionHelper.read(in);
417         else
418           throw new MARSHAL(id);
419       }
420     catch (RemarshalException _rm)
421       {
422         throwException(parameter);
423       }
424     finally
425       {
426         _releaseReply(in);
427       }
428   }
429 }