ValueFactory.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// -D62023 klr new class
40
41import java.io.PrintWriter;
42import java.util.Vector;
43
44import com.sun.tools.corba.se.idl.GenFileStream;
45import com.sun.tools.corba.se.idl.SymtabEntry;
46import com.sun.tools.corba.se.idl.MethodEntry;
47import com.sun.tools.corba.se.idl.ValueEntry;
48
49/**
50 *
51 **/
52public class ValueFactory implements AuxGen
53{
54  /**
55   * Public zero-argument constructor.
56   **/
57  public ValueFactory ()
58  {
59  } // ctor
60
61  /**
62   * Generate the default value factory class. Provides general algorithm for
63   * auxiliary binding generation:
64   * 1.) Initialize symbol table and symbol table entry members,
65   *     common to all generators.
66   * 2.) Initialize members unique to this generator.
67   * 3.) Open print stream
68   * 4.) Write class heading (package, prologue, source comment, class
69   *     statement, open curly
70   * 5.) Write class body (member data and methods)
71   * 6.) Write class closing (close curly)
72   * 7.) Close the print stream
73   **/
74  public void generate (java.util.Hashtable symbolTable, com.sun.tools.corba.se.idl.SymtabEntry entry)
75  {
76    this.symbolTable = symbolTable;
77    this.entry       = entry;
78    init ();
79    if (hasFactoryMethods ()) {
80        openStream ();
81        if (stream == null)
82          return;
83        writeHeading ();
84        writeBody ();
85        writeClosing ();
86        closeStream ();
87    }
88  } // generate
89
90  /**
91   * Initialize variables unique to this generator.
92   **/
93  protected void init ()
94  {
95    factoryClass = entry.name () + "ValueFactory";
96    factoryType = Util.javaName (entry);
97  } // init
98
99  /**
100   * @return true if entry has any factory methods declared
101   **/
102  protected boolean hasFactoryMethods ()
103  {
104    Vector init = ((ValueEntry)entry).initializers ();
105    if (init != null && init.size () > 0)
106      return true;
107    else
108      return false;
109  } // hasFactoryMethods
110
111  /**
112   * Open the print stream for subsequent output.
113   **/
114  protected void openStream ()
115  {
116    stream = Util.stream (entry, "ValueFactory.java");
117  } // openStream
118
119  /**
120   * Generate the heading, including the package, imports,
121   * source comment, class statement, and left curly.
122   **/
123  protected void writeHeading ()
124  {
125    Util.writePackage (stream, entry, Util.TypeFile); // REVISIT - same as interface?
126    Util.writeProlog (stream, stream.name ());
127    if (entry.comment () != null)
128      entry.comment ().generate ("", stream);
129    stream.println ("public interface " + factoryClass + " extends org.omg.CORBA.portable.ValueFactory");
130    stream.println ('{');
131  } // writeHeading
132
133  /**
134   * Generate members of this class.
135   **/
136  protected void writeBody ()
137  {
138    Vector init = ((ValueEntry)entry).initializers ();
139    if (init != null)
140    {
141      for (int i = 0; i < init.size (); i++)
142      {
143        MethodEntry element = (MethodEntry) init.elementAt (i);
144        element.valueMethod (true); //tag value method if not tagged previously
145        ((MethodGen) element.generator ()). interfaceMethod (symbolTable, element, stream);
146      }
147    }
148  } // writeBody
149
150  /**
151   * Generate the closing statements.
152   **/
153  protected void writeClosing ()
154  {
155    stream.println ('}');
156  } // writeClosing
157
158  /**
159   * Write the stream to file by closing the print stream.
160   **/
161  protected void closeStream ()
162  {
163    stream.close ();
164  } // closeStream
165
166  protected java.util.Hashtable     symbolTable;
167  protected com.sun.tools.corba.se.idl.SymtabEntry entry;
168  protected GenFileStream           stream;
169
170  // Unique to this generator
171  protected String factoryClass;
172  protected String factoryType;
173} // class Holder
174