ForwardValueGen.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25/*
26 * COMPONENT_NAME: idl.toJava
27 *
28 * ORIGINS: 27
29 *
30 * Licensed Materials - Property of IBM
31 * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
32 * RMI-IIOP v1.0
33 *
34 */
35
36package com.sun.tools.corba.se.idl.toJavaPortable;
37
38// NOTES:
39// -D61056   <klr> Use Util.helperName
40
41import java.io.File;
42import java.io.PrintWriter;
43import java.util.Hashtable;
44import java.util.Enumeration;
45import java.util.Vector;
46
47import com.sun.tools.corba.se.idl.GenFileStream;
48import com.sun.tools.corba.se.idl.InterfaceEntry;
49import com.sun.tools.corba.se.idl.SymtabEntry;
50import com.sun.tools.corba.se.idl.TypedefEntry;
51import com.sun.tools.corba.se.idl.ForwardValueEntry;
52import com.sun.tools.corba.se.idl.InterfaceState;
53import com.sun.tools.corba.se.idl.MethodEntry;
54
55/**
56 *
57 **/
58public class ForwardValueGen implements com.sun.tools.corba.se.idl.ForwardValueGen, JavaGenerator
59{
60  /**
61   * Public zero-argument constructor.
62   **/
63  public ForwardValueGen ()
64  {
65  } // ctor
66
67  /**
68   *
69   **/
70  public void generate (Hashtable symbolTable, ForwardValueEntry v, PrintWriter str)
71  {
72    this.symbolTable = symbolTable;
73    this.v = v;
74
75    openStream ();
76    if (stream == null)
77      return;
78    generateHelper ();
79    generateHolder ();
80    generateStub ();
81    writeHeading ();
82    writeBody ();
83    writeClosing ();
84    closeStream ();
85  } // generate
86
87  /**
88   *
89   **/
90  protected void openStream ()
91  {
92    stream = Util.stream (v, ".java");
93  } // openStream
94
95  /**
96   *
97   **/
98  protected void generateHelper ()
99  {
100    ((Factories)Compile.compiler.factories ()).helper ().generate (symbolTable, v);
101  } // generateHelper
102
103  /**
104   *
105   **/
106  protected void generateHolder ()
107  {
108    ((Factories)Compile.compiler.factories ()).holder ().generate (symbolTable, v);
109  } // generateHolder
110
111  /**
112   *
113   **/
114  protected void generateStub ()
115  {
116  } // generateStub
117
118  /**
119   *
120   **/
121  protected void writeHeading ()
122  {
123    Util.writePackage (stream, v);
124    Util.writeProlog (stream, ((GenFileStream)stream).name ());
125
126    if (v.comment () != null)
127      v.comment ().generate ("", stream);
128
129    stream.print ("public class " + v.name () + " implements org.omg.CORBA.portable.IDLEntity");
130      // There should ALWAYS be at least one:  ValueBase
131
132    stream.println ("{");
133  } // writeHeading
134
135  /**
136   *
137   **/
138  protected void writeBody ()
139  {
140  } // writeBody
141
142  /**
143   *
144   **/
145  protected void writeClosing ()
146  {
147   stream.println ("} // class " + v.name ());
148  } // writeClosing
149
150  /**
151   *
152   **/
153  protected void closeStream ()
154  {
155    stream.close ();
156  } // closeStream
157
158  ///////////////
159  // From JavaGenerator
160
161  public int helperType (int index, String indent, TCOffsets tcoffsets, String name, SymtabEntry entry, PrintWriter stream)
162  {
163    return index;
164  } // helperType
165
166  public int type (int index, String indent, TCOffsets tcoffsets, String name, SymtabEntry entry, PrintWriter stream) {
167    stream.println (indent + name + " = " + Util.helperName (entry, true) + ".type ();"); // <d61056>
168    return index;
169  } // type
170
171  public void helperRead (String entryName, SymtabEntry entry, PrintWriter stream)
172  {
173    stream.println ("    " + entryName + " value = new " + entryName + " ();");
174    read (0, "    ", "value", entry, stream);
175    stream.println ("    return value;");
176  } // helperRead
177
178  public int read (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
179  {
180    return index;
181  } // read
182
183  public void helperWrite (SymtabEntry entry, PrintWriter stream)
184  {
185    write (0, "    ", "value", entry, stream);
186  } // helperWrite
187
188  public int write (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
189  {
190    return index;
191  } // write
192
193  // From JavaGenerator
194  ///////////////
195
196  /**
197   *
198   **/
199  protected void writeAbstract ()
200  {
201  } // writeAbstract
202
203  protected Hashtable  symbolTable = null;
204  protected ForwardValueEntry v = null;
205  protected PrintWriter stream = null;
206} // class ForwardValueGen
207