Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/chaoswg/xtc4y/classdesc/RefCPEntry.java


1   //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/RefCPEntry.java,v 1.1.1.1 2003/08/07 13:40:30 toggm Exp $
2   /******************************************************************************
3    * XTC4y - eXtreme Testing Collection 4 you                                   *
4    * -------------------------------------------------------------------------- *
5    * URL: http://www.chaoswg.com/xtc4y                                          *
6    * Author: Mike Toggweiler (2.dog@gmx.ch)                                     *
7    *                                                                            *
8    * Last Updated: $Date: 2003/08/07 13:40:30 $, by $Author: toggm $            *
9    * Version: $Revision: 1.1.1.1 $                                                  *
10   * -------------------------------------------------------------------------- *
11   * COPYRIGHT:   (c) 2003 by Mike Toggweiler                                   *
12   *                                                                            *
13   * This program is free software; you can redistribute it and/or modify       *
14   * it under the terms of the GNU General Public License as published by       *
15   * the Free Software Foundation; either version 2 of the License, or          *
16   * (at your option) any later version.                                        *
17   *****************************************************************************/
18  package com.chaoswg.xtc4y.classdesc;
19  
20  import java.io.DataInputStream;
21  import java.io.DataOutputStream;
22  import java.io.IOException;
23  
24  /**
25   * this class represent a Ref constant pool entry and is an abstraction 
26   * from all the reference CP Entried. No setter methods 
27   * are implemented because the values may be changed in the returned 
28   * constant pool entries.
29   * @author Mike Toggweiler
30   **/
31  public abstract class RefCPEntry extends ConstantPoolEntry {
32      private ClassCPEntry classCP;
33      private NameAndTypeCPEntry natCP;
34      private short classIndex;
35      private short natIndex;
36      
37      /**
38       * Create a fieldref entry
39       * @param tag the tag of the implementing ref cp entry
40       * @param classCP a ClassCPEntry
41       * @param natCP a NameAndTypeCPEntry
42       **/
43      protected RefCPEntry(byte tag, ClassCPEntry classCP, 
44         NameAndTypeCPEntry natCP) {
45    super(tag);
46    this.classCP = classCP;
47    this.natCP = natCP;
48      }  
49  
50      /**
51       * Creates a RefCPEntry and initializes it from a DataInputStream
52       * @param tag the tag of the implementing ref cp entry
53       * @param dis the DataInputStream to read from
54       **/
55      protected RefCPEntry(byte tag, DataInputStream dis) 
56    throws IOException {
57    super(tag);
58    
59    //class_index
60    classIndex = (short)dis.readUnsignedShort();
61    //name_and_type_index
62    natIndex = (short)dis.readUnsignedShort();
63      }
64  
65      /**
66       * Resolve the internal stored indices thorugh the Constantpool
67       * @param cp the constantpool to resolve indices
68       **/
69      protected void resolve(ConstantPool cp) {
70    classCP = (ClassCPEntry)cp.getCPEntryAt(classIndex);
71    natCP = (NameAndTypeCPEntry)cp.getCPEntryAt(natIndex);
72      }
73  
74      /**
75       * Write the type specific constant pool entry information onto a 
76       * DataOutputStream
77       * @param dos the DataOutputStream to write on     
78       * @param cp the constantpool entry used to register names
79       **/
80      protected void writeCPEntry(DataOutputStream dos, ConstantPool cp) 
81    throws IOException {
82    dos.writeShort(cp.addCPEntry(classCP));
83    dos.writeShort(cp.addCPEntry(natCP));  
84      }
85  
86      /**
87       * @return the class cp entry
88       **/
89      public ClassCPEntry getClassCP() {
90    return classCP;
91      }
92  
93      /**
94       * @return the nameAndType cp
95       **/
96      public NameAndTypeCPEntry getNameAndTypeCP() {
97    return natCP;
98      }
99  
100     /**
101      * Checks if another RefCPEntry is equal to this. 
102      **/
103     public boolean equals(Object obj) {
104   if (!(getClass().isAssignableFrom(obj.getClass()))) {
105       return false;
106   }
107   RefCPEntry other = (RefCPEntry)obj;  
108   boolean check = (this.classCP == null && other.classCP == null ||
109        this.classCP != null && 
110        this.classCP.equals(other.classCP));
111   return (check && (this.natCP == null && other.natCP == null || 
112         this.natCP != null && 
113         this.natCP.equals(other.natCP)));
114     }
115 
116     /**
117      * print in a readable way
118      **/
119     public String toString() {
120   return getClass().getName()+":"+hashCode()+":["+classCP+"]:["+
121       natCP+"]";
122     }
123 }