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