KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > javaguard > classfile > ExceptionInfo


1 /**
2  * JavaGuard -- an obfuscation package for Java classfiles.
3  *
4  * Copyright (c) 1999 Mark Welsh (markw@retrologic.com)
5  * Copyright (c) 2002 Thorsten Heit (theit@gmx.de)
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * The author may be contacted at theit@gmx.de.
22  *
23  *
24  * $Id: ExceptionInfo.java,v 1.2 2002/05/08 11:53:42 glurk Exp $
25  */

26 package net.sf.javaguard.classfile;
27
28 import java.io.*;
29
30
31 /** Representation of an Exception table entry.
32  *
33  * @author <a HREF="mailto:theit@gmx.de">Thorsten Heit</a>
34  * @author <a HREF="mailto:markw@retrologic.com">Mark Welsh</a>
35  */

36 public class ExceptionInfo {
37   /** The size of the exception info constant field. */
38   public static final int CONSTANT_FIELD_SIZE = 8;
39   
40   /** The startPc field. */
41   private int startPc;
42   /** The endPc field. */
43   private int endPc;
44   /** The handlerPc field. */
45   private int handlerPc;
46   /** The catchType field. */
47   private int catchType;
48   
49   
50   
51   
52   /** Creates a new ExceptionInfo object from the given input stream.
53    * @param din the input stream
54    * @return the ExceptionInfo object created from the input stream
55    * @throws IOException if an I/O error occurs
56    */

57   public static ExceptionInfo create(DataInput din)
58   throws IOException {
59     ExceptionInfo ei = new ExceptionInfo();
60     ei.read(din);
61     return ei;
62   }
63   
64   
65   
66   
67   /** Private constructor.
68    */

69   private ExceptionInfo() {
70   }
71   
72   
73   
74   
75   /** Sets the value for the startPc field.
76    * @param value the value for the startPc field
77    * @see #getStartPc
78    */

79   protected void setStartPc(int value) {
80     startPc = value;
81   }
82   
83   
84   /** Returns the value of the startPc field.
85    * @return value of the startPc field.
86    * @see #setStartPc
87    */

88   protected int getStartPc() {
89     return startPc;
90   }
91   
92   
93   
94   
95   /** Sets the value for the endPc field.
96    * @param value the value for the endPc field
97    * @see #getEndPc
98    */

99   protected void setEndPc(int value) {
100     endPc = value;
101   }
102   
103   
104   /** Returns the value of the endPc field.
105    * @return value of the endPc field
106    * @see #getEndPc
107    */

108   protected int getEndPc() {
109     return endPc;
110   }
111   
112   
113   
114   
115   /** Sets the value for the handlerPc field.
116    * @param value the value for the handlerPc field
117    * @see #getHandlerPc
118    */

119   protected void setHandlerPc(int value) {
120     handlerPc = value;
121   }
122   
123   
124   /** Returns the value of the handlerPc field.
125    * @return value of the handlerPc field
126    * @see #setHandlerPc
127    */

128   protected int getHandlerPc() {
129     return handlerPc;
130   }
131   
132   
133   
134   
135   /** Sets the value for the catchType field.
136    * @param value the value for the catchType field
137    * @see #getCatchType
138    */

139   protected void setCatchType(int value) {
140     catchType = value;
141   }
142   
143   
144   /** Returns the value of the catchType field.
145    * @return value of the catchType field
146    *Ê@see #setCatchType
147    */

148   protected int getCatchType() {
149     return catchType;
150   }
151   
152   
153   
154   
155   /** Read the data following the header.
156    * @param din the input stream
157    * @throws IOException if an I/O error occurs
158    */

159   private void read(DataInput din)
160   throws IOException {
161     setStartPc(din.readUnsignedShort());
162     setEndPc(din.readUnsignedShort());
163     setHandlerPc(din.readUnsignedShort());
164     setCatchType(din.readUnsignedShort());
165   }
166   
167   
168   /** Export data following the header to a DataOutput stream. Should be
169    * overwritten in subclasses.
170    * @param dout the output stream
171    * @throws IOException if an I/O error occurs
172    */

173   public void write(DataOutput dout)
174   throws IOException {
175     dout.writeShort(getStartPc());
176     dout.writeShort(getEndPc());
177     dout.writeShort(getHandlerPc());
178     dout.writeShort(getCatchType());
179   }
180   
181   
182   
183   
184   /** Dump the content of the entry to the specified file (used for debugging).
185    * @param pw the print writer
186    * @param cf the class file the element belongs to
187    */

188   public void dump(PrintWriter pw, ClassFile cf) {
189     pw.print("startPC: ");
190     pw.println(getStartPc());
191     pw.print("endPc: ");
192     pw.println(getEndPc());
193     pw.print("handlerPc: ");
194     pw.println(getHandlerPc());
195     pw.print("catchType: ");
196     pw.println(getCatchType());
197   }
198 }
199
Popular Tags