KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > structures > attributes > ExceptionTableEntry


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.structures.attributes;
9
10 import org.gjt.jclasslib.structures.*;
11
12 import java.io.*;
13
14 /**
15  * Describes an exception table entry in a <tt>Code</tt> attribute structure.
16  *
17  * @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>, <a HREF="mailto:vitor.carreira@gmail.com">Vitor Carreira</a>
18  * @version $Revision: 1.5 $ $Date: 2004/12/28 13:04:31 $
19  */

20 public class ExceptionTableEntry extends AbstractStructure {
21
22     /**
23      * Length in bytes of an exception table entry.
24      */

25     public static final int LENGTH = 8;
26
27     private int startPc;
28     private int endPc;
29     private int handlerPc;
30     private int catchType;
31
32     /**
33      * Factory method for creating <tt>ExceptionTableEntry</tt> structures.
34      *
35      * @param in the <tt>DataInput</tt> from which to read the
36      * <tt>ExceptionTableEntry</tt> structure
37      * @param classFile the parent class file of the structure to be created
38      * @return the new <tt>ExceptionTableEntry</tt> structure
39      * @throws InvalidByteCodeException if the byte code is invalid
40      * @throws IOException if an exception occurs with the <tt>DataInput</tt>
41      */

42     public static ExceptionTableEntry create(DataInput in, ClassFile classFile)
43             throws InvalidByteCodeException, IOException {
44
45         ExceptionTableEntry exceptionTableEntry = new ExceptionTableEntry();
46         exceptionTableEntry.setClassFile(classFile);
47         exceptionTableEntry.read(in);
48
49         return exceptionTableEntry;
50     }
51
52     /**
53      * Constructor.
54      */

55     public ExceptionTableEntry() {
56     }
57
58     /**
59      * Constructor.
60      *
61      * @param startPc the <tt>start_pc</tt>
62      * @param endPc the <tt>end_pc</tt>
63      * @param handlerPc the <tt>handler_pc</tt>
64      * @param catchType the constant pool index for the catch type of this exception table entry
65      */

66     public ExceptionTableEntry(int startPc, int endPc, int handlerPc, int catchType) {
67         this.startPc = startPc;
68         this.endPc = endPc;
69         this.handlerPc = handlerPc;
70         this.catchType = catchType;
71     }
72
73     /**
74      * Get the <tt>start_pc</tt> of this exception table entry.
75      *
76      * @return the <tt>start_pc</tt>
77      */

78     public int getStartPc() {
79         return startPc;
80     }
81
82     /**
83      * Set the <tt>start_pc</tt> of this exception table entry.
84      *
85      * @param startPc the <tt>start_pc</tt>
86      */

87     public void setStartPc(int startPc) {
88         this.startPc = startPc;
89     }
90
91     /**
92      * Get the <tt>end_pc</tt> of this exception table entry.
93      *
94      * @return the <tt>end_pc</tt>
95      */

96     public int getEndPc() {
97         return endPc;
98     }
99
100     /**
101      * Set the <tt>end_pc</tt> of this exception table entry.
102      *
103      * @param endPc the <tt>end_pc</tt>
104      */

105     public void setEndPc(int endPc) {
106         this.endPc = endPc;
107     }
108
109     /**
110      * Get the <tt>handler_pc</tt> of this exception table entry.
111      *
112      * @return the <tt>handler_pc</tt>
113      */

114     public int getHandlerPc() {
115         return handlerPc;
116     }
117
118     /**
119      * Set the <tt>handler_pc</tt> of this exception table entry.
120      *
121      * @param handlerPc the <tt>handler_pc</tt>
122      */

123     public void setHandlerPc(int handlerPc) {
124         this.handlerPc = handlerPc;
125     }
126
127     /**
128      * Get the constant pool index for the catch type of this exception table entry.
129      *
130      * @return the index
131      */

132     public int getCatchType() {
133         return catchType;
134     }
135
136     /**
137      * Set the constant pool index for the catch type of this exception table entry.
138      *
139      * @param catchType the index
140      */

141     public void setCatchType(int catchType) {
142         this.catchType = catchType;
143     }
144
145     public void read(DataInput in)
146             throws InvalidByteCodeException, IOException {
147
148         startPc = in.readUnsignedShort();
149         endPc = in.readUnsignedShort();
150         handlerPc = in.readUnsignedShort();
151         catchType = in.readUnsignedShort();
152         if (debug) debug("read ");
153     }
154
155     public void write(DataOutput out)
156             throws InvalidByteCodeException, IOException {
157
158         super.write(out);
159         out.writeShort(startPc);
160         out.writeShort(endPc);
161         out.writeShort(handlerPc);
162         out.writeShort(catchType);
163         if (debug) debug("wrote ");
164     }
165
166     protected void debug(String JavaDoc message) {
167         super.debug(message + "exception table entry with start_pc " + startPc +
168                 ", end_pc " + endPc + ", handler_pc " + handlerPc +
169                 ", catch_type index " + catchType);
170     }
171
172     protected String JavaDoc printAccessFlagsVerbose(int accessFlags) {
173         if (accessFlags != 0)
174             throw new RuntimeException JavaDoc("Access flags should be zero: " + Integer.toHexString(accessFlags));
175         return "";
176     }
177
178 }
179
Popular Tags