08d1759d8d21e19983ea07c5dde41534618d21f1
[gcc.git] /
1 /* comServant.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
48 import java.io.File;
49 import java.io.FileNotFoundException;
50 import java.io.FileOutputStream;
51 import java.io.FileReader;
52 import java.io.PrintStream;
53
54 /**
55 * This class handles the actual server functionality in this test
56 * application. When the client calls the remote method, this
57 * finally results calling the method of this class.
58 *
59 * The parameters, passed to the server only, are just parameters of the
60 * java methods. The parameters that shuld be returned to client
61 * are wrapped into holder classes.
62 *
63 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
64 */
65 public class comServant
66 extends _comTesterImplBase
67 {
68 /**
69 * The field, that can be set and checked by remote client.
70 */
71 private int m_theField = 17;
72
73 /**
74 * Passes wide (UTF-16) string and narrow (ISO8859_1) string.
75 * @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
76 * encodings. Returs they generalization as a wide string.
77 */
78 public String passCharacters(String wide, String narrow)
79 {
80 System.out.println("SERVER: **** Wide and narrow string test.");
81 System.out.println("SERVER: Received '" + narrow + "' and '" + wide +
82 "'"
83 );
84
85 return "return '" + narrow + "' and '" + wide + "'";
86 }
87
88 /**
89 * Accept and return parameters, having various types.
90 */
91 public int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short,
92 StringHolder a_string, DoubleHolder a_double
93 )
94 {
95 System.out.println("SERVER: ***** Test passing multiple parameters");
96 System.out.println("SERVER: Received:");
97 System.out.println("SERVER: octet " + an_octet.value);
98 System.out.println("SERVER: short " + a_short.value);
99 System.out.println("SERVER: string " + a_string.value);
100
101 // Returning incremented values.
102 an_octet.value++;
103 a_short.value++;
104
105 // OUT parameter, return only.
106 a_double.value = 1;
107 a_string.value += " [return]";
108 return 452572;
109 }
110
111 /**
112 * Accept and return the string arrays.
113 */
114 public String[] passStrings(String[] args)
115 {
116 System.out.println("SERVER: ***** Transferring string arrays");
117
118 String[] rt = new String[ args.length ];
119 for (int i = 0; i < args.length; i++)
120 {
121 System.out.println("SERVER: " + args [ i ]);
122
123 // Returning the changed content.
124 rt [ i ] = args [ i ] + ":" + args [ i ];
125 }
126 return rt;
127 }
128
129 /**
130 * Accept and return the structures.
131 */
132 public returnThis passStructure(passThis in_structure)
133 {
134 System.out.println("SERVER: ***** Transferring structures");
135 System.out.println("SERVER: Received " + in_structure.a + ":" +
136 in_structure.b
137 );
138
139 // Create and send back the returned structure.
140 returnThis r = new returnThis();
141 r.c = in_structure.a + in_structure.b;
142 r.n = 555;
143 r.arra = new int[] { 11, 22, 33 };
144 return r;
145 }
146
147 /**
148 * Pass and return the tree structure
149 */
150 public void passTree(nodeHolder tree)
151 {
152 System.out.println("SERVER: ***** Transferring tree");
153
154 StringBuffer b = new StringBuffer();
155
156 // This both creates the tree string representation
157 // and changes the node names.
158 getImage(b, tree.value);
159 System.out.println("SERVER: The tree was: " + b + ", returning changed.");
160 }
161
162 /**
163 * Just prints the hello message.
164 */
165 public void sayHello()
166 {
167 System.out.println("SERVER: ***** Hello, world!");
168 }
169
170 /**
171 * Get the value of our field.
172 */
173 public int theField()
174 {
175 System.out.println("SERVER: ***** Getting the field value, " + m_theField);
176 return m_theField;
177 }
178
179 /**
180 * Set the value of our field.
181 */
182 public void theField(int a_field)
183 {
184 System.out.println("SERVER: ***** Setting the field value to " + a_field);
185 m_theField = a_field;
186 }
187
188 /**
189 * Throw an exception.
190 *
191 * @param parameter specifies which exception will be thrown.
192 *
193 * @throws ourUserException for the non negative parameter.
194 * @throws BAD_OPERATION for the negative parameter.
195 */
196 public void throwException(int parameter)
197 throws ourUserException
198 {
199 System.out.println("SERVER: ***** Testing exceptions");
200 if (parameter > 0)
201 {
202 System.out.println("SERVER: Throwing the user exception, " +
203 "specific field = "+parameter
204 );
205 throw new ourUserException(parameter);
206 }
207 else
208 {
209 System.out.println("SERVER: Throwing " +
210 "the BAD_OPERATION, minor 456, completed"
211 );
212 throw new BAD_OPERATION(456, CompletionStatus.COMPLETED_YES);
213 }
214 }
215
216 /**
217 * Visit all tree nodes, getting the string representation
218 * and adding '++' to the node names.
219 *
220 * @param b the buffer to collect the string representation.
221 * @param n the rott tree node.
222 */
223 private void getImage(StringBuffer b, node n)
224 {
225 b.append(n.name);
226 n.name = n.name + "++";
227 b.append(": (");
228
229 for (int i = 0; i < n.children.length; i++)
230 {
231 getImage(b, n.children [ i ]);
232 b.append(' ');
233 }
234 b.append(") ");
235 }
236 }