ValueBoxGen24.java revision 673:6b017d166ac2
1/*
2 * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25/*
26 * COMPONENT_NAME: idl.toJava
27 *
28 * ORIGINS: 27
29 *
30 * Licensed Materials - Property of IBM
31 * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
32 * RMI-IIOP v1.0
33 *
34 */
35
36package com.sun.tools.corba.se.idl.toJavaPortable;
37
38// NOTES:
39// -D62023  <klr> Update for Java 2.4 RTF
40
41import java.io.File;
42import java.io.PrintWriter;
43import java.util.Hashtable;
44import java.util.Enumeration;
45import java.util.Vector;
46
47import com.sun.tools.corba.se.idl.GenFileStream;
48import com.sun.tools.corba.se.idl.InterfaceEntry;
49import com.sun.tools.corba.se.idl.SymtabEntry;
50import com.sun.tools.corba.se.idl.TypedefEntry;
51import com.sun.tools.corba.se.idl.ValueEntry;
52import com.sun.tools.corba.se.idl.ValueBoxEntry;
53import com.sun.tools.corba.se.idl.InterfaceState;
54import com.sun.tools.corba.se.idl.MethodEntry;
55import com.sun.tools.corba.se.idl.PrimitiveEntry;
56import com.sun.tools.corba.se.idl.SequenceEntry;
57import com.sun.tools.corba.se.idl.StringEntry;
58
59/**
60 *
61 **/
62public class ValueBoxGen24 extends ValueBoxGen
63{
64  /**
65   * Public zero-argument constructor.
66   **/
67  public ValueBoxGen24 ()
68  {
69  } // ctor
70
71  /**
72   * d62023 - Move from helper to mapped class
73   **/
74  protected void writeTruncatable () // <d60929>
75  {
76      stream.print   ("  private static String[] _truncatable_ids = {");
77      stream.println (Util.helperName(v, true) + ".id ()};");
78      stream.println ();
79      stream.println ("  public String[] _truncatable_ids() {");
80      stream.println ("    return _truncatable_ids;");
81      stream.println ("  }");
82      stream.println ();
83  } // writeTruncatable
84
85
86  /**
87   * d62023
88   **/
89  public void helperRead (String entryName, SymtabEntry entry, PrintWriter stream)
90  {
91    stream.println ("    if (!(istream instanceof org.omg.CORBA_2_3.portable.InputStream)) {");
92    stream.println ("      throw new org.omg.CORBA.BAD_PARAM(); }");
93    stream.println ("    return (" + entryName +") ((org.omg.CORBA_2_3.portable.InputStream) istream).read_value (_instance);");
94    stream.println ("  }");
95    stream.println ();
96
97    // done with "read", now do "read_value with real marshalling code.
98
99    stream.println ("  public java.io.Serializable read_value (org.omg.CORBA.portable.InputStream istream)"); // <d60929>
100    stream.println ("  {");
101
102    String indent = "    ";
103    Vector vMembers = ((ValueBoxEntry) entry).state ();
104    TypedefEntry member = ((InterfaceState) vMembers.elementAt (0)).entry;
105    SymtabEntry mType = member.type ();
106    if (mType instanceof PrimitiveEntry ||
107        mType instanceof SequenceEntry ||
108        mType instanceof TypedefEntry ||
109        mType instanceof StringEntry ||
110        !member.arrayInfo ().isEmpty ()) {
111      stream.println (indent + Util.javaName (mType) + " tmp;");
112      ((JavaGenerator)member.generator ()).read (0, indent, "tmp", member, stream);
113    }
114    else
115      stream.println (indent + Util.javaName (mType) + " tmp = " +
116                      Util.helperName ( mType, true ) + ".read (istream);");
117    if (mType instanceof PrimitiveEntry)
118      stream.println (indent + "return new " + entryName + " (tmp);");
119    else
120      stream.println (indent + "return (java.io.Serializable) tmp;");
121  } // helperRead
122
123  /**
124   * d62023
125   **/
126  public void helperWrite (SymtabEntry entry, PrintWriter stream)
127  {
128    stream.println ("    if (!(ostream instanceof org.omg.CORBA_2_3.portable.OutputStream)) {");
129    stream.println ("      throw new org.omg.CORBA.BAD_PARAM(); }");
130    stream.println ("    ((org.omg.CORBA_2_3.portable.OutputStream) ostream).write_value (value, _instance);");
131    stream.println ("  }");
132    stream.println ();
133
134    // done with "write", now do "write_value with real marshalling code.
135
136    stream.println ("  public void write_value (org.omg.CORBA.portable.OutputStream ostream, java.io.Serializable value)");
137    stream.println ("  {");
138
139    String entryName = Util.javaName(entry);
140    stream.println ("    if (!(value instanceof " + entryName + ")) {");
141    stream.println ("      throw new org.omg.CORBA.MARSHAL(); }");
142    stream.println ("    " + entryName + " valueType = (" + entryName + ") value;");
143    write (0, "    ", "valueType", entry, stream);
144  } // helperWrite
145
146  /**
147   * d62023
148   **/
149  public int write (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
150  {
151    Vector vMembers = ( (ValueEntry) entry ).state ();
152    TypedefEntry member = ((InterfaceState) vMembers.elementAt (0)).entry;
153    SymtabEntry mType = member.type ();
154
155    if (mType instanceof PrimitiveEntry || !member.arrayInfo ().isEmpty ())
156      index = ((JavaGenerator)member.generator ()).write (index, indent, name + ".value", member, stream);
157    else if (mType instanceof SequenceEntry || mType instanceof StringEntry || mType instanceof TypedefEntry || !member.arrayInfo ().isEmpty ())
158      index = ((JavaGenerator)member.generator ()).write (index, indent, name, member, stream);
159    else
160      stream.println (indent + Util.helperName (mType, true) + ".write (ostream, " + name + ");"); // <d61056>
161    return index;
162  } // write
163}
164