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