< prev index next >

src/java.corba/share/classes/com/sun/tools/corba/se/idl/toJavaPortable/ValueGen24.java

Print this page




  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)


 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    * {@literal <d62023>} - delete constructor; helper is abstract
  77    **/
  78   protected void writeConstructor ()
  79   {
  80   } // writeConstructor
  81 
  82   /**
  83    * {@literal <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    * {@literal <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    * {@literal <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    * {@literal <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    * {@literal <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    * {@literal <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    * {@literal <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)


 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    * {@literal <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    * {@literal <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    * {@literal <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 ();
< prev index next >