001: /*
002: * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: /*
026: * COMPONENT_NAME: idl.toJava
027: *
028: * ORIGINS: 27
029: *
030: * Licensed Materials - Property of IBM
031: * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
032: * RMI-IIOP v1.0
033: *
034: * @(#)ValueBoxGen24.java 1.18 07/05/05
035: */
036:
037: package com.sun.tools.corba.se.idl.toJavaPortable;
038:
039: // NOTES:
040: // -D62023 <klr> Update for Java 2.4 RTF
041:
042: import java.io.File;
043: import java.io.PrintWriter;
044: import java.util.Hashtable;
045: import java.util.Enumeration;
046: import java.util.Vector;
047:
048: import com.sun.tools.corba.se.idl.GenFileStream;
049: import com.sun.tools.corba.se.idl.InterfaceEntry;
050: import com.sun.tools.corba.se.idl.SymtabEntry;
051: import com.sun.tools.corba.se.idl.TypedefEntry;
052: import com.sun.tools.corba.se.idl.ValueEntry;
053: import com.sun.tools.corba.se.idl.ValueBoxEntry;
054: import com.sun.tools.corba.se.idl.InterfaceState;
055: import com.sun.tools.corba.se.idl.MethodEntry;
056: import com.sun.tools.corba.se.idl.PrimitiveEntry;
057: import com.sun.tools.corba.se.idl.SequenceEntry;
058: import com.sun.tools.corba.se.idl.StringEntry;
059:
060: /**
061: *
062: **/
063: public class ValueBoxGen24 extends ValueBoxGen {
064: /**
065: * Public zero-argument constructor.
066: **/
067: public ValueBoxGen24() {
068: } // ctor
069:
070: /**
071: * <d62023> - Move from helper to mapped class
072: **/
073: protected void writeTruncatable() // <d60929>
074: {
075: stream.print(" private static String[] _truncatable_ids = {");
076: stream.println(Util.helperName(v, true) + ".id ()};");
077: stream.println();
078: stream.println(" public String[] _truncatable_ids() {");
079: stream.println(" return _truncatable_ids;");
080: stream.println(" }");
081: stream.println();
082: } // writeTruncatable
083:
084: /**
085: * <d62023>
086: **/
087: public void helperRead(String entryName, SymtabEntry entry,
088: PrintWriter stream) {
089: stream
090: .println(" if (!(istream instanceof org.omg.CORBA_2_3.portable.InputStream)) {");
091: stream.println(" throw new org.omg.CORBA.BAD_PARAM(); }");
092: stream
093: .println(" return ("
094: + entryName
095: + ") ((org.omg.CORBA_2_3.portable.InputStream) istream).read_value (_instance);");
096: stream.println(" }");
097: stream.println();
098:
099: // done with "read", now do "read_value with real marshalling code.
100:
101: stream
102: .println(" public java.io.Serializable read_value (org.omg.CORBA.portable.InputStream istream)"); // <d60929>
103: stream.println(" {");
104:
105: String indent = " ";
106: Vector vMembers = ((ValueBoxEntry) entry).state();
107: TypedefEntry member = ((InterfaceState) vMembers.elementAt(0)).entry;
108: SymtabEntry mType = member.type();
109: if (mType instanceof PrimitiveEntry
110: || mType instanceof SequenceEntry
111: || mType instanceof TypedefEntry
112: || mType instanceof StringEntry
113: || !member.arrayInfo().isEmpty()) {
114: stream.println(indent + Util.javaName(mType) + " tmp;");
115: ((JavaGenerator) member.generator()).read(0, indent, "tmp",
116: member, stream);
117: } else
118: stream
119: .println(indent + Util.javaName(mType) + " tmp = "
120: + Util.helperName(mType, true)
121: + ".read (istream);");
122: if (mType instanceof PrimitiveEntry)
123: stream.println(indent + "return new " + entryName
124: + " (tmp);");
125: else
126: stream.println(indent
127: + "return (java.io.Serializable) tmp;");
128: } // helperRead
129:
130: /**
131: * <d62023>
132: **/
133: public void helperWrite(SymtabEntry entry, PrintWriter stream) {
134: stream
135: .println(" if (!(ostream instanceof org.omg.CORBA_2_3.portable.OutputStream)) {");
136: stream.println(" throw new org.omg.CORBA.BAD_PARAM(); }");
137: stream
138: .println(" ((org.omg.CORBA_2_3.portable.OutputStream) ostream).write_value (value, _instance);");
139: stream.println(" }");
140: stream.println();
141:
142: // done with "write", now do "write_value with real marshalling code.
143:
144: stream
145: .println(" public void write_value (org.omg.CORBA.portable.OutputStream ostream, java.io.Serializable value)");
146: stream.println(" {");
147:
148: String entryName = Util.javaName(entry);
149: stream.println(" if (!(value instanceof " + entryName
150: + ")) {");
151: stream.println(" throw new org.omg.CORBA.MARSHAL(); }");
152: stream.println(" " + entryName + " valueType = ("
153: + entryName + ") value;");
154: write(0, " ", "valueType", entry, stream);
155: } // helperWrite
156:
157: /**
158: * <d62023>
159: **/
160: public int write(int index, String indent, String name,
161: SymtabEntry entry, PrintWriter stream) {
162: Vector vMembers = ((ValueEntry) entry).state();
163: TypedefEntry member = ((InterfaceState) vMembers.elementAt(0)).entry;
164: SymtabEntry mType = member.type();
165:
166: if (mType instanceof PrimitiveEntry
167: || !member.arrayInfo().isEmpty())
168: index = ((JavaGenerator) member.generator()).write(index,
169: indent, name + ".value", member, stream);
170: else if (mType instanceof SequenceEntry
171: || mType instanceof StringEntry
172: || mType instanceof TypedefEntry
173: || !member.arrayInfo().isEmpty())
174: index = ((JavaGenerator) member.generator()).write(index,
175: indent, name, member, stream);
176: else
177: stream.println(indent + Util.helperName(mType, true)
178: + ".write (ostream, " + name + ");"); // <d61056>
179: return index;
180: } // write
181: }
|