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

  1. /*
  2.  *
  3.  * @(#) Attribute.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.Attribute
  19.  * </p> 
  20.  *
  21.  * @version 1.0
  22.  * @author Laurence P. G. Cable
  23.  */
  24.  
  25. package sunw.demo.classfile;
  26.  
  27. import java.io.DataOutputStream;
  28. import java.io.IOException;
  29.  
  30. import sunw.demo.classfile.ClassFile;
  31. import sunw.demo.classfile.ConstantPoolEntry;
  32. import sunw.demo.classfile.UTF8Constant;
  33.  
  34. /**
  35.  * <p>
  36.  * The Attribute class is an abstract base class for all Attribute types
  37.  * found in the Java VM ClassFile format specification. This is a simple
  38.  * implementationd designed to support the minimal functionaliuty required
  39.  * to emit a valid ClassFile stream.
  40.  * </p>
  41.  */
  42.  
  43. abstract class Attribute {
  44.  
  45.     final static String SOURCEFILE         = "SourceFile";
  46.     final static String CONSTANTVALUE      = "ConstantValue";
  47.     final static String LOCALVARIABLETABLE = "LocalVariableTable";
  48.     final static String EXCEPTIONS         = "Exceptions";
  49.     final static String LINENUMBERTABLE    = "LineNumberTable";
  50.     final static String CODE           = "Code";
  51.     
  52.     private UTF8Constant name;
  53.     private ClassFile    classFile;
  54.  
  55.     /**
  56.      * <p> Construct an Attribute, enter it into the ConstantPool. </p>
  57.      */
  58.  
  59.     protected Attribute(String n, ClassFile cf) {
  60.         UTF8Constant utf8 = new UTF8Constant(n, cf);
  61.             
  62.         name      = utf8;
  63.         classFile = cf;
  64.     }
  65.  
  66.     /**
  67.      * @return the ClassFile this Attribute is contained within
  68.      */
  69.  
  70.     ClassFile getClassFile() { return classFile; }
  71.  
  72.     /**
  73.      * @return the "name" of the Attribute.
  74.      */
  75.  
  76.     String getName() { return name.getString(); }
  77.  
  78.     /**
  79.      * @return get the index of this Attribute in the ConstantPool 
  80.      */
  81.  
  82.     short getNameConstantPoolIndex() {
  83.         return name.getConstantPoolIndex();
  84.     }
  85.  
  86.     /**
  87.      * @return the length of the attribute as defined by the concrete subclass.
  88.      */
  89.  
  90.     abstract int getLength();
  91.  
  92.     /**
  93.      * <p> write the concrete Attribute subclass to the stream <p>
  94.      *
  95.      * @throws IOException
  96.      */
  97.  
  98.     abstract void write(DataOutputStream dos) throws IOException;
  99.  
  100.     /**
  101.      * <p> Compare this Attribute with the object and return equality. </p>
  102.      *
  103.      * @return is it equal
  104.      */
  105.  
  106.     abstract public boolean equals(Object o);
  107.  
  108.     /**
  109.      * @return a hashcode for the object.
  110.      */
  111.     abstract public int hashCode();
  112. }
  113.