KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > enhancer > classfile > ExceptionRange


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.jdo.api.persistence.enhancer.classfile;
26
27 import java.io.*;
28
29 /**
30  * ExceptionRange represents a range an exception handler within
31  * a method in class file.
32  */

33
34 public class ExceptionRange {
35   /* The start of the exception hander (inclusive) */
36   private InsnTarget excStartPC;
37
38   /* The end of the exception hander (exclusive) */
39   private InsnTarget excEndPC;
40
41   /* The exception handler code */
42   private InsnTarget excHandlerPC;
43
44   /* The exception specification */
45   private ConstClass excCatchType;
46
47   /* public accessors */
48
49   /**
50    * return the start of the exception hander (inclusive)
51    */

52   public InsnTarget startPC() {
53     return excStartPC;
54   }
55
56   /**
57    * return the end of the exception hander (exclusive)
58    */

59   public InsnTarget endPC() {
60     return excEndPC;
61   }
62
63   /**
64    * return the exception handler code
65    */

66   public InsnTarget handlerPC() {
67     return excHandlerPC;
68   }
69
70   /**
71    * return the exception specification
72    * a null return value means a catch of any (try/finally)
73    */

74   public ConstClass catchType() {
75     return excCatchType;
76   }
77
78   /**
79    * constructor
80    */

81
82   public ExceptionRange(InsnTarget startPC, InsnTarget endPC,
83             InsnTarget handlerPC, ConstClass catchType) {
84     excStartPC = startPC;
85     excEndPC = endPC;
86     excHandlerPC = handlerPC;
87     excCatchType = catchType;
88   }
89
90   /* package local methods */
91
92   static ExceptionRange read(DataInputStream data, CodeEnv env)
93     throws IOException {
94     InsnTarget startPC = env.getTarget(data.readUnsignedShort());
95     InsnTarget endPC = env.getTarget(data.readUnsignedShort());
96     InsnTarget handlerPC = env.getTarget(data.readUnsignedShort());
97     ConstClass catchType =
98       (ConstClass) env.pool().constantAt(data.readUnsignedShort());
99     return new ExceptionRange(startPC, endPC, handlerPC, catchType);
100   }
101
102   void write(DataOutputStream out) throws IOException {
103     out.writeShort(excStartPC.offset());
104     out.writeShort(excEndPC.offset());
105     out.writeShort(excHandlerPC.offset());
106     out.writeShort(excCatchType == null ? 0 : excCatchType.getIndex());
107   }
108
109   void print(PrintStream out, int indent) {
110     ClassPrint.spaces(out, indent);
111     out.print("Exc Range:");//NOI18N
112
if (excCatchType == null)
113         out.print("any");//NOI18N
114
else
115         out.print("'" + excCatchType.asString() + "'");//NOI18N
116
out.print(" start = " + Integer.toString(excStartPC.offset()));//NOI18N
117
out.print(" end = " + Integer.toString(excEndPC.offset()));//NOI18N
118
out.println(" handle = " + Integer.toString(excHandlerPC.offset()));//NOI18N
119
}
120 }
121
122
Popular Tags