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

Quick Search    Search Deep

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


1   //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/LocalVariableTableAttribute.java,v 1.2 2003/09/08 21:03:31 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/09/08 21:03:31 $, by $Author: toggm $            *
9    * Version: $Revision: 1.2 $                                                  *
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.util.Vector;
21  
22  import java.io.DataInputStream;
23  import java.io.DataOutputStream;
24  import java.io.IOException;
25  
26  import com.chaoswg.xtc4y.classdesc.code.Code;
27  
28  /**
29   * This class describes the information for a localVariableTable attribute 
30   * ($4.7.9)
31   * TBD: make editable
32   * @author Mike Toggweiler
33   **/
34  public class LocalVariableTableAttribute extends Attribute 
35      implements CodeCompatible {
36  
37      public static final String NAME = "LocalVariableTable";    
38      private Vector entries = new Vector();
39  
40      /**
41       * Creates a LocalVariableTableAttribute and initializes it from a 
42       * DataInputStream
43       * The attribute name and length 
44       * of the attribute information was already read.
45       * @param dis the DataInputStream to read from
46       * @param cp the constant pool to resolve indices
47       * @param length the length of the attribute information provided 
48       * on the DataInputStream    
49       **/
50      protected LocalVariableTableAttribute(DataInputStream dis, ConstantPool cp, 
51            int length) 
52    throws IOException {    
53    super(dis, cp, length);
54    
55    if (!getName().equals(NAME)) {
56        throw new ClassFormatError("Attribute name does not match");
57    }
58  
59    int tableLength = dis.readUnsignedShort();
60    for (int i=0; i<tableLength; ++i) {
61        entries.add(new LocalVariableTableEntry(dis, cp));
62    }
63      }    
64  
65      /**
66       * construct a new deprecated attribute
67       **/
68      public LocalVariableTableAttribute() {
69      }
70  
71      /**
72       * Write the attribute information onto the DataOutputStream, using the 
73       * constant pool to register variables. The Attribute name and the 
74       * length of the information will already be written. A specific 
75       * attribute implementation should overwrite this method.
76       * @param dos the DataOutputStream to write on
77       * @param cp The constant pool to register variables
78       **/
79      protected void writeAttribute(DataOutputStream dos, ConstantPool cp) 
80    throws IOException {
81    dos.writeShort(entries.size());
82    for (int i=0; i<entries.size(); ++i) {
83        ((LocalVariableTableEntry)
84         entries.elementAt(i)).writeEntry(dos, cp);
85    }
86      }
87  
88      /**
89       * @return the name of the attribute
90       **/
91      public String getName() {
92    return NAME;
93      }   
94  
95      /**
96       * Called to resolve the temporary stored indices into the code 
97       * table
98       * @param code the Code table after initialization
99       **/
100     public void resolveIndices(Code code) {
101   for (int i=0; i<entries.size(); ++i) {
102       ((LocalVariableTableEntry)
103        entries.elementAt(i)).resolveIndices(code);
104   }
105     }
106 
107     /**
108      * Called to resolve indices on instructions from the code table
109      * @param code the code table after initialization
110      **/
111     public void readIndices(Code code) {
112   for (int i=0; i<entries.size(); ++i) {
113       ((LocalVariableTableEntry)
114        entries.elementAt(i)).readIndices(code);
115   }
116     }
117 }