src/share/classes/com/sun/tools/corba/se/idl/toJavaPortable/StringGen.java

Sun, 05 Dec 2010 22:22:54 -0800

author
skoppar
date
Sun, 05 Dec 2010 22:22:54 -0800
changeset 236
33ca1bceec2d
parent 158
91006f157c46
child 748
6845b95cba6b
permissions
-rw-r--r--

7004713: regression: cannot find symbol: variable delegate failed compile _Stub
Summary: Also reviewed by ken.cavanaugh@oracle.com
Reviewed-by: asaha

duke@1 1 /*
ohair@158 2 * Copyright (c) 1999, 2000, Oracle and/or its affiliates. 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
ohair@158 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@158 9 * by Oracle 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 *
ohair@158 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@158 22 * or visit www.oracle.com if you need additional information or have any
ohair@158 23 * 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 // -D61056 <klr> Use Util.helperName
duke@1 40
duke@1 41 import java.io.PrintWriter;
duke@1 42 import java.util.Hashtable;
duke@1 43
duke@1 44 import com.sun.tools.corba.se.idl.StringEntry;
duke@1 45 import com.sun.tools.corba.se.idl.SymtabEntry;
duke@1 46
duke@1 47 /**
duke@1 48 * Handles generation of CORBA strings as well as wstrings. Be careful
duke@1 49 * not to forget the wstrings.
duke@1 50 **/
duke@1 51 public class StringGen implements com.sun.tools.corba.se.idl.StringGen, JavaGenerator
duke@1 52 {
duke@1 53 /**
duke@1 54 * Public zero-argument constructor.
duke@1 55 **/
duke@1 56 public StringGen ()
duke@1 57 {
duke@1 58 } // ctor
duke@1 59
duke@1 60 /**
duke@1 61 * This should never be called. This class exists for the
duke@1 62 * JavaGenerator interface.
duke@1 63 **/
duke@1 64 public void generate (Hashtable symbolTable, StringEntry e, PrintWriter stream)
duke@1 65 {
duke@1 66 } // generate
duke@1 67
duke@1 68 ///////////////
duke@1 69 // From JavaGenerator
duke@1 70
duke@1 71 public int helperType (int index, String indent, TCOffsets tcoffsets, String name, SymtabEntry entry, PrintWriter stream)
duke@1 72 {
duke@1 73 return type(index, indent, tcoffsets, name, entry, stream);
duke@1 74 } // helperType
duke@1 75
duke@1 76 public int type (int index, String indent, TCOffsets tcoffsets, String name, SymtabEntry entry, PrintWriter stream) {
duke@1 77 tcoffsets.set (entry);
duke@1 78 StringEntry stringEntry = (StringEntry)entry;
duke@1 79 String bound;
duke@1 80 if (stringEntry.maxSize () == null)
duke@1 81 bound = "0";
duke@1 82 else
duke@1 83 bound = Util.parseExpression (stringEntry.maxSize ());
duke@1 84
duke@1 85 // entry.name() is necessary to determine whether it is a
duke@1 86 // string or wstring
duke@1 87
duke@1 88 stream.println (indent
duke@1 89 + name
duke@1 90 + " = org.omg.CORBA.ORB.init ().create_"
duke@1 91 + entry.name()
duke@1 92 + "_tc ("
duke@1 93 + bound + ");");
duke@1 94 return index;
duke@1 95 } // type
duke@1 96
duke@1 97 public void helperRead (String entryName, SymtabEntry entry, PrintWriter stream)
duke@1 98 {
duke@1 99 } // helperRead
duke@1 100
duke@1 101 public void helperWrite (SymtabEntry entry, PrintWriter stream)
duke@1 102 {
duke@1 103 } // helperWrite
duke@1 104
duke@1 105 public int read (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
duke@1 106 {
duke@1 107 StringEntry string = (StringEntry)entry;
duke@1 108 String entryName = entry.name ();
duke@1 109 if (entryName.equals ("string"))
duke@1 110 stream.println (indent + name + " = istream.read_string ();");
duke@1 111 else if (entryName.equals ("wstring"))
duke@1 112 stream.println (indent + name + " = istream.read_wstring ();");
duke@1 113 if (string.maxSize () != null)
duke@1 114 {
duke@1 115 stream.println (indent + "if (" + name + ".length () > (" + Util.parseExpression (string.maxSize ()) + "))");
duke@1 116 stream.println (indent + " throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);");
duke@1 117 }
duke@1 118 return index;
duke@1 119 } // read
duke@1 120
duke@1 121 public int write (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
duke@1 122 {
duke@1 123 StringEntry string = (StringEntry)entry;
duke@1 124 if (string.maxSize () != null)
duke@1 125 {
duke@1 126 stream.print (indent + "if (" + name + ".length () > (" + Util.parseExpression (string.maxSize ()) + "))");
duke@1 127 stream.println (indent + " throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);");
duke@1 128 }
duke@1 129 String entryName = entry.name ();
duke@1 130 if (entryName.equals ("string"))
duke@1 131 stream.println (indent + "ostream.write_string (" + name + ");");
duke@1 132 else if (entryName.equals ("wstring"))
duke@1 133 stream.println (indent + "ostream.write_wstring (" + name + ");");
duke@1 134 return index;
duke@1 135 } // write
duke@1 136
duke@1 137 // From JavaGenerator
duke@1 138 ///////////////
duke@1 139 } // class StringGen

mercurial