56 import com.sun.tools.corba.se.idl.MethodEntry;
57 import com.sun.tools.corba.se.idl.AttributeEntry;
58 import com.sun.tools.corba.se.idl.PrimitiveEntry;
59 import com.sun.tools.corba.se.idl.SequenceEntry;
60 import com.sun.tools.corba.se.idl.StringEntry;
61 import com.sun.tools.corba.se.idl.StructEntry;
62
63 /**
64 *
65 **/
66 public class ValueGen24 extends ValueGen
67 {
68 /**
69 * Public zero-argument constructor.
70 **/
71 public ValueGen24 ()
72 {
73 } // ctor
74
75 /**
76 * <d62023> - delete constructor; helper is abstract
77 **/
78 protected void writeConstructor ()
79 {
80 } // writeConstructor
81
82 /**
83 * <d62023> - delete write_value from non-boxed helpers
84 * - delete _write from non-boxed helpers
85 **/
86 public void helperWrite (SymtabEntry entry, PrintWriter stream)
87 {
88 // REVISIT: Abstract/Custom??
89 // per Simon mail 5/17/99
90 stream.println (" ((org.omg.CORBA_2_3.portable.OutputStream) ostream).write_value (value, id ());");
91 } // helperWrite
92
93 /**
94 * <d62023>
95 **/
96 public void helperRead (String entryName, SymtabEntry entry, PrintWriter stream)
97 {
98 // REVISIT: Abstract/Custom??
99 // per Simon mail 5/17/99
100 stream.println (" return (" + entryName + ")((org.omg.CORBA_2_3.portable.InputStream) istream).read_value (id ());");
101 } // helperRead
102
103 /**
104 * <d62023> - suppress initializers from mapped value; now generated in
105 * the Helper class and Factory class
106 **/
107 protected void writeInitializers ()
108 {
109 // override to do nothing
110 } // writeInitializers
111
112 /**
113 * <d62023> - Goes in mapped class, not Helper
114 **/
115 protected void writeTruncatable () // <d60929>
116 {
117 if (!v.isAbstract ()) {
118 stream.println (" private static String[] _truncatable_ids = {");
119 stream.print (" " + Util.helperName(v, true) + ".id ()");
120
121 // Any safe ValueEntry must have a concete value parent.
122 // The topmost parent cannot be safe since it doesn't have
123 // a concrete parent.
124 ValueEntry child = v;
125 while (child.isSafe ())
126 {
127 stream.println(",");
128 ValueEntry parent = (ValueEntry)child.derivedFrom ().elementAt (0);
129 stream.print(" \"" + Util.stripLeadingUnderscoresFromID (parent.repositoryID ().ID ()) + "\"");
130 child = parent;
131 }
132 stream.println();
133 stream.println(" };");
138 stream.println ();
139 }
140 } // writeTruncatable
141
142 class ImplStreamWriter {
143 private boolean isImplementsWritten = false ;
144
145 public void writeClassName( String name )
146 {
147 if (!isImplementsWritten) {
148 stream.print( " implements " ) ;
149 isImplementsWritten = true ;
150 } else
151 stream.print( ", " ) ;
152
153 stream.print( name ) ;
154 }
155 }
156
157 /**
158 * <d62023> CustomMarshal -> CustomValue for custom valuetypes
159 * mapped class is abstract
160 **/
161 protected void writeHeading ()
162 {
163 ImplStreamWriter isw = new ImplStreamWriter() ;
164
165 Util.writePackage (stream, v);
166 Util.writeProlog (stream, ((GenFileStream)stream).name ());
167
168 if (v.comment () != null)
169 v.comment ().generate ("", stream);
170
171 if (v.isAbstract ()) {
172 writeAbstract ();
173 return;
174 } else
175 stream.print ("public abstract class " + v.name ());
176
177 // There should always be at least one parent: ValueBase
178 SymtabEntry parent = (SymtabEntry) v.derivedFrom ().elementAt (0);
200
201 // Write out the supported interfaces
202 Enumeration enumeration = v.supports().elements();
203 while (enumeration.hasMoreElements()) {
204 InterfaceEntry ie = (InterfaceEntry)(enumeration.nextElement()) ;
205 String cname = Util.javaName(ie) ;
206 if (!ie.isAbstract())
207 cname += "Operations" ;
208 isw.writeClassName( cname ) ;
209 }
210
211 // for when a custom valuetype inherits from a non-custom valuetype
212 if ( v.isCustom () && !cv)
213 isw.writeClassName( "org.omg.CORBA.portable.CustomValue" ) ;
214
215 stream.println ();
216 stream.println ("{");
217 } // writeHeading
218
219 /**
220 * <d62023> - private state maps to protected, not default
221 **/
222 protected void writeMembers ()
223 {
224 // if the value type contains no data members, a null return is expected
225 if (v.state () == null)
226 return;
227
228 for (int i = 0; i < v.state ().size (); i ++)
229 {
230 InterfaceState member = (InterfaceState) v.state ().elementAt (i);
231 SymtabEntry entry = (SymtabEntry) member.entry;
232 Util.fillInfo (entry);
233
234 if (entry.comment () != null)
235 entry.comment ().generate (" ", stream);
236
237 String modifier = " ";
238 if (member.modifier == InterfaceState.Public)
239 modifier = " public ";
240 else
241 modifier = " protected ";
242 Util.writeInitializer (modifier, entry.name (), "", entry, stream);
243 }
244 stream.println();
245 } // writeMembers
246
247 /**
248 * <d62023> Methods need to be abstract
249 * writeStreamable
250 **/
251 protected void writeMethods ()
252 {
253 // contained vector contains methods, attributes, const, enums, exceptions,
254 // structs, unions, or typedefs that are declared inside the value object.
255 // State members of the nested types are also included in this vector.
256 // Thus, if the declaration of a constructed type is nested in the decl.
257 // of a state member, e.g struct x {boolean b;} memberx;
258 // the generation of the nested type must be handled here.
259 Enumeration e = v.contained ().elements ();
260 while (e.hasMoreElements ())
261 {
262 SymtabEntry contained = (SymtabEntry)e.nextElement ();
263 if (contained instanceof AttributeEntry)
264 {
265 AttributeEntry element = (AttributeEntry)contained;
266 ((AttributeGen24)element.generator ()).abstractMethod (symbolTable, element, stream);
267 }
268 else if (contained instanceof MethodEntry)
269 {
277 contained.type ().generate (symbolTable, stream);
278
279 // Note that we also need to generate the typedef itself if
280 // contained is a typedef.
281 contained.generate (symbolTable, stream);
282 }
283 }
284
285 // Abstract values are mapped to interfaces. There is no need to generate
286 // the bindings for inheriting methods in case of inheritance from other
287 // abstract values or supporting interface
288 if (v.isAbstract ())
289 return;
290
291 // Non-abstract, Non-Custom valuetypes support the Streamable interface
292 if (!(v.isCustom () || v.isAbstract ()))
293 writeStreamableMethods ();
294 } // writeMethods
295
296 /**
297 * <d62023> Call super._read()
298 **/
299 public int read (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
300 {
301 // First do the state members from concrete parent hierarchy
302 Vector vParents = ((ValueEntry) entry).derivedFrom ();
303 if (vParents != null && vParents.size() != 0)
304 {
305 ValueEntry parent = (ValueEntry) vParents.elementAt (0);
306 if (parent == null)
307 return index;
308
309 // call super._read if non-abstract value parent
310 if ((!parent.isAbstract ()) && (! Util.javaQualifiedName(parent).equals ("java.io.Serializable"))) // <d60929>
311 stream.println(indent + "super._read (istream);");
312 }
313
314 Vector vMembers = ((ValueEntry) entry).state ();
315 int noOfMembers = vMembers == null ? 0 : vMembers.size ();
316
317 for (int k = 0; k < noOfMembers; k++)
318 {
319 TypedefEntry member = (TypedefEntry)((InterfaceState)vMembers.elementAt (k)).entry;
320 String memberName = member.name ();
321 SymtabEntry mType = member.type ();
322
323 if (mType instanceof PrimitiveEntry ||
324 mType instanceof TypedefEntry ||
325 mType instanceof SequenceEntry ||
326 mType instanceof StringEntry ||
327 !member.arrayInfo ().isEmpty ())
328 index = ((JavaGenerator)member.generator ()).read (index, indent, name + '.' + memberName, member, stream);
329 else
330 stream.println (indent + name + '.' + memberName + " = " +
331 Util.helperName (mType, true) + ".read (istream);"); // <d61056>
332 }
333
334 return index;
335 } // read
336
337 /**
338 * <d62023> Call super._write()
339 **/
340 public int write (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
341 {
342 // First do the state members from concrete parent hierarchy
343 Vector vParents = ((ValueEntry)entry).derivedFrom ();
344 if (vParents != null && vParents.size () != 0)
345 {
346 ValueEntry parent = (ValueEntry)vParents.elementAt (0);
347 if (parent == null)
348 return index;
349 // call super._read if non-abstract value parent
350 if ((!parent.isAbstract ()) && (! Util.javaQualifiedName(parent).equals ("java.io.Serializable"))) // <d60929>
351 stream.println(indent + "super._write (ostream);");
352 }
353
354 Vector vMembers = ((ValueEntry) entry ).state ();
355 int noOfMembers = vMembers == null ? 0 : vMembers.size ();
356 for (int k = 0; k < noOfMembers; k++)
357 {
358 TypedefEntry member = (TypedefEntry)((InterfaceState)vMembers.elementAt (k)).entry;
359 String memberName = member.name ();
360 SymtabEntry mType = member.type ();
361
362 if (mType instanceof PrimitiveEntry ||
363 mType instanceof TypedefEntry ||
364 mType instanceof SequenceEntry ||
365 mType instanceof StringEntry ||
366 !member.arrayInfo ().isEmpty ())
367 index = ((JavaGenerator)member.generator ()).write (index, indent, name + '.' + memberName, member, stream);
368 else
369 stream.println (indent + Util.helperName (mType, true) + // <d61056>
370 ".write (ostream, " + name + '.' + memberName + ");");
371 }
372
373 return index;
374 } // write
375
376 /**
377 * <62023> - generate factory interface and default factory
378 **/
379 public void generate (Hashtable symbolTable, ValueEntry v, PrintWriter str)
380 {
381 this.symbolTable = symbolTable;
382 this.v = v;
383 init ();
384
385 openStream ();
386 if (stream == null)
387 return;
388 generateTie ();
389 generateHelper ();
390 generateHolder ();
391 if (!v.isAbstract ()) {
392 generateValueFactory ();
393 generateDefaultFactory ();
394 }
395 writeHeading ();
396 writeBody ();
397 writeClosing ();
|
56 import com.sun.tools.corba.se.idl.MethodEntry;
57 import com.sun.tools.corba.se.idl.AttributeEntry;
58 import com.sun.tools.corba.se.idl.PrimitiveEntry;
59 import com.sun.tools.corba.se.idl.SequenceEntry;
60 import com.sun.tools.corba.se.idl.StringEntry;
61 import com.sun.tools.corba.se.idl.StructEntry;
62
63 /**
64 *
65 **/
66 public class ValueGen24 extends ValueGen
67 {
68 /**
69 * Public zero-argument constructor.
70 **/
71 public ValueGen24 ()
72 {
73 } // ctor
74
75 /**
76 * d62023 - delete constructor; helper is abstract
77 **/
78 protected void writeConstructor ()
79 {
80 } // writeConstructor
81
82 /**
83 * <pre>
84 * d62023 - delete write_value from non-boxed helpers
85 * - delete _write from non-boxed helpers
86 * </pre>
87 **/
88 public void helperWrite (SymtabEntry entry, PrintWriter stream)
89 {
90 // REVISIT: Abstract/Custom??
91 // per Simon mail 5/17/99
92 stream.println (" ((org.omg.CORBA_2_3.portable.OutputStream) ostream).write_value (value, id ());");
93 } // helperWrite
94
95 /**
96 * d62023
97 **/
98 public void helperRead (String entryName, SymtabEntry entry, PrintWriter stream)
99 {
100 // REVISIT: Abstract/Custom??
101 // per Simon mail 5/17/99
102 stream.println (" return (" + entryName + ")((org.omg.CORBA_2_3.portable.InputStream) istream).read_value (id ());");
103 } // helperRead
104
105 /**
106 * d62023 - suppress initializers from mapped value; now generated in
107 * the Helper class and Factory class
108 **/
109 protected void writeInitializers ()
110 {
111 // override to do nothing
112 } // writeInitializers
113
114 /**
115 * d62023 - goes in mapped class, not Helper
116 **/
117 protected void writeTruncatable () // <d60929>
118 {
119 if (!v.isAbstract ()) {
120 stream.println (" private static String[] _truncatable_ids = {");
121 stream.print (" " + Util.helperName(v, true) + ".id ()");
122
123 // Any safe ValueEntry must have a concete value parent.
124 // The topmost parent cannot be safe since it doesn't have
125 // a concrete parent.
126 ValueEntry child = v;
127 while (child.isSafe ())
128 {
129 stream.println(",");
130 ValueEntry parent = (ValueEntry)child.derivedFrom ().elementAt (0);
131 stream.print(" \"" + Util.stripLeadingUnderscoresFromID (parent.repositoryID ().ID ()) + "\"");
132 child = parent;
133 }
134 stream.println();
135 stream.println(" };");
140 stream.println ();
141 }
142 } // writeTruncatable
143
144 class ImplStreamWriter {
145 private boolean isImplementsWritten = false ;
146
147 public void writeClassName( String name )
148 {
149 if (!isImplementsWritten) {
150 stream.print( " implements " ) ;
151 isImplementsWritten = true ;
152 } else
153 stream.print( ", " ) ;
154
155 stream.print( name ) ;
156 }
157 }
158
159 /**
160 * d62023 - CustomMarshal {@literal ->} CustomValue for custom valuetypes
161 * mapped class is abstract
162 **/
163 protected void writeHeading ()
164 {
165 ImplStreamWriter isw = new ImplStreamWriter() ;
166
167 Util.writePackage (stream, v);
168 Util.writeProlog (stream, ((GenFileStream)stream).name ());
169
170 if (v.comment () != null)
171 v.comment ().generate ("", stream);
172
173 if (v.isAbstract ()) {
174 writeAbstract ();
175 return;
176 } else
177 stream.print ("public abstract class " + v.name ());
178
179 // There should always be at least one parent: ValueBase
180 SymtabEntry parent = (SymtabEntry) v.derivedFrom ().elementAt (0);
202
203 // Write out the supported interfaces
204 Enumeration enumeration = v.supports().elements();
205 while (enumeration.hasMoreElements()) {
206 InterfaceEntry ie = (InterfaceEntry)(enumeration.nextElement()) ;
207 String cname = Util.javaName(ie) ;
208 if (!ie.isAbstract())
209 cname += "Operations" ;
210 isw.writeClassName( cname ) ;
211 }
212
213 // for when a custom valuetype inherits from a non-custom valuetype
214 if ( v.isCustom () && !cv)
215 isw.writeClassName( "org.omg.CORBA.portable.CustomValue" ) ;
216
217 stream.println ();
218 stream.println ("{");
219 } // writeHeading
220
221 /**
222 * d62023 - private state maps to protected, not default
223 **/
224 protected void writeMembers ()
225 {
226 // if the value type contains no data members, a null return is expected
227 if (v.state () == null)
228 return;
229
230 for (int i = 0; i < v.state ().size (); i ++)
231 {
232 InterfaceState member = (InterfaceState) v.state ().elementAt (i);
233 SymtabEntry entry = (SymtabEntry) member.entry;
234 Util.fillInfo (entry);
235
236 if (entry.comment () != null)
237 entry.comment ().generate (" ", stream);
238
239 String modifier = " ";
240 if (member.modifier == InterfaceState.Public)
241 modifier = " public ";
242 else
243 modifier = " protected ";
244 Util.writeInitializer (modifier, entry.name (), "", entry, stream);
245 }
246 stream.println();
247 } // writeMembers
248
249 /**
250 * d62023 - methods need to be abstract writeStreamable
251 **/
252 protected void writeMethods ()
253 {
254 // contained vector contains methods, attributes, const, enums, exceptions,
255 // structs, unions, or typedefs that are declared inside the value object.
256 // State members of the nested types are also included in this vector.
257 // Thus, if the declaration of a constructed type is nested in the decl.
258 // of a state member, e.g struct x {boolean b;} memberx;
259 // the generation of the nested type must be handled here.
260 Enumeration e = v.contained ().elements ();
261 while (e.hasMoreElements ())
262 {
263 SymtabEntry contained = (SymtabEntry)e.nextElement ();
264 if (contained instanceof AttributeEntry)
265 {
266 AttributeEntry element = (AttributeEntry)contained;
267 ((AttributeGen24)element.generator ()).abstractMethod (symbolTable, element, stream);
268 }
269 else if (contained instanceof MethodEntry)
270 {
278 contained.type ().generate (symbolTable, stream);
279
280 // Note that we also need to generate the typedef itself if
281 // contained is a typedef.
282 contained.generate (symbolTable, stream);
283 }
284 }
285
286 // Abstract values are mapped to interfaces. There is no need to generate
287 // the bindings for inheriting methods in case of inheritance from other
288 // abstract values or supporting interface
289 if (v.isAbstract ())
290 return;
291
292 // Non-abstract, Non-Custom valuetypes support the Streamable interface
293 if (!(v.isCustom () || v.isAbstract ()))
294 writeStreamableMethods ();
295 } // writeMethods
296
297 /**
298 * d62023 - call super._read()
299 **/
300 public int read (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
301 {
302 // First do the state members from concrete parent hierarchy
303 Vector vParents = ((ValueEntry) entry).derivedFrom ();
304 if (vParents != null && vParents.size() != 0)
305 {
306 ValueEntry parent = (ValueEntry) vParents.elementAt (0);
307 if (parent == null)
308 return index;
309
310 // call super._read if non-abstract value parent
311 if ((!parent.isAbstract ()) && (! Util.javaQualifiedName(parent).equals ("java.io.Serializable"))) // <d60929>
312 stream.println(indent + "super._read (istream);");
313 }
314
315 Vector vMembers = ((ValueEntry) entry).state ();
316 int noOfMembers = vMembers == null ? 0 : vMembers.size ();
317
318 for (int k = 0; k < noOfMembers; k++)
319 {
320 TypedefEntry member = (TypedefEntry)((InterfaceState)vMembers.elementAt (k)).entry;
321 String memberName = member.name ();
322 SymtabEntry mType = member.type ();
323
324 if (mType instanceof PrimitiveEntry ||
325 mType instanceof TypedefEntry ||
326 mType instanceof SequenceEntry ||
327 mType instanceof StringEntry ||
328 !member.arrayInfo ().isEmpty ())
329 index = ((JavaGenerator)member.generator ()).read (index, indent, name + '.' + memberName, member, stream);
330 else
331 stream.println (indent + name + '.' + memberName + " = " +
332 Util.helperName (mType, true) + ".read (istream);"); // <d61056>
333 }
334
335 return index;
336 } // read
337
338 /**
339 * d62023 - call super._write()
340 **/
341 public int write (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
342 {
343 // First do the state members from concrete parent hierarchy
344 Vector vParents = ((ValueEntry)entry).derivedFrom ();
345 if (vParents != null && vParents.size () != 0)
346 {
347 ValueEntry parent = (ValueEntry)vParents.elementAt (0);
348 if (parent == null)
349 return index;
350 // call super._read if non-abstract value parent
351 if ((!parent.isAbstract ()) && (! Util.javaQualifiedName(parent).equals ("java.io.Serializable"))) // <d60929>
352 stream.println(indent + "super._write (ostream);");
353 }
354
355 Vector vMembers = ((ValueEntry) entry ).state ();
356 int noOfMembers = vMembers == null ? 0 : vMembers.size ();
357 for (int k = 0; k < noOfMembers; k++)
358 {
359 TypedefEntry member = (TypedefEntry)((InterfaceState)vMembers.elementAt (k)).entry;
360 String memberName = member.name ();
361 SymtabEntry mType = member.type ();
362
363 if (mType instanceof PrimitiveEntry ||
364 mType instanceof TypedefEntry ||
365 mType instanceof SequenceEntry ||
366 mType instanceof StringEntry ||
367 !member.arrayInfo ().isEmpty ())
368 index = ((JavaGenerator)member.generator ()).write (index, indent, name + '.' + memberName, member, stream);
369 else
370 stream.println (indent + Util.helperName (mType, true) + // <d61056>
371 ".write (ostream, " + name + '.' + memberName + ");");
372 }
373
374 return index;
375 } // write
376
377 /**
378 * d62023 - generate factory interface and default factory
379 **/
380 public void generate (Hashtable symbolTable, ValueEntry v, PrintWriter str)
381 {
382 this.symbolTable = symbolTable;
383 this.v = v;
384 init ();
385
386 openStream ();
387 if (stream == null)
388 return;
389 generateTie ();
390 generateHelper ();
391 generateHolder ();
392 if (!v.isAbstract ()) {
393 generateValueFactory ();
394 generateDefaultFactory ();
395 }
396 writeHeading ();
397 writeBody ();
398 writeClosing ();
|