home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 July / Chip_1998-07_cd.bin / zkuste / JBuilder / BDK / Win / bdk_sep97.exe / _SETUP.1 / FieldDesc.java < prev    next >
Encoding:
Java Source  |  1997-09-10  |  2.7 KB  |  108 lines

  1. /*
  2.  *
  3.  * @(#) FieldDesc.java 1.4@(#)
  4.  *
  5.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  6.  * 
  7.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  8.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  9.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  10.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  11.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  12.  * THIS SOFTWARE OR ITS DERIVATIVES.
  13.  * 
  14.  */
  15.  
  16. /**
  17.  * <p>
  18.  * sunw.demo.classfile.FieldDesc
  19.  * </p> 
  20.  *
  21.  * @version 1.0
  22.  * @author Laurence P. G. Cable
  23.  */
  24.  
  25.  
  26. package sunw.demo.classfile;
  27.  
  28.  
  29. import java.io.DataOutputStream;
  30. import java.io.IOException;
  31.  
  32. import sunw.demo.classfile.ClassFile;
  33. import sunw.demo.classfile.UTF8Constant;
  34. import sunw.demo.classfile.Attribute;
  35.  
  36. /**
  37.  * <p>
  38.  * Implements the field_info structure of a class file, used to describe
  39.  * the attributes of all fields implemented by this class. The class provides
  40.  * minimal support to write the formatted structure to the stream.
  41.  * </p>
  42.  */
  43.  
  44. final class FieldDesc {
  45.  
  46.     final static short ACC_PUBLIC        = 0x0001;
  47.     final static short ACC_PRIVATE        = 0x0002;
  48.     final static short ACC_PROTECTED        = 0x0004;
  49.     final static short ACC_STATIC        = 0x0008;
  50.     final static short ACC_FINAL        = 0x0010;
  51.     final static short ACC_VOLATILE        = 0x0040;
  52.     final static short ACC_TRANSIENT        = 0x0080;
  53.  
  54.     private UTF8Constant    name;
  55.     private UTF8Constant    descriptor;
  56.  
  57.     private short        accessFlags;
  58.  
  59.     private ClassFile        classFile;
  60.  
  61.     private Attribute[]        attributes;
  62.  
  63.     /**
  64.      * <p> construct a descriptor for a field. </p>
  65.      *
  66.      * @param field    name
  67.      * @param desc    its type descriptor
  68.      * @param flags    access flags
  69.      * @param cf    the class file
  70.      * @param attrs    any associated attributes
  71.      *
  72.      */
  73.  
  74.     FieldDesc(String field, String desc, short flags, ClassFile cf, Attribute[] attrs) {
  75.         super();
  76.  
  77.         // we would validate here ...
  78.  
  79.         name        = cf.addUTF8Constant(field);
  80.         descriptor  = cf.addUTF8Constant(desc);
  81.         accessFlags = flags;
  82.         classFile   = cf;
  83.         attributes  = attrs;
  84.     }
  85.  
  86.     /**
  87.      * <p> write the field to the stream </p>
  88.      *
  89.      * @param dos    the output stream
  90.      *
  91.      * @throws IOException
  92.      */
  93.  
  94.     void write(DataOutputStream dos) throws IOException {
  95.         dos.writeShort(accessFlags);
  96.         dos.writeShort(name.getConstantPoolIndex());
  97.         dos.writeShort(descriptor.getConstantPoolIndex());
  98.  
  99.     if (attributes != null && attributes.length == 0) {
  100.             dos.writeShort(attributes.length);
  101.  
  102.             for (int i = 0; i < attributes.length; i++) {
  103.             attributes[i].write(dos);
  104.             }
  105.     } else dos.writeShort(0);
  106.     }
  107. }
  108.