001: /*
002: * Copyright 1999-2000 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: * @(#)StringGen.java 1.21 07/05/05
035: */
036:
037: package com.sun.tools.corba.se.idl.toJavaPortable;
038:
039: // NOTES:
040: // -D61056 <klr> Use Util.helperName
041:
042: import java.io.PrintWriter;
043: import java.util.Hashtable;
044:
045: import com.sun.tools.corba.se.idl.StringEntry;
046: import com.sun.tools.corba.se.idl.SymtabEntry;
047:
048: /**
049: * Handles generation of CORBA strings as well as wstrings. Be careful
050: * not to forget the wstrings.
051: **/
052: public class StringGen implements com.sun.tools.corba.se.idl.StringGen,
053: JavaGenerator {
054: /**
055: * Public zero-argument constructor.
056: **/
057: public StringGen() {
058: } // ctor
059:
060: /**
061: * This should never be called. This class exists for the
062: * JavaGenerator interface.
063: **/
064: public void generate(Hashtable symbolTable, StringEntry e,
065: PrintWriter stream) {
066: } // generate
067:
068: ///////////////
069: // From JavaGenerator
070:
071: public int helperType(int index, String indent,
072: TCOffsets tcoffsets, String name, SymtabEntry entry,
073: PrintWriter stream) {
074: return type(index, indent, tcoffsets, name, entry, stream);
075: } // helperType
076:
077: public int type(int index, String indent, TCOffsets tcoffsets,
078: String name, SymtabEntry entry, PrintWriter stream) {
079: tcoffsets.set(entry);
080: StringEntry stringEntry = (StringEntry) entry;
081: String bound;
082: if (stringEntry.maxSize() == null)
083: bound = "0";
084: else
085: bound = Util.parseExpression(stringEntry.maxSize());
086:
087: // entry.name() is necessary to determine whether it is a
088: // string or wstring
089:
090: stream.println(indent + name
091: + " = org.omg.CORBA.ORB.init ().create_" + entry.name()
092: + "_tc (" + bound + ");");
093: return index;
094: } // type
095:
096: public void helperRead(String entryName, SymtabEntry entry,
097: PrintWriter stream) {
098: } // helperRead
099:
100: public void helperWrite(SymtabEntry entry, PrintWriter stream) {
101: } // helperWrite
102:
103: public int read(int index, String indent, String name,
104: SymtabEntry entry, PrintWriter stream) {
105: StringEntry string = (StringEntry) entry;
106: String entryName = entry.name();
107: if (entryName.equals("string"))
108: stream
109: .println(indent + name
110: + " = istream.read_string ();");
111: else if (entryName.equals("wstring"))
112: stream.println(indent + name
113: + " = istream.read_wstring ();");
114: if (string.maxSize() != null) {
115: stream.println(indent + "if (" + name + ".length () > ("
116: + Util.parseExpression(string.maxSize()) + "))");
117: stream
118: .println(indent
119: + " throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);");
120: }
121: return index;
122: } // read
123:
124: public int write(int index, String indent, String name,
125: SymtabEntry entry, PrintWriter stream) {
126: StringEntry string = (StringEntry) entry;
127: if (string.maxSize() != null) {
128: stream.print(indent + "if (" + name + ".length () > ("
129: + Util.parseExpression(string.maxSize()) + "))");
130: stream
131: .println(indent
132: + " throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);");
133: }
134: String entryName = entry.name();
135: if (entryName.equals("string"))
136: stream.println(indent + "ostream.write_string (" + name
137: + ");");
138: else if (entryName.equals("wstring"))
139: stream.println(indent + "ostream.write_wstring (" + name
140: + ");");
141: return index;
142: } // write
143:
144: // From JavaGenerator
145: ///////////////
146: } // class StringGen
|