001: /*
002: * Copyright 1999 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: * @(#)ValueFactory.java 1.18 07/05/05
035: */
036:
037: package com.sun.tools.corba.se.idl.toJavaPortable;
038:
039: // NOTES:
040: // -D62023 klr new class
041:
042: import java.io.PrintWriter;
043: import java.util.Vector;
044:
045: import com.sun.tools.corba.se.idl.GenFileStream;
046: import com.sun.tools.corba.se.idl.SymtabEntry;
047: import com.sun.tools.corba.se.idl.MethodEntry;
048: import com.sun.tools.corba.se.idl.ValueEntry;
049:
050: /**
051: *
052: **/
053: public class ValueFactory implements AuxGen {
054: /**
055: * Public zero-argument constructor.
056: **/
057: public ValueFactory() {
058: } // ctor
059:
060: /**
061: * Generate the default value factory class. Provides general algorithm for
062: * auxiliary binding generation:
063: * 1.) Initialize symbol table and symbol table entry members,
064: * common to all generators.
065: * 2.) Initialize members unique to this generator.
066: * 3.) Open print stream
067: * 4.) Write class heading (package, prologue, source comment, class
068: * statement, open curly
069: * 5.) Write class body (member data and methods)
070: * 6.) Write class closing (close curly)
071: * 7.) Close the print stream
072: **/
073: public void generate(java.util.Hashtable symbolTable,
074: com.sun.tools.corba.se.idl.SymtabEntry entry) {
075: this .symbolTable = symbolTable;
076: this .entry = entry;
077: init();
078: if (hasFactoryMethods()) {
079: openStream();
080: if (stream == null)
081: return;
082: writeHeading();
083: writeBody();
084: writeClosing();
085: closeStream();
086: }
087: } // generate
088:
089: /**
090: * Initialize variables unique to this generator.
091: **/
092: protected void init() {
093: factoryClass = entry.name() + "ValueFactory";
094: factoryType = Util.javaName(entry);
095: } // init
096:
097: /**
098: * @return true if entry has any factory methods declared
099: **/
100: protected boolean hasFactoryMethods() {
101: Vector init = ((ValueEntry) entry).initializers();
102: if (init != null && init.size() > 0)
103: return true;
104: else
105: return false;
106: } // hasFactoryMethods
107:
108: /**
109: * Open the print stream for subsequent output.
110: **/
111: protected void openStream() {
112: stream = Util.stream(entry, "ValueFactory.java");
113: } // openStream
114:
115: /**
116: * Generate the heading, including the package, imports,
117: * source comment, class statement, and left curly.
118: **/
119: protected void writeHeading() {
120: Util.writePackage(stream, entry, Util.TypeFile); // REVISIT - same as interface?
121: Util.writeProlog(stream, stream.name());
122: if (entry.comment() != null)
123: entry.comment().generate("", stream);
124: stream.println("public interface " + factoryClass
125: + " extends org.omg.CORBA.portable.ValueFactory");
126: stream.println('{');
127: } // writeHeading
128:
129: /**
130: * Generate members of this class.
131: **/
132: protected void writeBody() {
133: Vector init = ((ValueEntry) entry).initializers();
134: if (init != null) {
135: for (int i = 0; i < init.size(); i++) {
136: MethodEntry element = (MethodEntry) init.elementAt(i);
137: element.valueMethod(true); //tag value method if not tagged previously
138: ((MethodGen) element.generator()).interfaceMethod(
139: symbolTable, element, stream);
140: }
141: }
142: } // writeBody
143:
144: /**
145: * Generate the closing statements.
146: **/
147: protected void writeClosing() {
148: stream.println('}');
149: } // writeClosing
150:
151: /**
152: * Write the stream to file by closing the print stream.
153: **/
154: protected void closeStream() {
155: stream.close();
156: } // closeStream
157:
158: protected java.util.Hashtable symbolTable;
159: protected com.sun.tools.corba.se.idl.SymtabEntry entry;
160: protected GenFileStream stream;
161:
162: // Unique to this generator
163: protected String factoryClass;
164: protected String factoryType;
165: } // class Holder
|