001: /*
002: * Copyright 1999-2002 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: /*
026: * COMPONENT_NAME: idl.toJava
027: *
028: * ORIGINS: 27
029: *
030: * Licensed Materials - Property of IBM
031: * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
032: * RMI-IIOP v1.0
033: *
034: * @(#)AttributeGen.java 1.22 07/05/05
035: */
036:
037: package com.sun.tools.corba.se.idl.toJavaPortable;
038:
039: // NOTES:
040:
041: import java.io.PrintWriter;
042: import java.util.Enumeration;
043: import java.util.Hashtable;
044:
045: import com.sun.tools.corba.se.idl.AttributeEntry;
046: import com.sun.tools.corba.se.idl.InterfaceEntry;
047: import com.sun.tools.corba.se.idl.MethodEntry;
048: import com.sun.tools.corba.se.idl.ParameterEntry;
049: import com.sun.tools.corba.se.idl.SymtabEntry;
050:
051: /**
052: *
053: **/
054: public class AttributeGen extends MethodGen implements
055: com.sun.tools.corba.se.idl.AttributeGen {
056: /**
057: * Public zero-argument constructor.
058: **/
059: public AttributeGen() {
060: } // ctor
061:
062: /**
063: *
064: **/
065: private boolean unique(InterfaceEntry entry, String name) {
066: // Compare the name to the methods of this interface
067: Enumeration methods = entry.methods().elements();
068: while (methods.hasMoreElements()) {
069: SymtabEntry method = (SymtabEntry) methods.nextElement();
070: if (name.equals(method.name()))
071: return false;
072: }
073:
074: // Recursively call unique on each derivedFrom interface
075: Enumeration derivedFrom = entry.derivedFrom().elements();
076: while (derivedFrom.hasMoreElements())
077: if (!unique((InterfaceEntry) derivedFrom.nextElement(),
078: name))
079: return false;
080:
081: // If the name isn't in any method, nor in any method of the
082: // derivedFrom interfaces, then the name is unique.
083: return true;
084: } // unique
085:
086: /**
087: * Method generate() is not used in MethodGen. They are replaced by the
088: * more granular interfaceMethod, stub, skeleton, dispatchSkeleton.
089: **/
090: public void generate(Hashtable symbolTable, AttributeEntry m,
091: PrintWriter stream) {
092: } // generate
093:
094: /**
095: *
096: **/
097: protected void interfaceMethod(Hashtable symbolTable,
098: MethodEntry m, PrintWriter stream) {
099: AttributeEntry a = (AttributeEntry) m;
100:
101: // Generate for the get method
102: super .interfaceMethod(symbolTable, a, stream);
103:
104: // Generate for the set method if the attribute is not readonly
105: if (!a.readOnly()) {
106: setupForSetMethod();
107: super .interfaceMethod(symbolTable, a, stream);
108: clear();
109: }
110: } // interfaceMethod
111:
112: /**
113: *
114: **/
115: protected void stub(String className, boolean isAbstract,
116: Hashtable symbolTable, MethodEntry m, PrintWriter stream,
117: int index) {
118: AttributeEntry a = (AttributeEntry) m;
119:
120: // Generate for the get method
121: super
122: .stub(className, isAbstract, symbolTable, a, stream,
123: index);
124:
125: // Generate for the set method if the attribute is not readonly
126: if (!a.readOnly()) {
127: setupForSetMethod();
128: super .stub(className, isAbstract, symbolTable, a, stream,
129: index + 1);
130: clear();
131: }
132: } // stub
133:
134: /**
135: *
136: **/
137: protected void skeleton(Hashtable symbolTable, MethodEntry m,
138: PrintWriter stream, int index) {
139: AttributeEntry a = (AttributeEntry) m;
140:
141: // Generate for the get method
142: super .skeleton(symbolTable, a, stream, index);
143:
144: // Generate for the set method if the attribute is not readonly
145: if (!a.readOnly()) {
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,
156: MethodEntry m, PrintWriter stream, int index) {
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: setupForSetMethod();
165: super .dispatchSkeleton(symbolTable, m, stream, index + 1);
166: clear();
167: }
168: } // dispatchSkeleton
169:
170: private SymtabEntry realType = null;
171:
172: /**
173: *
174: **/
175: protected void setupForSetMethod() {
176: ParameterEntry parm = Compile.compiler.factory.parameterEntry();
177: parm.type(m.type());
178: parm.name("new" + Util.capitalize(m.name()));
179: m.parameters().addElement(parm);
180: realType = m.type();
181: m.type(null);
182: } // setupForSetMethod
183:
184: /**
185: *
186: **/
187: protected void clear() {
188: // Set back to normal
189: m.parameters().removeAllElements();
190: m.type(realType);
191: } // clear
192: } // class AttributeGen
|