1 /* GiopIo.java -- Generates GIOP input/output statements.
2 Copyright (C) 2006 Free Software Foundation
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
22 package gnu.classpath.tools.giop.grmic;
24 import java.rmi.Remote;
26 import org.omg.CORBA.portable.ObjectImpl;
29 * Generates the code for reading and writing data over GIOP stream.
31 * @author Audrius Meskauskas, Lithuania (audriusa@Bioinformatics.org)
36 * Get the statement for writing the variable of the given type to the GIOP ({@link org.omg.CORBA_2_3.portable.OutputStream) stream. The
37 * stream is always named "out".
40 * the class of the object being written
42 * the variable, where the object value is stored
44 * the parent generator, used to name the class
45 * @return the write statement.
47 public static String getWriteStatement(Class c, String variable, GiopRmicCompiler r)
49 if (c.equals(boolean.class))
50 return "out.write_boolean(" + variable + ");";
51 if (c.equals(byte.class))
52 return "out.write_octet(" + variable + ");";
53 else if (c.equals(short.class))
54 return "out.write_int(" + variable + ");";
55 else if (c.equals(int.class))
56 return "out.write_long(" + variable + ");";
57 else if (c.equals(long.class))
58 return "out.write_long_long(" + variable + ");";
59 else if (c.equals(double.class))
60 return "out.write_double(" + variable + ");";
61 else if (c.equals(float.class))
62 return "out.write_float(" + variable + ");";
63 else if (c.equals(char.class))
64 return "out.write_char(" + variable + ");";
65 else if (Remote.class.isAssignableFrom(c))
66 return "Util.writeRemoteObject(out, " + variable + ");";
67 else if (ObjectImpl.class.isAssignableFrom(c))
68 return "out.write_Object(" + variable + ");";
70 return "out.write_value(" + variable + ", " + r.name(c) + ".class);";
74 * 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
75 * stream is always named "in".
78 * the class of the object being written
80 * the parent generator, used to name the class
81 * @return the right side of the read statement.
83 public static String getReadStatement(Class c, GiopRmicCompiler r)
85 if (c.equals(boolean.class))
86 return "in.read_boolean();";
87 else if (c.equals(byte.class))
88 return "in.read_octet();";
89 else if (c.equals(short.class))
90 return "in.read_int();";
91 else if (c.equals(int.class))
92 return "in.read_long();";
93 else if (c.equals(long.class))
94 return "in.read_long_long();";
95 else if (c.equals(double.class))
96 return "in.read_double();";
97 else if (c.equals(float.class))
98 return "in.read_float();";
99 else if (c.equals(char.class))
100 return "in.read_char();";
101 else if (Remote.class.isAssignableFrom(c))
102 return "(" + r.name(c)
103 + ") PortableRemoteObject.narrow(in.read_Object()," + r.name(c)
105 else if (ObjectImpl.class.isAssignableFrom(c))
106 return "in.read_Object();";
108 return "(" + r.name(c)
109 + ") in.read_value(" + r.name(c) + ".class);";