001: /*
002: * Copyright 1999-2001 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: * @(#)ValueGen.java 1.21 07/05/05
035: */
036:
037: package com.sun.tools.corba.se.idl.toJavaPortable;
038:
039: // NOTES:
040: // -F46082.51<daz> Remove -stateful feature; javaStatefulName() obsolete.
041: // -D57067 <klr> suppress default init if an emit init explicitly specified.
042: // -D59071 <daz> Clone method entries when their content needs modification.
043: // -D59092 <klr> Valuetype supporting interfaces should implement interface.
044: // -D59418 <klr> Custom values implement org.omg.CORBA.CustomMarshal
045: // -D59418 <klr> Invert read/read_Value, write/write_Value for Simon
046: // -D60929 <klr> Update for RTF2.4 changes
047: // -D62018 <klr> write_value for value with value field x calls xHelper.write.
048: // -D62062 <klr> Add _write to value Helper to marshal state.
049: // write_value for value subclass calls parent._write
050: // -D61650<daz> Remove '\n' from generated strings; use println()'s.
051:
052: import java.io.File;
053: import java.io.PrintWriter;
054: import java.util.Hashtable;
055: import java.util.Enumeration;
056: import java.util.Vector;
057:
058: import com.sun.tools.corba.se.idl.GenFileStream;
059: import com.sun.tools.corba.se.idl.InterfaceEntry;
060: import com.sun.tools.corba.se.idl.SymtabEntry;
061: import com.sun.tools.corba.se.idl.TypedefEntry;
062: import com.sun.tools.corba.se.idl.ValueEntry;
063: import com.sun.tools.corba.se.idl.ValueBoxEntry;
064: import com.sun.tools.corba.se.idl.InterfaceState;
065: import com.sun.tools.corba.se.idl.MethodEntry;
066: import com.sun.tools.corba.se.idl.PrimitiveEntry;
067: import com.sun.tools.corba.se.idl.SequenceEntry;
068: import com.sun.tools.corba.se.idl.StringEntry;
069: import com.sun.tools.corba.se.idl.StructEntry;
070:
071: /**
072: *
073: **/
074: public class ValueGen implements com.sun.tools.corba.se.idl.ValueGen,
075: JavaGenerator {
076: /**
077: * Public zero-argument constructor.
078: **/
079: public ValueGen() {
080: } // ctor
081:
082: /**
083: *
084: **/
085: public void generate(Hashtable symbolTable, ValueEntry v,
086: PrintWriter str) {
087: this .symbolTable = symbolTable;
088: this .v = v;
089: init();
090:
091: openStream();
092: if (stream == null)
093: return;
094: generateTie();
095: generateHelper();
096: generateHolder();
097: writeHeading();
098: writeBody();
099: writeClosing();
100: closeStream();
101: } // generate
102:
103: /**
104: * Initialize members unique to this generator.
105: **/
106: protected void init() {
107: emit = ((Arguments) Compile.compiler.arguments).emit;
108: factories = (Factories) Compile.compiler.factories();
109: } // init
110:
111: /**
112: *
113: **/
114: protected void openStream() {
115: stream = Util.stream(v, ".java");
116: } // openStream
117:
118: /**
119: * Generate a Tie class only when the user specifies the TIE option
120: * and the valuetype does support an interface.
121: **/
122: protected void generateTie() {
123: boolean tie = ((Arguments) Compile.compiler.arguments).TIEServer;
124: if (v.supports().size() > 0 && tie) {
125: Factories factories = (Factories) Compile.compiler
126: .factories();
127: factories.skeleton().generate(symbolTable, v);
128: }
129: } // generateTie
130:
131: /**
132: *
133: **/
134: protected void generateHelper() {
135: ((Factories) Compile.compiler.factories()).helper().generate(
136: symbolTable, v);
137: } // generateHelper
138:
139: /**
140: *
141: **/
142: protected void generateHolder() {
143: ((Factories) Compile.compiler.factories()).holder().generate(
144: symbolTable, v);
145: } // generateHolder
146:
147: /**
148: *
149: **/
150: protected void writeHeading() {
151: Util.writePackage(stream, v);
152: Util.writeProlog(stream, ((GenFileStream) stream).name());
153:
154: if (v.comment() != null)
155: v.comment().generate("", stream);
156:
157: if (v.isAbstract()) {
158: writeAbstract();
159: return;
160: } else
161: stream.print("public class " + v.name());
162:
163: // There should always be at least one parent: ValueBase
164: SymtabEntry parent = (SymtabEntry) v.derivedFrom().elementAt(0);
165:
166: // If parent is ValueBase, it's mapped to java.io.Serializable
167: String parentName = Util.javaName(parent);
168: boolean impl = false;
169:
170: if (parentName.equals("java.io.Serializable")) {
171: // stream.print (" implements org.omg.CORBA.portable.ValueBase, org.omg.CORBA.portable.Streamable");
172: stream
173: .print(" implements org.omg.CORBA.portable.ValueBase"); // <d60929>
174: impl = true;
175: } else if (!((ValueEntry) parent).isAbstract())
176: stream.print(" extends " + parentName);
177:
178: // if inheriting from abstract values
179: for (int i = 0; i < v.derivedFrom().size(); i++) {
180: parent = (SymtabEntry) v.derivedFrom().elementAt(i);
181: if (((ValueEntry) parent).isAbstract()) {
182: if (!impl) {
183: stream.print(" implements ");
184: impl = true;
185: } else
186: stream.print(", ");
187: stream.print(Util.javaName(parent));
188: }
189: }
190: // <d59092-klr> Valuetype supporting interface implement Operations interface
191: // for supported IDL interface
192: if (((ValueEntry) v).supports().size() > 0) {
193: if (!impl) {
194: stream.print(" implements ");
195: impl = true;
196: } else
197: stream.print(", ");
198:
199: InterfaceEntry s = (InterfaceEntry) ((ValueEntry) v)
200: .supports().elementAt(0);
201: // abstract supported classes don't have "Operations"
202: if (s.isAbstract())
203: stream.print(Util.javaName(s));
204: else
205: stream.print(Util.javaName(s) + "Operations");
206: }
207:
208: // <d59418> Custom valuetypes implement org.omg.CORBA.CustomMarshal.
209: if (((ValueEntry) v).isCustom()) {
210: if (!impl) {
211: stream.print(" implements ");
212: impl = true;
213: } else
214: stream.print(", ");
215:
216: stream.print("org.omg.CORBA.CustomMarshal ");
217: }
218:
219: stream.println();
220: stream.println("{");
221: } // writeHeading
222:
223: /**
224: *
225: **/
226: protected void writeBody() {
227: writeMembers();
228: writeInitializers();
229: writeConstructor(); // <d57067>
230: writeTruncatable(); // <d60929>
231: writeMethods();
232: } // writeBody
233:
234: /**
235: *
236: **/
237: protected void writeClosing() {
238: if (v.isAbstract())
239: stream.println("} // interface " + v.name());
240: else
241: stream.println("} // class " + v.name());
242: } // writeClosing
243:
244: /**
245: *
246: **/
247: protected void closeStream() {
248: stream.close();
249: } // closeStream
250:
251: /**
252: *
253: **/
254: protected void writeConstructor() {
255: // Per Simon, 9/3/98, emit a protected default constructor
256: if (!v.isAbstract() && !explicitDefaultInit) { // <d57067 - klr>
257: stream.println(" protected " + v.name() + " () {}");
258: stream.println();
259: }
260: } // writeConstructor
261:
262: /**
263: *
264: **/
265: protected void writeTruncatable() // <d60929>
266: {
267: // Per Simon, 4/6/98, emit _truncatable_ids()
268: if (!v.isAbstract()) {
269: stream.println(" public String[] _truncatable_ids() {");
270: stream.println(" return " + Util.helperName(v, true)
271: + ".get_instance().get_truncatable_base_ids();"); // <d61056>
272: stream.println(" }");
273: stream.println();
274: }
275: } // writeTruncatable
276:
277: /**
278: *
279: **/
280: protected void writeMembers() {
281: // if the value type contains no data members, a null return is expected
282: if (v.state() == null)
283: return;
284:
285: for (int i = 0; i < v.state().size(); i++) {
286: InterfaceState member = (InterfaceState) v.state()
287: .elementAt(i);
288: SymtabEntry entry = (SymtabEntry) member.entry;
289: Util.fillInfo(entry);
290:
291: if (entry.comment() != null)
292: entry.comment().generate(" ", stream);
293:
294: String modifier = " ";
295: if (member.modifier == InterfaceState.Public)
296: modifier = " public ";
297: Util.writeInitializer(modifier, entry.name(), "", entry,
298: stream);
299: }
300: } // writeMembers
301:
302: /**
303: *
304: **/
305: protected void writeInitializers() {
306: Vector init = v.initializers();
307: if (init != null) {
308: stream.println();
309: for (int i = 0; i < init.size(); i++) {
310: MethodEntry element = (MethodEntry) init.elementAt(i);
311: element.valueMethod(true);
312: ((MethodGen) element.generator()).interfaceMethod(
313: symbolTable, element, stream);
314: if (element.parameters().isEmpty()) // <d57067-klr>
315: explicitDefaultInit = true;
316: }
317: }
318: } // writeInitializers
319:
320: /**
321: *
322: **/
323: protected void writeMethods() {
324: // contained vector contains methods, attributes, const, enums, exceptions,
325: // structs, unions, or typedefs that are declared inside the value object.
326: // State members of the nested types are also included in this vector.
327: // Thus, if the declaration of a constructed type is nested in the decl.
328: // of a state member, e.g struct x {boolean b;} memberx;
329: // the generation of the nested type must be handled here.
330: Enumeration e = v.contained().elements();
331: while (e.hasMoreElements()) {
332: SymtabEntry contained = (SymtabEntry) e.nextElement();
333: if (contained instanceof MethodEntry) {
334: MethodEntry element = (MethodEntry) contained;
335: ((MethodGen) element.generator()).interfaceMethod(
336: symbolTable, element, stream);
337: } else {
338: // Generate the type referenced by the typedef.
339: if (contained instanceof TypedefEntry)
340: contained.type().generate(symbolTable, stream);
341:
342: // Note that we also need to generate the typedef itself if
343: // contained is a typedef.
344: contained.generate(symbolTable, stream);
345: }
346: }
347:
348: // Abstract values are mapped to interfaces. There is no need to generate
349: // the bindings for inheriting methods in case of inheritance from other
350: // abstract values or supporting interface
351: if (v.isAbstract())
352: return;
353:
354: // workaround: if the value type doesnot support any interfaces, a null
355: // return is expected instead of an empty vector
356:
357: // if supporting an interfaces, generate bindings for inheriting methods
358: if (v.supports().size() > 0) {
359: InterfaceEntry intf = (InterfaceEntry) v.supports()
360: .elementAt(0);
361: Enumeration el = intf.allMethods().elements();
362: while (el.hasMoreElements()) {
363: MethodEntry m = (MethodEntry) el.nextElement();
364: // <d59071> Don't alter the symbol table/emit list elements!
365: //m.container (v);
366: //((MethodGen)m.generator ()).interfaceMethod (symbolTable, m, stream);
367: MethodEntry mClone = (MethodEntry) m.clone();
368: mClone.container(v);
369: ((MethodGen) mClone.generator()).interfaceMethod(
370: symbolTable, mClone, stream);
371: }
372: }
373:
374: // if inheriting from abstract values, generating bindings for all
375: // inheriting methods
376: for (int i = 0; i < v.derivedFrom().size(); i++) {
377: ValueEntry parentValue = (ValueEntry) v.derivedFrom()
378: .elementAt(i);
379: if (parentValue.isAbstract()) {
380: Enumeration el = parentValue.allMethods().elements();
381: while (el.hasMoreElements()) {
382: MethodEntry m = (MethodEntry) el.nextElement();
383: // <d59071> Don't alter the symbol table/emit list elements!
384: //m.container (v);
385: //((MethodGen)m.generator ()).interfaceMethod (symbolTable, m, stream);
386: MethodEntry mClone = (MethodEntry) m.clone();
387: mClone.container(v);
388: ((MethodGen) mClone.generator()).interfaceMethod(
389: symbolTable, mClone, stream);
390: }
391: }
392: }
393:
394: //writeStreamableMethods ();
395: } // writeMethods
396:
397: /**
398: *
399: **/
400: protected void writeStreamableMethods() {
401: stream
402: .println(" public void _read (org.omg.CORBA.portable.InputStream istream)");
403: stream.println(" {");
404: read(0, " ", "this", v, stream);
405: stream.println(" }");
406: stream.println();
407: stream
408: .println(" public void _write (org.omg.CORBA.portable.OutputStream ostream)");
409: stream.println(" {");
410: write(0, " ", "this", v, stream);
411: stream.println(" }");
412: stream.println();
413: stream.println(" public org.omg.CORBA.TypeCode _type ()");
414: stream.println(" {");
415: stream.println(" return " + Util.helperName(v, false)
416: + ".type ();"); // <d61056>
417: stream.println(" }");
418: } // writeStreamableMethods
419:
420: ///////////////
421: // From JavaGenerator
422:
423: public int helperType(int index, String indent,
424: TCOffsets tcoffsets, String name, SymtabEntry entry,
425: PrintWriter stream) {
426: ValueEntry vt = (ValueEntry) entry;
427: Vector state = vt.state();
428: int noOfMembers = state == null ? 0 : state.size();
429: String members = "_members" + index++;
430: String tcOfMembers = "_tcOf" + members;
431:
432: stream.println(indent + "org.omg.CORBA.ValueMember[] "
433: + members + " = new org.omg.CORBA.ValueMember["
434: + noOfMembers + "];");
435: stream.println(indent + "org.omg.CORBA.TypeCode " + tcOfMembers
436: + " = null;");
437: //stream.println (""); // <d61650>
438:
439: String definedInrepId = "_id";
440: String repId, version;
441:
442: for (int k = 0; k < noOfMembers; k++) {
443: InterfaceState valueMember = (InterfaceState) state
444: .elementAt(k);
445: TypedefEntry member = (TypedefEntry) valueMember.entry;
446: SymtabEntry mType = Util.typeOf(member);
447: if (hasRepId(member)) {
448: repId = Util.helperName(mType, true) + ".id ()"; // <d61056>
449: if (mType instanceof ValueEntry
450: || mType instanceof ValueBoxEntry)
451: // OBV spec is silent on defining VersionSpec for valuetype RepIds
452: version = "\"\"";
453: else {
454: String id = mType.repositoryID().ID();
455: version = '"' + id
456: .substring(id.lastIndexOf(':') + 1) + '"';
457: }
458: } else {
459: repId = "\"\"";
460: version = "\"\"";
461: }
462:
463: // Get TypeCode for valuetype member and store it var. name given by tcOfMembers
464: stream.println(indent + "// ValueMember instance for "
465: + member.name());
466: index = ((JavaGenerator) member.generator()).type(index,
467: indent, tcoffsets, tcOfMembers, member, stream);
468: stream.println(indent + members + "[" + k
469: + "] = new org.omg.CORBA.ValueMember (" // <d61650>
470: + '"' + member.name() + "\", "); // name
471: stream.println(indent + " " + repId + ", "); // id
472: stream.println(indent + " " + definedInrepId + ", "); // defined_in
473: stream.println(indent + " " + version + ", "); // version
474: stream.println(indent + " " + tcOfMembers + ", "); // type
475: stream.println(indent + " " + "null, "); // type_def
476: stream
477: .println(indent
478: + " "
479: + "org.omg.CORBA."
480: + (valueMember.modifier == InterfaceState.Public ? "PUBLIC_MEMBER"
481: : "PRIVATE_MEMBER") + ".value"
482: + ");"); // access
483: } // end for
484:
485: stream.println(indent + name
486: + " = org.omg.CORBA.ORB.init ().create_value_tc ("
487: + "_id, " + '"' + entry.name() + "\", "
488: + getValueModifier(vt) + ", "
489: + getConcreteBaseTypeCode(vt) + ", " + members + ");");
490:
491: return index;
492: } // helperType
493:
494: public int type(int index, String indent, TCOffsets tcoffsets,
495: String name, SymtabEntry entry, PrintWriter stream) {
496: stream.println(indent + name + " = "
497: + Util.helperName(entry, true) + ".type ();"); // <d61056>
498: return index;
499: } // type
500:
501: // Check for types which don't have a Repository ID: primitive,
502: // string, arrays and sequences.
503:
504: private static boolean hasRepId(SymtabEntry member) {
505: SymtabEntry mType = Util.typeOf(member);
506: return !(mType instanceof PrimitiveEntry
507: || mType instanceof StringEntry
508: || (mType instanceof TypedefEntry && !(((TypedefEntry) mType)
509: .arrayInfo().isEmpty())) || (mType instanceof TypedefEntry && member
510: .type() instanceof SequenceEntry));
511: } // hasRepId
512:
513: private static String getValueModifier(ValueEntry vt) {
514: String mod = "NONE";
515: if (vt.isCustom())
516: mod = "CUSTOM";
517: else if (vt.isAbstract())
518: mod = "ABSTRACT";
519: else if (vt.isSafe())
520: mod = "TRUNCATABLE";
521: return "org.omg.CORBA.VM_" + mod + ".value";
522: } // getValueModifier
523:
524: private static String getConcreteBaseTypeCode(ValueEntry vt) {
525: Vector v = vt.derivedFrom();
526: if (!vt.isAbstract()) {
527: SymtabEntry base = (SymtabEntry) vt.derivedFrom()
528: .elementAt(0);
529: if (!"ValueBase".equals(base.name()))
530: return Util.helperName(base, true) + ".type ()"; // <d61056>
531: }
532: return "null";
533: } // getConcreteBaseTypeCode
534:
535: public void helperRead(String entryName, SymtabEntry entry,
536: PrintWriter stream) {
537: // <d59418 - KLR> per Simon, make "static" read call istream.read_value.
538: // put real marshalling code in read_value.
539:
540: if (((ValueEntry) entry).isAbstract()) {
541: stream
542: .println(" throw new org.omg.CORBA.BAD_OPERATION (\"abstract value cannot be instantiated\");");
543: } else {
544: stream
545: .println(" return ("
546: + entryName
547: + ") ((org.omg.CORBA_2_3.portable.InputStream) istream).read_value (get_instance());"); // <d60929>
548: }
549: stream.println(" }");
550: stream.println();
551:
552: // done with "read", now do "read_value with real marshalling code.
553:
554: stream
555: .println(" public java.io.Serializable read_value (org.omg.CORBA.portable.InputStream istream)"); // <d60929>
556: stream.println(" {");
557:
558: // per Simon, 3/3/99, read_value for custom values throws an exception
559: if (((ValueEntry) entry).isAbstract()) {
560: stream
561: .println(" throw new org.omg.CORBA.BAD_OPERATION (\"abstract value cannot be instantiated\");");
562: } else if (((ValueEntry) entry).isCustom()) {
563: stream
564: .println(" throw new org.omg.CORBA.BAD_OPERATION (\"custom values should use unmarshal()\");");
565: } else {
566: stream.println(" " + entryName + " value = new "
567: + entryName + " ();");
568: read(0, " ", "value", entry, stream);
569: stream.println(" return value;");
570: }
571: stream.println(" }");
572: stream.println();
573: // End of normal read method
574:
575: // Per Simon, 8/26/98 - Value helpers get an additional overloaded
576: // read method where the value is passed in instead of "new'd" up. This is
577: // used for reading parent value state.
578:
579: // Per Simon, 3/3/99 - Don't change this "read" for custom marshalling
580: stream
581: .println(" public static void read (org.omg.CORBA.portable.InputStream istream, "
582: + entryName + " value)");
583: stream.println(" {");
584: read(0, " ", "value", entry, stream);
585: } // helperRead
586:
587: public int read(int index, String indent, String name,
588: SymtabEntry entry, PrintWriter stream) {
589: // First do the state members from concrete parent hierarchy
590: Vector vParents = ((ValueEntry) entry).derivedFrom();
591: if (vParents != null && vParents.size() != 0) {
592: ValueEntry parent = (ValueEntry) vParents.elementAt(0);
593: if (parent == null)
594: return index;
595: // Per Simon, 4/6/99 - call parent read. <d60929>
596: if (!Util.javaQualifiedName(parent).equals(
597: "java.io.Serializable")) // <d60929>
598: stream.println(indent + Util.helperName(parent, true)
599: + ".read (istream, value);"); // <d60929> // <d61056>
600: }
601:
602: Vector vMembers = ((ValueEntry) entry).state();
603: int noOfMembers = vMembers == null ? 0 : vMembers.size();
604:
605: for (int k = 0; k < noOfMembers; k++) {
606: TypedefEntry member = (TypedefEntry) ((InterfaceState) vMembers
607: .elementAt(k)).entry;
608: String memberName = member.name();
609: SymtabEntry mType = member.type();
610:
611: if (mType instanceof PrimitiveEntry
612: || mType instanceof TypedefEntry
613: || mType instanceof SequenceEntry
614: || mType instanceof StringEntry
615: || !member.arrayInfo().isEmpty())
616: index = ((JavaGenerator) member.generator()).read(
617: index, indent, name + '.' + memberName, member,
618: stream);
619: else if (mType instanceof ValueEntry) {
620: String returnType = Util.javaQualifiedName(mType);
621: if (mType instanceof ValueBoxEntry)
622: // <f46082.51> Remove -stateful.
623: //returnType = Util.javaStatefulName (mType);
624: returnType = Util.javaName(mType);
625: stream
626: .println(" "
627: + name
628: + '.'
629: + memberName
630: + " = ("
631: + returnType
632: + ") ((org.omg.CORBA_2_3.portable.InputStream)istream).read_value ("
633: + Util.helperName(mType, true) + // <d61056>
634: ".get_instance ());"); // <d61056>
635: } else
636: stream.println(indent + name + '.' + memberName + " = "
637: + Util.helperName(mType, true)
638: + ".read (istream);"); // <d61056>
639: }
640:
641: return index;
642: } // read
643:
644: public void helperWrite(SymtabEntry entry, PrintWriter stream) {
645: // <d59418 - KLR> per Simon, make "static" write call istream.write_value.
646: // put real marshalling code in write_value.
647: stream
648: .println(" ((org.omg.CORBA_2_3.portable.OutputStream) ostream).write_value (value, get_instance());"); // <d60929>
649: stream.println(" }");
650: stream.println();
651:
652: // <d62062>
653: // per Simon, 4/27/99, add static _write that marshals the state of this
654: // value for non-custom valuetypes
655: if (!((ValueEntry) entry).isCustom()) {
656: stream
657: .println(" public static void _write (org.omg.CORBA.portable.OutputStream ostream, "
658: + Util.javaName(entry) + " value)");
659: stream.println(" {");
660: write(0, " ", "value", entry, stream);
661: stream.println(" }");
662: stream.println();
663: }
664:
665: // done with "_write", now do "write_value
666: stream
667: .println(" public void write_value (org.omg.CORBA.portable.OutputStream ostream, java.io.Serializable obj)"); // <d60929>
668: stream.println(" {");
669:
670: // per Simon, 3/3/99, write_value for custom values throws an exception
671: if (((ValueEntry) entry).isCustom()) {
672: stream
673: .println(" throw new org.omg.CORBA.BAD_OPERATION (\"custom values should use marshal()\");");
674: } else {
675: String entryName = Util.javaName(entry);
676: stream.println(" _write (ostream, (" + entryName
677: + ") obj);"); // <d62062>
678: // write (0, " ", "value", entry, stream); <d62062>
679: }
680: } // helperWrite
681:
682: public int write(int index, String indent, String name,
683: SymtabEntry entry, PrintWriter stream) {
684: // First do the state members from concrete parent hierarchy
685: Vector vParents = ((ValueEntry) entry).derivedFrom();
686: if (vParents != null && vParents.size() != 0) {
687: ValueEntry parent = (ValueEntry) vParents.elementAt(0);
688: if (parent == null)
689: return index;
690: // Per Simon, 4/06/99 - call parent write. <d60929>
691: // Per Simon, 4/27/99 - call parent _write. <d62062>
692: if (!Util.javaQualifiedName(parent).equals(
693: "java.io.Serializable")) // <d60929>
694: stream.println(indent + Util.helperName(parent, true)
695: + "._write (ostream, value);"); // <d60929> <d61056> <d62062>
696: }
697:
698: Vector vMembers = ((ValueEntry) entry).state();
699: int noOfMembers = vMembers == null ? 0 : vMembers.size();
700: for (int k = 0; k < noOfMembers; k++) {
701: TypedefEntry member = (TypedefEntry) ((InterfaceState) vMembers
702: .elementAt(k)).entry;
703: String memberName = member.name();
704: SymtabEntry mType = member.type();
705:
706: if (mType instanceof PrimitiveEntry
707: || mType instanceof TypedefEntry
708: || mType instanceof SequenceEntry
709: || mType instanceof StringEntry
710: || !member.arrayInfo().isEmpty())
711: index = ((JavaGenerator) member.generator()).write(
712: index, indent, name + '.' + memberName, member,
713: stream);
714: else
715: stream.println(indent + Util.helperName(mType, true)
716: + // <d61056>
717: ".write (ostream, " + name + '.' + memberName
718: + ");");
719: }
720:
721: return index;
722: } // write
723:
724: /**
725: *
726: **/
727: protected void writeAbstract() {
728: stream.print("public interface " + v.name());
729:
730: // workaround: if the abstract value type does not have any parent, a vector
731: // containing ValueBase should be returned instead of an empty vector
732: if (v.derivedFrom().size() == 0)
733: stream.print(" extends org.omg.CORBA.portable.ValueBase"); // <d60929>
734: else {
735: SymtabEntry parent;
736: // list the values the abstract value type inherits
737: for (int i = 0; i < v.derivedFrom().size(); i++) {
738: if (i == 0)
739: stream.print(" extends ");
740: else
741: stream.print(", ");
742: parent = (SymtabEntry) v.derivedFrom().elementAt(i);
743: stream.print(Util.javaName(parent));
744: }
745: }
746:
747: // list the interface the abstract value type supports
748: if (v.supports().size() > 0) {
749: stream.print(", ");
750: SymtabEntry intf = (SymtabEntry) v.supports().elementAt(0);
751: stream.print(Util.javaName(intf));
752: }
753: stream.println();
754: stream.println("{");
755: }
756:
757: protected int emit = 0;
758: protected Factories factories = null;
759: protected Hashtable symbolTable = null;
760: protected ValueEntry v = null;
761: protected PrintWriter stream = null;
762: protected boolean explicitDefaultInit = false; // <d57067 - klr>
763: } // class ValueGen
|