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

mercurial