AttributeGen.java revision 608:7e06bf1dcb09
1/* 2 * Copyright (c) 1999, 2002, 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 40import java.io.PrintWriter; 41import java.util.Enumeration; 42import java.util.Hashtable; 43 44import com.sun.tools.corba.se.idl.AttributeEntry; 45import com.sun.tools.corba.se.idl.InterfaceEntry; 46import com.sun.tools.corba.se.idl.MethodEntry; 47import com.sun.tools.corba.se.idl.ParameterEntry; 48import com.sun.tools.corba.se.idl.SymtabEntry; 49 50/** 51 * 52 **/ 53public class AttributeGen extends MethodGen implements com.sun.tools.corba.se.idl.AttributeGen 54{ 55 /** 56 * Public zero-argument constructor. 57 **/ 58 public AttributeGen () 59 { 60 } // ctor 61 62 /** 63 * 64 **/ 65 private boolean unique (InterfaceEntry entry, String name) 66 { 67 // Compare the name to the methods of this interface 68 Enumeration methods = entry.methods ().elements (); 69 while (methods.hasMoreElements ()) 70 { 71 SymtabEntry method = (SymtabEntry)methods.nextElement (); 72 if (name.equals (method.name ())) 73 return false; 74 } 75 76 // Recursively call unique on each derivedFrom interface 77 Enumeration derivedFrom = entry.derivedFrom ().elements (); 78 while (derivedFrom.hasMoreElements ()) 79 if (!unique ((InterfaceEntry)derivedFrom.nextElement (), name)) 80 return false; 81 82 // If the name isn't in any method, nor in any method of the 83 // derivedFrom interfaces, then the name is unique. 84 return true; 85 } // unique 86 87 /** 88 * Method generate() is not used in MethodGen. They are replaced by the 89 * more granular interfaceMethod, stub, skeleton, dispatchSkeleton. 90 **/ 91 public void generate (Hashtable symbolTable, AttributeEntry m, PrintWriter stream) 92 { 93 } // generate 94 95 /** 96 * 97 **/ 98 protected void interfaceMethod (Hashtable symbolTable, MethodEntry m, PrintWriter stream) 99 { 100 AttributeEntry a = (AttributeEntry)m; 101 102 // Generate for the get method 103 super.interfaceMethod (symbolTable, a, stream); 104 105 // Generate for the set method if the attribute is not readonly 106 if (!a.readOnly ()) 107 { 108 setupForSetMethod (); 109 super.interfaceMethod (symbolTable, a, stream); 110 clear (); 111 } 112 } // interfaceMethod 113 114 /** 115 * 116 **/ 117 protected void stub (String className, boolean isAbstract, Hashtable symbolTable, MethodEntry m, PrintWriter stream, int index) 118 { 119 AttributeEntry a = (AttributeEntry)m; 120 121 // Generate for the get method 122 super.stub (className, isAbstract, symbolTable, a, stream, index); 123 124 // Generate for the set method if the attribute is not readonly 125 if (!a.readOnly ()) 126 { 127 setupForSetMethod (); 128 super.stub (className, isAbstract, symbolTable, a, stream, index + 1); 129 clear (); 130 } 131 } // stub 132 133 /** 134 * 135 **/ 136 protected void skeleton (Hashtable symbolTable, MethodEntry m, PrintWriter stream, int index) 137 { 138 AttributeEntry a = (AttributeEntry)m; 139 140 // Generate for the get method 141 super.skeleton (symbolTable, a, stream, index); 142 143 // Generate for the set method if the attribute is not readonly 144 if (!a.readOnly ()) 145 { 146 setupForSetMethod (); 147 super.skeleton (symbolTable, a, stream, index + 1); 148 clear (); 149 } 150 } // skeleton 151 152 /** 153 * 154 **/ 155 protected void dispatchSkeleton (Hashtable symbolTable, MethodEntry m, PrintWriter stream, int index) 156 { 157 AttributeEntry a = (AttributeEntry)m; 158 159 // Generate for the get method 160 super.dispatchSkeleton (symbolTable, a, stream, index); 161 162 // Generate for the set method if the attribute is not readonly 163 if (!a.readOnly ()) 164 { 165 setupForSetMethod (); 166 super.dispatchSkeleton (symbolTable, m, stream, index + 1); 167 clear (); 168 } 169 } // dispatchSkeleton 170 171 private SymtabEntry realType = null; 172 173 /** 174 * 175 **/ 176 protected void setupForSetMethod () 177 { 178 ParameterEntry parm = Compile.compiler.factory.parameterEntry (); 179 parm.type (m.type ()); 180 parm.name ("new" + Util.capitalize (m.name ())); 181 m.parameters ().addElement (parm); 182 realType = m.type (); 183 m.type (null); 184 } // setupForSetMethod 185 186 /** 187 * 188 **/ 189 protected void clear () 190 { 191 // Set back to normal 192 m.parameters ().removeAllElements (); 193 m.type (realType); 194 } // clear 195} // class AttributeGen 196