libjava/ChangeLog:
[official-gcc.git] / libjava / classpath / examples / gnu / classpath / examples / CORBA / SimpleCommunication / communication / DemoServant.java
blob9af20d227abc83b51df1c363a7a214e8986df575
1 /* DemoServant.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)
9 any later version.
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
19 02110-1301 USA.
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.
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;
48 /**
49 * This class handles the actual server functionality in this test
50 * application. When the client calls the remote method, this
51 * finally results calling the method of this class.
53 * The parameters, passed to the server only, are just parameters of the
54 * java methods. The parameters that shuld be returned to client
55 * are wrapped into holder classes.
57 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
59 public class DemoServant
60 extends _DemoTesterImplBase
62 /**
63 * The field, that can be set and checked by remote client.
65 private int m_theField = 17;
67 /**
68 * Passes wide (UTF-16) string and narrow (ISO8859_1) string.
69 * @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
70 * encodings. Returs they generalization as a wide string.
72 public String passCharacters(String wide, String narrow)
74 System.out.println("SERVER: **** Wide and narrow string test.");
75 System.out.println("SERVER: Received '" + narrow + "' and '" + wide +
76 "'"
79 return "return '" + narrow + "' and '" + wide + "'";
82 /**
83 * Accept and return parameters, having various types.
85 public int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short,
86 StringHolder a_string, DoubleHolder a_double
89 System.out.println("SERVER: ***** Test passing multiple parameters");
90 System.out.println("SERVER: Received:");
91 System.out.println("SERVER: octet " + an_octet.value);
92 System.out.println("SERVER: short " + a_short.value);
93 System.out.println("SERVER: string " + a_string.value);
95 // Returning incremented values.
96 an_octet.value++;
97 a_short.value++;
99 // OUT parameter, return only.
100 a_double.value = 1;
101 a_string.value += " [return]";
102 return 452572;
106 * Accept and return the string arrays.
108 public String[] passStrings(String[] args)
110 System.out.println("SERVER: ***** Transferring string arrays");
112 String[] rt = new String[ args.length ];
113 for (int i = 0; i < args.length; i++)
115 System.out.println("SERVER: " + args [ i ]);
117 // Returning the changed content.
118 rt [ i ] = args [ i ] + ":" + args [ i ];
120 return rt;
124 * Accept and return the structures.
126 public StructureToReturn passStructure(StructureToPass in_structure)
128 System.out.println("SERVER: ***** Transferring structures");
129 System.out.println("SERVER: Received " + in_structure.a + ":" +
130 in_structure.b
133 // Create and send back the returned structure.
134 StructureToReturn r = new StructureToReturn();
135 r.c = in_structure.a + in_structure.b;
136 r.n = 555;
137 r.arra = new int[] { 11, 22, 33 };
138 return r;
142 * Pass and return the tree structure
144 public void passTree(TreeNodeHolder tree)
146 System.out.println("SERVER: ***** Transferring tree");
148 StringBuilder b = new StringBuilder();
150 // This both creates the tree string representation
151 // and changes the TreeNode names.
152 getImage(b, tree.value);
153 System.out.println("SERVER: The tree was: " + b + ", returning changed.");
157 * Just prints the hello message.
159 public void sayHello()
161 System.out.println("SERVER: ***** Hello, world!");
165 * Get the value of our field.
167 public int theField()
169 System.out.println("SERVER: ***** Getting the field value, " + m_theField);
170 return m_theField;
174 * Set the value of our field.
176 public void theField(int a_field)
178 System.out.println("SERVER: ***** Setting the field value to " + a_field);
179 m_theField = a_field;
183 * Throw an exception.
185 * @param parameter specifies which exception will be thrown.
187 * @throws WeThrowThisException for the non negative parameter.
188 * @throws BAD_OPERATION for the negative parameter.
190 public void throwException(int parameter)
191 throws WeThrowThisException
193 System.out.println("SERVER: ***** Testing exceptions");
194 if (parameter > 0)
196 System.out.println("SERVER: Throwing the user exception, " +
197 "specific field = "+parameter
199 throw new WeThrowThisException(parameter);
201 else
203 System.out.println("SERVER: Throwing " +
204 "the BAD_OPERATION, minor 456, completed"
206 throw new BAD_OPERATION(456, CompletionStatus.COMPLETED_YES);
211 * Visit all tree nodes, getting the string representation
212 * and adding '++' to the TreeNode names.
214 * @param b the buffer to collect the string representation.
215 * @param n the rott tree TreeNode.
217 private void getImage(StringBuilder b, TreeNode n)
219 b.append(n.name);
220 n.name = n.name + "++";
221 b.append(": (");
223 for (int i = 0; i < n.children.length; i++)
225 getImage(b, n.children [ i ]);
226 b.append(' ');
228 b.append(") ");