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

  1. /*
  2.  *
  3.  * @(#) RefConstant.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.RefConstant
  19.  * </p> 
  20.  *
  21.  * @version 1.0
  22.  * @author Laurence P. G. Cable
  23.  */
  24.  
  25.  
  26. package sunw.demo.classfile;
  27.  
  28. import java.io.DataOutputStream;
  29. import java.io.IOException;
  30.  
  31. import sunw.demo.classfile.ClassFile;
  32. import sunw.demo.classfile.ConstantPoolEntry;
  33. import sunw.demo.classfile.ClassConstant;
  34. import sunw.demo.classfile.NameAndTypeConstant;
  35.  
  36. /**
  37.  * <p>
  38.  * this base class provides minimal support for METHODREF, FIELDREF, and
  39.  * INTERFACEMETHODREF CPE's
  40.  * </p>
  41.  */
  42.  
  43. class RefConstant extends ConstantPoolEntry {
  44.  
  45.     private ClassConstant    clazz;
  46.     private NameAndTypeConstant    nandt;
  47.  
  48.     /**
  49.      * <p> construct a CPE </p>
  50.      *
  51.      * @param t        the CPE tag value
  52.      * @param cName    the class name
  53.      * @param nName    the name of the referenced field or method
  54.      * @param tName    the type descriptor of the field or method
  55.      * @param cf    the class file
  56.      *
  57.      */
  58.  
  59.     protected RefConstant(byte   t,     String cName,
  60.                       String nName, String tName, ClassFile cf) {
  61.         super(t, cf);
  62.     
  63.         clazz = new ClassConstant(cName, cf);
  64.         nandt = new NameAndTypeConstant(nName, tName, cf);
  65.  
  66.         addToConstantPool();
  67.     }
  68.  
  69.     /**
  70.      * <p> write the referenced object to the stream </p>
  71.      *
  72.      * @param dos the output stream
  73.      *
  74.      * @throws IOException
  75.      */
  76.  
  77.     void write(DataOutputStream dos) throws IOException {
  78.         dos.writeByte(getTag());
  79.         dos.writeShort(clazz.getConstantPoolIndex());
  80.         dos.writeShort(nandt.getConstantPoolIndex());
  81.     }
  82.  
  83.     /**
  84.      * @return the class constant for the referenced object
  85.      */
  86.  
  87.     ClassConstant getClassObject() { return clazz; }
  88.  
  89.     /**
  90.      * @return the name and type CPE for the referenced object
  91.      */
  92.  
  93.     NameAndTypeConstant getNameAndType() { return nandt; }
  94.  
  95.     /**
  96.      * @return object equality
  97.      */
  98.  
  99.     public boolean equals(Object o) {
  100.         if (o instanceof RefConstant) {
  101.             RefConstant rc = (RefConstant)o;
  102.  
  103.             return clazz.equals(rc.clazz) &&
  104.                    nandt.equals(rc.nandt);
  105.         } 
  106.  
  107.         return false;
  108.     }
  109.  
  110.     /**
  111.      * @return a hashcode for the object.
  112.      */
  113.     public int hashCode() {
  114.     return clazz.hashCode() + nandt.hashCode();
  115.     }
  116. }
  117.