Helper24.java revision 672:2bb058ce572e
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 file to implement CORBA 2.4 RTF 40 41import java.io.PrintWriter; 42 43import java.util.Enumeration; 44import java.util.Vector; 45 46import com.sun.tools.corba.se.idl.GenFileStream; 47import com.sun.tools.corba.se.idl.InterfaceEntry; 48import com.sun.tools.corba.se.idl.MethodEntry; 49import com.sun.tools.corba.se.idl.ParameterEntry; 50import com.sun.tools.corba.se.idl.SymtabEntry; 51import com.sun.tools.corba.se.idl.ValueEntry; 52import com.sun.tools.corba.se.idl.ValueBoxEntry; 53import com.sun.tools.corba.se.idl.TypedefEntry; 54import com.sun.tools.corba.se.idl.InterfaceState; 55import com.sun.tools.corba.se.idl.PrimitiveEntry; 56import com.sun.tools.corba.se.idl.StructEntry; 57 58/** 59 * 60 **/ 61public class Helper24 extends Helper 62{ 63 /** 64 * Public zero-argument constructor. 65 **/ 66 public Helper24 () 67 { 68 } // ctor 69 70 /** 71 * Generate the heading, including package, imports, class statements, 72 * and open curly. 73 * d62023 - don't implement ValueHelper, make non-boxed helpers abstract 74 **/ 75 protected void writeHeading () 76 { 77 Util.writePackage (stream, entry, Util.HelperFile); 78 Util.writeProlog (stream, stream.name ()); 79 80 // Transfer comment to target <30jul1997daz>. 81 if (entry.comment () != null) 82 entry.comment ().generate ("", stream); 83 84 if (entry instanceof ValueBoxEntry) { 85 stream.print ("public final class " + helperClass); 86 stream.println (" implements org.omg.CORBA.portable.BoxedValueHelper"); 87 } 88 else 89 stream.println ("abstract public class " + helperClass); 90 stream.println ('{'); 91 } 92 93 /** 94 * Generate the instance variables. 95 * <pre> 96 * d62023 - no helper instance except for boxed valuetypes; 97 * - move truncatable_ids to mapped class. 98 * </pre> 99 **/ 100 protected void writeInstVars () 101 { 102 stream.println (" private static String _id = \"" + Util.stripLeadingUnderscoresFromID (entry.repositoryID ().ID ()) + "\";"); 103 if (entry instanceof ValueEntry) 104 { 105 stream.println (); 106 if (entry instanceof ValueBoxEntry) { 107 stream.println (" private static " + helperClass + " _instance = new " + helperClass + " ();"); 108 stream.println (); 109 } 110 } 111 stream.println (); 112 } // writeInstVars 113 114 /** 115 * d62023 - generate members of BoxedValueHelper interface if boxed 116 * 117 * d62023 - hook in here to write factory methods for non-boxed ValueTypes 118 * into Helper. 119 **/ 120 protected void writeValueHelperInterface () 121 { 122 if (entry instanceof ValueBoxEntry) { 123 writeGetID (); 124 } else if (entry instanceof ValueEntry) { 125 writeHelperFactories (); 126 } 127 } // writeValueHelperInterface 128 129 /** 130 * 131 **/ 132 protected void writeHelperFactories () 133 { 134 Vector init = ((ValueEntry)entry).initializers (); 135 if (init != null) 136 { 137 stream.println (); 138 for (int i = 0; i < init.size (); i++) 139 { 140 MethodEntry element = (MethodEntry) init.elementAt (i); 141 element.valueMethod (true); //tag value method if not tagged previously 142 ((MethodGen24) element.generator ()). helperFactoryMethod (symbolTable, element, entry, stream); 143 } 144 } 145 } // writeHelperFactories 146 147 /** 148 * d62023 - generate constructors only for boxed valuetype helpers. 149 * All other helpers are abstract. 150 **/ 151 protected void writeCtors () 152 { 153 if (entry instanceof ValueBoxEntry) { 154 stream.println (" public " + helperClass + "()"); 155 stream.println (" {"); 156 stream.println (" }"); 157 stream.println (); 158 } 159 } // writeCtors 160} 161