]> git.ipfire.org Git - thirdparty/gcc.git/blob
4c8f5b94c68d200c6d6804b0e8b75c68d29c9950
[thirdparty/gcc.git] /
1 /* _comTesterImplBase.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.BAD_OPERATION;
42 import org.omg.CORBA.ByteHolder;
43 import org.omg.CORBA.CompletionStatus;
44 import org.omg.CORBA.DoubleHolder;
45 import org.omg.CORBA.ShortHolder;
46 import org.omg.CORBA.StringHolder;
47 import org.omg.CORBA.StringSeqHelper;
48 import org.omg.CORBA.portable.InputStream;
49 import org.omg.CORBA.portable.InvokeHandler;
50 import org.omg.CORBA.portable.ObjectImpl;
51 import org.omg.CORBA.portable.OutputStream;
52 import org.omg.CORBA.portable.ResponseHandler;
53
54 /**
55 * The base for the class that is actually implementing the functionality
56 * of the object on the server side ({@link comServant} of our case).
57 *
58 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
59 */
60 public abstract class _comTesterImplBase
61 extends ObjectImpl
62 implements comTester, InvokeHandler
63 {
64 /**
65 * When the server receives the request message from client, it
66 * calls this method.
67 *
68 * @param a_method the method name.
69 * @param in the CDR stream, from where the implementing code must
70 * read the method parameters.
71 * @param rh the response handler, used to get the stream where
72 * the returned values must be written.
73 *
74 * @return the stream, obtained from the response handler.
75 */
76 public OutputStream _invoke(String a_method, InputStream in,
77 ResponseHandler rh
78 )
79 {
80 OutputStream out;
81
82 /* Get the field value. */
83 if (a_method.equals("_get_theField"))
84 {
85 int result = (int) 0;
86 result = theField();
87 out = rh.createReply();
88 out.write_long(result);
89 }
90 else
91 /* Set the field value. */
92 if (a_method.equals("_set_theField"))
93 {
94 int newTheField = in.read_long();
95 theField(newTheField);
96 out = rh.createReply();
97 }
98 else
99 /* Logs calls to the file. */
100 if (a_method.equals("sayHello"))
101 {
102 sayHello();
103 out = rh.createReply();
104 }
105 else
106 /* Passes various parameters in both directions. */
107 if (a_method.equals("passSimple"))
108 {
109 ByteHolder an_octet = new ByteHolder();
110 an_octet.value = in.read_octet();
111
112 int a_long = in.read_long();
113 ShortHolder a_short = new ShortHolder();
114 a_short.value = in.read_short();
115
116 StringHolder a_string = new StringHolder();
117 a_string.value = in.read_string();
118
119 DoubleHolder a_double = new DoubleHolder();
120 int result = passSimple(an_octet, a_long, a_short, a_string, a_double);
121 out = rh.createReply();
122 out.write_long(result);
123 out.write_octet(an_octet.value);
124 out.write_short(a_short.value);
125 out.write_string(a_string.value);
126 out.write_double(a_double.value);
127 }
128 else
129 /* Passes the 'wide' (usually Unicode) string and the ordinary string. */
130 if (a_method.equals("passCharacters"))
131 {
132 String wide = in.read_wstring();
133 String narrow = in.read_string();
134 String result = null;
135 result = passCharacters(wide, narrow);
136 out = rh.createReply();
137 out.write_wstring(result);
138 }
139 else
140 /*
141 Throws either 'ourUserException' with the 'ourField' field
142 initialised to the passed positive value
143 or system exception (if the parameter is zero or negative).
144 */
145 if (a_method.equals("throwException"))
146 {
147 try
148 {
149 int parameter = in.read_long();
150 throwException(parameter);
151 out = rh.createReply();
152 }
153 catch (ourUserException exception)
154 {
155 out = rh.createExceptionReply();
156 ourUserExceptionHelper.write(out, exception);
157 }
158 }
159 else
160 /* Passes and returns the structures. */
161 if (a_method.equals("passStructure"))
162 {
163 passThis in_structure = passThisHelper.read(in);
164 returnThis result = null;
165 result = passStructure(in_structure);
166 out = rh.createReply();
167 returnThisHelper.write(out, result);
168 }
169 else
170 /* Passes and returns the string sequence. */
171 if (a_method.equals("passStrings"))
172 {
173 String[] arg = StringSeqHelper.read(in);
174 String[] result = null;
175 result = passStrings(arg);
176 out = rh.createReply();
177 StringSeqHelper.write(out, result);
178 }
179 else
180 /** Pass and return the tree structure */
181 if (a_method.equals("passTree"))
182 {
183 nodeHolder tree = new nodeHolder();
184 tree.value = nodeHelper.read(in);
185 passTree(tree);
186 out = rh.createReply();
187 nodeHelper.write(out, tree.value);
188 }
189
190 else
191 throw new BAD_OPERATION("No method: " + a_method, 0,
192 CompletionStatus.COMPLETED_MAYBE
193 );
194
195 return out;
196 }
197
198 /**
199 * Return an array of this object repository ids.
200 */
201 public String[] _ids()
202 {
203 // They are the same as for the stub.
204 return _comTesterStub._ids;
205 }
206 }