ValueBoxGen24.java revision 672:2bb058ce572e
181634Sbrian/* 281634Sbrian * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. 381634Sbrian * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 481634Sbrian * 581634Sbrian * This code is free software; you can redistribute it and/or modify it 681634Sbrian * under the terms of the GNU General Public License version 2 only, as 781634Sbrian * published by the Free Software Foundation. Oracle designates this 881634Sbrian * particular file as subject to the "Classpath" exception as provided 981634Sbrian * by Oracle in the LICENSE file that accompanied this code. 1081634Sbrian * 1181634Sbrian * This code is distributed in the hope that it will be useful, but WITHOUT 1281634Sbrian * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1381634Sbrian * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1481634Sbrian * version 2 for more details (a copy is included in the LICENSE file that 1581634Sbrian * accompanied this code). 1681634Sbrian * 1781634Sbrian * You should have received a copy of the GNU General Public License version 1881634Sbrian * 2 along with this work; if not, write to the Free Software Foundation, 1981634Sbrian * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2081634Sbrian * 2181634Sbrian * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2281634Sbrian * or visit www.oracle.com if you need additional information or have any 2381634Sbrian * questions. 2481634Sbrian */ 2581634Sbrian/* 2681634Sbrian * COMPONENT_NAME: idl.toJava 2781634Sbrian * 2881634Sbrian * ORIGINS: 27 2981634Sbrian * 3081634Sbrian * Licensed Materials - Property of IBM 3181634Sbrian * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999 3281634Sbrian * RMI-IIOP v1.0 3381634Sbrian * 3481634Sbrian */ 3581634Sbrian 3681634Sbrianpackage com.sun.tools.corba.se.idl.toJavaPortable; 3781634Sbrian 3881634Sbrian// NOTES: 3981634Sbrian// -D62023 <klr> Update for Java 2.4 RTF 4081634Sbrian 4181634Sbrianimport java.io.File; 4281634Sbrianimport java.io.PrintWriter; 4381634Sbrianimport java.util.Hashtable; 4481634Sbrianimport java.util.Enumeration; 4581634Sbrianimport java.util.Vector; 4681634Sbrian 4781634Sbrianimport com.sun.tools.corba.se.idl.GenFileStream; 4881634Sbrianimport com.sun.tools.corba.se.idl.InterfaceEntry; 4981634Sbrianimport com.sun.tools.corba.se.idl.SymtabEntry; 5081634Sbrianimport com.sun.tools.corba.se.idl.TypedefEntry; 5181634Sbrianimport com.sun.tools.corba.se.idl.ValueEntry; 5281634Sbrianimport com.sun.tools.corba.se.idl.ValueBoxEntry; 5381634Sbrianimport com.sun.tools.corba.se.idl.InterfaceState; 5481634Sbrianimport com.sun.tools.corba.se.idl.MethodEntry; 5581634Sbrianimport com.sun.tools.corba.se.idl.PrimitiveEntry; 5681634Sbrianimport com.sun.tools.corba.se.idl.SequenceEntry; 5781634Sbrianimport com.sun.tools.corba.se.idl.StringEntry; 5881634Sbrian 5981634Sbrian/** 6081634Sbrian * 6181634Sbrian **/ 6281634Sbrianpublic class ValueBoxGen24 extends ValueBoxGen 6381634Sbrian{ 6481634Sbrian /** 6581634Sbrian * Public zero-argument constructor. 6681634Sbrian **/ 6781634Sbrian public ValueBoxGen24 () 6881634Sbrian { 6981634Sbrian } // ctor 7081634Sbrian 7181634Sbrian /** 7281634Sbrian * d62023 - Move from helper to mapped class 7381634Sbrian **/ 7481634Sbrian protected void writeTruncatable () // <d60929> 7581634Sbrian { 7681634Sbrian stream.print (" private static String[] _truncatable_ids = {"); 7781634Sbrian stream.println (Util.helperName(v, true) + ".id ()};"); 7881634Sbrian stream.println (); 7981634Sbrian stream.println (" public String[] _truncatable_ids() {"); 8081634Sbrian stream.println (" return _truncatable_ids;"); 8181634Sbrian 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