1 /* _DemoTesterImplBase.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.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;
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).
58 * Following CORBA standards, the name of this class must start from
59 * underscore and end by the "ImplBase".
61 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
63 public abstract class _DemoTesterImplBase
65 implements DemoTester, InvokeHandler
68 * When the server receives the request message from client, it
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.
77 * @return the stream, obtained from the response handler.
79 public OutputStream _invoke(String a_method, InputStream in,
85 /* Get the field value. */
86 if (a_method.equals("_get_theField"))
90 out = rh.createReply();
91 out.write_long(result);
94 /* Set the field value. */
95 if (a_method.equals("_set_theField"))
97 int newTheField = in.read_long();
98 theField(newTheField);
99 out = rh.createReply();
102 /* Logs calls to the file. */
103 if (a_method.equals("sayHello"))
106 out = rh.createReply();
109 /* Passes various parameters in both directions. */
110 if (a_method.equals("passSimple"))
112 ByteHolder an_octet = new ByteHolder();
113 an_octet.value = in.read_octet();
115 int a_long = in.read_long();
116 ShortHolder a_short = new ShortHolder();
117 a_short.value = in.read_short();
119 StringHolder a_string = new StringHolder();
120 a_string.value = in.read_string();
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);
132 /* Passes the 'wide' (usually Unicode) string and the ordinary string. */
133 if (a_method.equals("passCharacters"))
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);
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).
148 if (a_method.equals("throwException"))
152 int parameter = in.read_long();
153 throwException(parameter);
154 out = rh.createReply();
156 catch (WeThrowThisException exception)
158 out = rh.createExceptionReply();
159 WeThrowThisExceptionHelper.write(out, exception);
163 /* Passes and returns the structures. */
164 if (a_method.equals("passStructure"))
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);
173 /* Passes and returns the string sequence. */
174 if (a_method.equals("passStrings"))
176 String[] arg = StringSeqHelper.read(in);
177 String[] result = null;
178 result = passStrings(arg);
179 out = rh.createReply();
180 StringSeqHelper.write(out, result);
183 /** Pass and return the tree structure */
184 if (a_method.equals("passTree"))
186 TreeNodeHolder tree = new TreeNodeHolder();
187 tree.value = TreeNodeHelper.read(in);
189 out = rh.createReply();
190 TreeNodeHelper.write(out, tree.value);
194 throw new BAD_OPERATION("No method: " + a_method, 0,
195 CompletionStatus.COMPLETED_MAYBE
202 * Return an array of this object repository ids.
204 public String[] _ids()
206 // They are the same as for the stub.
207 return _DemoTesterStub._ids;