ValueBoxGen24.java revision 608:7e06bf1dcb09
1193323Sed/* 2193323Sed * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. 3193323Sed * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4193323Sed * 5193323Sed * This code is free software; you can redistribute it and/or modify it 6193323Sed * under the terms of the GNU General Public License version 2 only, as 7193323Sed * published by the Free Software Foundation. Oracle designates this 8193323Sed * particular file as subject to the "Classpath" exception as provided 9193323Sed * by Oracle in the LICENSE file that accompanied this code. 10193323Sed * 11193323Sed * This code is distributed in the hope that it will be useful, but WITHOUT 12193323Sed * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13193323Sed * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14193323Sed * version 2 for more details (a copy is included in the LICENSE file that 15193323Sed * accompanied this code). 16193323Sed * 17193323Sed * You should have received a copy of the GNU General Public License version 18193323Sed * 2 along with this work; if not, write to the Free Software Foundation, 19193323Sed * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20193323Sed * 21193323Sed * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22193323Sed * or visit www.oracle.com if you need additional information or have any 23193323Sed * questions. 24193323Sed */ 25193323Sed/* 26193323Sed * COMPONENT_NAME: idl.toJava 27193323Sed * 28193323Sed * ORIGINS: 27 29193323Sed * 30193323Sed * Licensed Materials - Property of IBM 31193323Sed * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999 32193323Sed * RMI-IIOP v1.0 33193323Sed * 34249423Sdim */ 35249423Sdim 36234353Sdimpackage com.sun.tools.corba.se.idl.toJavaPortable; 37251662Sdim 38234353Sdim// NOTES: 39200581Srdivacky// -D62023 <klr> Update for Java 2.4 RTF 40193323Sed 41234353Sdimimport java.io.File; 42193323Sedimport java.io.PrintWriter; 43263508Sdimimport java.util.Hashtable; 44234353Sdimimport java.util.Enumeration; 45193323Sedimport java.util.Vector; 46193323Sed 47193323Sedimport com.sun.tools.corba.se.idl.GenFileStream; 48249423Sdimimport com.sun.tools.corba.se.idl.InterfaceEntry; 49218893Sdimimport com.sun.tools.corba.se.idl.SymtabEntry; 50218893Sdimimport com.sun.tools.corba.se.idl.TypedefEntry; 51193323Sedimport com.sun.tools.corba.se.idl.ValueEntry; 52249423Sdimimport com.sun.tools.corba.se.idl.ValueBoxEntry; 53249423Sdimimport com.sun.tools.corba.se.idl.InterfaceState; 54193323Sedimport com.sun.tools.corba.se.idl.MethodEntry; 55198090Srdivackyimport com.sun.tools.corba.se.idl.PrimitiveEntry; 56193323Sedimport com.sun.tools.corba.se.idl.SequenceEntry; 57193323Sedimport com.sun.tools.corba.se.idl.StringEntry; 58193323Sed 59193323Sed/** 60193323Sed * 61234353Sdim **/ 62193323Sedpublic class ValueBoxGen24 extends ValueBoxGen 63193323Sed{ 64193323Sed /** 65193323Sed * Public zero-argument constructor. 66193323Sed **/ 67204642Srdivacky public ValueBoxGen24 () 68218893Sdim { 69193323Sed } // ctor 70198090Srdivacky 71198090Srdivacky /** 72203954Srdivacky * <d62023> - Move from helper to mapped class 73203954Srdivacky **/ 74198090Srdivacky protected void writeTruncatable () // <d60929> 75234353Sdim { 76212904Sdim stream.print (" private static String[] _truncatable_ids = {"); 77234353Sdim stream.println (Util.helperName(v, true) + ".id ()};"); 78234353Sdim stream.println (); 79234353Sdim stream.println (" public String[] _truncatable_ids() {"); 80234353Sdim stream.println (" return _truncatable_ids;"); 81212904Sdim stream.println (" }"); 82193323Sed stream.println (); 83193323Sed } // writeTruncatable 84218893Sdim 85218893Sdim 86218893Sdim /** 87218893Sdim * <d62023> 88218893Sdim **/ 89218893Sdim public void helperRead (String entryName, SymtabEntry entry, PrintWriter stream) 90193323Sed { 91218893Sdim stream.println (" if (!(istream instanceof org.omg.CORBA_2_3.portable.InputStream)) {"); 92193323Sed stream.println (" throw new org.omg.CORBA.BAD_PARAM(); }"); 93218893Sdim stream.println (" return (" + entryName +") ((org.omg.CORBA_2_3.portable.InputStream) istream).read_value (_instance);"); 94251662Sdim stream.println (" }"); 95251662Sdim stream.println (); 96218893Sdim 97218893Sdim // done with "read", now do "read_value with real marshalling code. 98218893Sdim 99218893Sdim stream.println (" public java.io.Serializable read_value (org.omg.CORBA.portable.InputStream istream)"); // <d60929> 100218893Sdim stream.println (" {"); 101193323Sed 102218893Sdim String indent = " "; 103218893Sdim Vector vMembers = ((ValueBoxEntry) entry).state (); 104218893Sdim TypedefEntry member = ((InterfaceState) vMembers.elementAt (0)).entry; 105218893Sdim SymtabEntry mType = member.type (); 106193323Sed if (mType instanceof PrimitiveEntry || 107218893Sdim mType instanceof SequenceEntry || 108218893Sdim mType instanceof TypedefEntry || 109193323Sed mType instanceof StringEntry || 110218893Sdim !member.arrayInfo ().isEmpty ()) { 111218893Sdim stream.println (indent + Util.javaName (mType) + " tmp;"); 112193323Sed ((JavaGenerator)member.generator ()).read (0, indent, "tmp", member, stream); 113218893Sdim } 114212904Sdim else 115218893Sdim stream.println (indent + Util.javaName (mType) + " tmp = " + 116218893Sdim Util.helperName ( mType, true ) + ".read (istream);"); 117218893Sdim if (mType instanceof PrimitiveEntry) 118218893Sdim stream.println (indent + "return new " + entryName + " (tmp);"); 119218893Sdim else 120218893Sdim stream.println (indent + "return (java.io.Serializable) tmp;"); 121218893Sdim } // helperRead 122212904Sdim 123193323Sed /** 124251662Sdim * <d62023> 125193323Sed **/ 126224145Sdim public void helperWrite (SymtabEntry entry, PrintWriter stream) 127224145Sdim { 128218893Sdim stream.println (" if (!(ostream instanceof org.omg.CORBA_2_3.portable.OutputStream)) {"); 129218893Sdim stream.println (" throw new org.omg.CORBA.BAD_PARAM(); }"); 130218893Sdim stream.println (" ((org.omg.CORBA_2_3.portable.OutputStream) ostream).write_value (value, _instance);"); 131218893Sdim stream.println (" }"); 132218893Sdim stream.println (); 133263508Sdim 134203954Srdivacky // done with "write", now do "write_value with real marshalling code. 135251662Sdim 136218893Sdim stream.println (" public void write_value (org.omg.CORBA.portable.OutputStream ostream, java.io.Serializable value)"); 137218893Sdim stream.println (" {"); 138218893Sdim 139193323Sed String entryName = Util.javaName(entry); 140218893Sdim stream.println (" if (!(value instanceof " + entryName + ")) {"); 141193323Sed stream.println (" throw new org.omg.CORBA.MARSHAL(); }"); 142218893Sdim stream.println (" " + entryName + " valueType = (" + entryName + ") value;"); 143218893Sdim write (0, " ", "valueType", entry, stream); 144193323Sed } // helperWrite 145218893Sdim 146218893Sdim /** 147218893Sdim * <d62023> 148218893Sdim **/ 149193323Sed public int write (int index, String indent, String name, SymtabEntry entry, PrintWriter stream) 150218893Sdim { 151218893Sdim Vector vMembers = ( (ValueEntry) entry ).state (); 152218893Sdim TypedefEntry member = ((InterfaceState) vMembers.elementAt (0)).entry; 153193323Sed SymtabEntry mType = member.type (); 154218893Sdim 155193323Sed if (mType instanceof PrimitiveEntry || !member.arrayInfo ().isEmpty ()) 156218893Sdim index = ((JavaGenerator)member.generator ()).write (index, indent, name + ".value", member, stream); 157193323Sed else if (mType instanceof SequenceEntry || mType instanceof StringEntry || mType instanceof TypedefEntry || !member.arrayInfo ().isEmpty ()) 158218893Sdim index = ((JavaGenerator)member.generator ()).write (index, indent, name, member, stream); 159193323Sed else 160263508Sdim stream.println (indent + Util.helperName (mType, true) + ".write (ostream, " + name + ");"); // <d61056> 161218893Sdim return index; 162218893Sdim } // write 163218893Sdim} 164218893Sdim