OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [examples/] [gnu/] [classpath/] [examples/] [CORBA/] [SimpleCommunication/] [communication/] [DemoServant.java] - Blame information for rev 781

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 781 jeremybenn
/* DemoServant.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
/**
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.
52
 *
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.
56
 *
57
 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
58
 */
59
public class DemoServant
60
  extends _DemoTesterImplBase
61
{
62
  /**
63
   * The field, that can be set and checked by remote client.
64
   */
65
  private int m_theField = 17;
66
 
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.
71
   */
72
  public String passCharacters(String wide, String narrow)
73
  {
74
    System.out.println("SERVER: **** Wide and narrow string test.");
75
    System.out.println("SERVER:   Received '" + narrow + "' and '" + wide +
76
                       "'"
77
                      );
78
 
79
    return "return '" + narrow + "' and '" + wide + "'";
80
  }
81
 
82
  /**
83
   * Accept and return parameters, having various types.
84
   */
85
  public int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short,
86
                        StringHolder a_string, DoubleHolder a_double
87
                       )
88
  {
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);
94
 
95
    // Returning incremented values.
96
    an_octet.value++;
97
    a_short.value++;
98
 
99
    // OUT parameter, return only.
100
    a_double.value = 1;
101
    a_string.value += " [return]";
102
    return 452572;
103
  }
104
 
105
  /**
106
   * Accept and return the string arrays.
107
   */
108
  public String[] passStrings(String[] args)
109
  {
110
    System.out.println("SERVER: ***** Transferring string arrays");
111
 
112
    String[] rt = new String[ args.length ];
113
    for (int i = 0; i < args.length; i++)
114
      {
115
        System.out.println("SERVER:   " + args [ i ]);
116
 
117
        // Returning the changed content.
118
        rt [ i ] = args [ i ] + ":" + args [ i ];
119
      }
120
    return rt;
121
  }
122
 
123
  /**
124
   * Accept and return the structures.
125
   */
126
  public StructureToReturn passStructure(StructureToPass in_structure)
127
  {
128
    System.out.println("SERVER: ***** Transferring structures");
129
    System.out.println("SERVER:   Received " + in_structure.a + ":" +
130
                       in_structure.b
131
                      );
132
 
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;
139
  }
140
 
141
  /**
142
   * Pass and return the tree structure
143
   */
144
  public void passTree(TreeNodeHolder tree)
145
  {
146
    System.out.println("SERVER: ***** Transferring tree");
147
 
148
    StringBuilder b = new StringBuilder();
149
 
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.");
154
  }
155
 
156
  /**
157
   * Just prints the hello message.
158
   */
159
  public void sayHello()
160
  {
161
    System.out.println("SERVER: ***** Hello, world!");
162
  }
163
 
164
  /**
165
   * Get the value of our field.
166
   */
167
  public int theField()
168
  {
169
    System.out.println("SERVER: ***** Getting the field value, " + m_theField);
170
    return m_theField;
171
  }
172
 
173
  /**
174
   * Set the value of our field.
175
   */
176
  public void theField(int a_field)
177
  {
178
    System.out.println("SERVER: ***** Setting the field value to " + a_field);
179
    m_theField = a_field;
180
  }
181
 
182
  /**
183
   * Throw an exception.
184
   *
185
   * @param parameter specifies which exception will be thrown.
186
   *
187
   * @throws WeThrowThisException for the non negative parameter.
188
   * @throws BAD_OPERATION for the negative parameter.
189
   */
190
  public void throwException(int parameter)
191
                      throws WeThrowThisException
192
  {
193
    System.out.println("SERVER: ***** Testing exceptions");
194
    if (parameter > 0)
195
      {
196
        System.out.println("SERVER:   Throwing the user exception, " +
197
                           "specific field = "+parameter
198
                          );
199
        throw new WeThrowThisException(parameter);
200
      }
201
    else
202
      {
203
        System.out.println("SERVER:   Throwing " +
204
                           "the BAD_OPERATION, minor 456, completed"
205
                          );
206
        throw new BAD_OPERATION(456, CompletionStatus.COMPLETED_YES);
207
      }
208
  }
209
 
210
  /**
211
   * Visit all tree nodes, getting the string representation
212
   * and adding '++' to the TreeNode names.
213
   *
214
   * @param b the buffer to collect the string representation.
215
   * @param n the rott tree TreeNode.
216
   */
217
  private void getImage(StringBuilder b, TreeNode n)
218
  {
219
    b.append(n.name);
220
    n.name = n.name + "++";
221
    b.append(": (");
222
 
223
    for (int i = 0; i < n.children.length; i++)
224
      {
225
        getImage(b, n.children [ i ]);
226
        b.append(' ');
227
      }
228
    b.append(") ");
229
  }
230
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.