1 |
779 |
jeremybenn |
/* GiopIo.java -- Generates GIOP input/output statements.
|
2 |
|
|
Copyright (C) 2006 Free Software Foundation
|
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.tools.rmic;
|
40 |
|
|
|
41 |
|
|
import java.rmi.Remote;
|
42 |
|
|
|
43 |
|
|
import org.omg.CORBA.portable.ObjectImpl;
|
44 |
|
|
|
45 |
|
|
/**
|
46 |
|
|
* Generates the code for reading and writing data over GIOP stream.
|
47 |
|
|
*
|
48 |
|
|
* @author Audrius Meskauskas, Lithuania (audriusa@Bioinformatics.org)
|
49 |
|
|
*/
|
50 |
|
|
public class GiopIo
|
51 |
|
|
{
|
52 |
|
|
/**
|
53 |
|
|
* Get the statement for writing the variable of the given type to the GIOP ({@link org.omg.CORBA_2_3.portable.OutputStream) stream. The
|
54 |
|
|
* stream is always named "out".
|
55 |
|
|
*
|
56 |
|
|
* @param c
|
57 |
|
|
* the class of the object being written
|
58 |
|
|
* @param variable
|
59 |
|
|
* the variable, where the object value is stored
|
60 |
|
|
* @param r
|
61 |
|
|
* the parent generator, used to name the class
|
62 |
|
|
* @return the write statement.
|
63 |
|
|
*/
|
64 |
|
|
public static String getWriteStatement(Class c, String variable, SourceGiopRmicCompiler r)
|
65 |
|
|
{
|
66 |
|
|
if (c.equals(boolean.class))
|
67 |
|
|
return "out.write_boolean(" + variable + ");";
|
68 |
|
|
if (c.equals(byte.class))
|
69 |
|
|
return "out.write_octet(" + variable + ");";
|
70 |
|
|
else if (c.equals(short.class))
|
71 |
|
|
return "out.write_int(" + variable + ");";
|
72 |
|
|
else if (c.equals(int.class))
|
73 |
|
|
return "out.write_long(" + variable + ");";
|
74 |
|
|
else if (c.equals(long.class))
|
75 |
|
|
return "out.write_long_long(" + variable + ");";
|
76 |
|
|
else if (c.equals(double.class))
|
77 |
|
|
return "out.write_double(" + variable + ");";
|
78 |
|
|
else if (c.equals(float.class))
|
79 |
|
|
return "out.write_float(" + variable + ");";
|
80 |
|
|
else if (c.equals(char.class))
|
81 |
|
|
return "out.write_char(" + variable + ");";
|
82 |
|
|
else if (Remote.class.isAssignableFrom(c))
|
83 |
|
|
return "Util.writeRemoteObject(out, " + variable + ");";
|
84 |
|
|
else if (ObjectImpl.class.isAssignableFrom(c))
|
85 |
|
|
return "out.write_Object(" + variable + ");";
|
86 |
|
|
else
|
87 |
|
|
return "out.write_value(" + variable + ", " + r.name(c) + ".class);";
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
/**
|
91 |
|
|
* Get the statement for reading the value of the given type from to the GIOP ({@link org.omg.CORBA_2_3.portable.InputStream) stream. The
|
92 |
|
|
* stream is always named "in".
|
93 |
|
|
*
|
94 |
|
|
* @param c
|
95 |
|
|
* the class of the object being written
|
96 |
|
|
* @param r
|
97 |
|
|
* the parent generator, used to name the class
|
98 |
|
|
* @return the right side of the read statement.
|
99 |
|
|
*/
|
100 |
|
|
public static String getReadStatement(Class c, SourceGiopRmicCompiler r)
|
101 |
|
|
{
|
102 |
|
|
if (c.equals(boolean.class))
|
103 |
|
|
return "in.read_boolean();";
|
104 |
|
|
else if (c.equals(byte.class))
|
105 |
|
|
return "in.read_octet();";
|
106 |
|
|
else if (c.equals(short.class))
|
107 |
|
|
return "in.read_int();";
|
108 |
|
|
else if (c.equals(int.class))
|
109 |
|
|
return "in.read_long();";
|
110 |
|
|
else if (c.equals(long.class))
|
111 |
|
|
return "in.read_long_long();";
|
112 |
|
|
else if (c.equals(double.class))
|
113 |
|
|
return "in.read_double();";
|
114 |
|
|
else if (c.equals(float.class))
|
115 |
|
|
return "in.read_float();";
|
116 |
|
|
else if (c.equals(char.class))
|
117 |
|
|
return "in.read_char();";
|
118 |
|
|
else if (Remote.class.isAssignableFrom(c))
|
119 |
|
|
return "(" + r.name(c)
|
120 |
|
|
+ ") PortableRemoteObject.narrow(in.read_Object()," + r.name(c)
|
121 |
|
|
+ ".class);";
|
122 |
|
|
else if (ObjectImpl.class.isAssignableFrom(c))
|
123 |
|
|
return "in.read_Object();";
|
124 |
|
|
else
|
125 |
|
|
return "(" + r.name(c)
|
126 |
|
|
+ ") in.read_value(" + r.name(c) + ".class);";
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
}
|