Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

CodeException.java

00001 package de.fub.bytecode.classfile;
00002 
00003 import  de.fub.bytecode.Constants;
00004 import  java.io.*;
00005 
00006 /**
00007  * This class represents an entry in the exception table of the <em>Code</em>
00008  * attribute and is used only there. It contains a range in which a
00009  * particular exception handler is active.
00010  *
00011  * @version $Id: CodeException.java,v 1.1.1.1 2002/01/24 03:44:00 pserver Exp $
00012  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00013  * @see     Code
00014  */
00015 public final class CodeException implements Cloneable, Constants {
00016   private int start_pc;   // Range in the code the exception handler is
00017   private int end_pc;     // active. start_pc is inclusive, end_pc exclusive
00018   private int handler_pc; /* Starting address of exception handler, i.e.
00019                * an offset from start of code.
00020                */
00021   private int catch_type; /* If this is zero the handler catches any
00022                * exception, otherwise it points to the
00023                * exception class which is to be caught.
00024                */
00025   /**
00026    * @param start_pc Range in the code the exception handler is active,
00027    * start_pc is inclusive while
00028    * @param end_pc is exclusive
00029    * @param handler_pc Starting address of exception handler, i.e.
00030    * an offset from start of code.
00031    * @param catch_type If zero the handler catches any 
00032    * exception, otherwise it points to the exception class which is 
00033    * to be caught.
00034    */
00035   public CodeException(int start_pc, int end_pc, int handler_pc,
00036                int catch_type)
00037   {
00038     this.start_pc   = start_pc;
00039     this.end_pc     = end_pc;
00040     this.handler_pc = handler_pc;
00041     this.catch_type = catch_type;
00042   }  
00043   /**
00044    * Initialize from another object.
00045    */
00046   public CodeException(CodeException c) {
00047     this(c.getStartPC(), c.getEndPC(), c.getHandlerPC(), c.getCatchType());
00048   }  
00049   /**
00050    * Construct object from file stream.
00051    * @param file Input stream
00052    * @throw IOException
00053    */  
00054   CodeException(DataInputStream file) throws IOException
00055   {
00056     this(file.readUnsignedShort(), file.readUnsignedShort(),
00057      file.readUnsignedShort(), file.readUnsignedShort());
00058   }  
00059   /**
00060    * Called by objects that are traversing the nodes of the tree implicitely
00061    * defined by the contents of a Java class. I.e., the hierarchy of methods,
00062    * fields, attributes, etc. spawns a tree of objects.
00063    *
00064    * @param v Visitor object
00065    */
00066   public void accept(Visitor v) {
00067     v.visitCodeException(this);
00068   }  
00069   /**
00070    * @return deep copy of this object
00071    */
00072   public CodeException copy() {
00073     try {
00074       return (CodeException)clone();
00075     } catch(CloneNotSupportedException e) {}
00076 
00077     return null;
00078   }  
00079   /**
00080    * Dump code exception to file stream in binary format.
00081    *
00082    * @param file Output file stream
00083    * @throw IOException
00084    */ 
00085   public final void dump(DataOutputStream file) throws IOException
00086   {
00087     file.writeShort(start_pc);
00088     file.writeShort(end_pc);
00089     file.writeShort(handler_pc);
00090     file.writeShort(catch_type);
00091   }  
00092   /**
00093    * @return 0, if the handler catches any exception, otherwise it points to
00094    * the exception class which is to be caught.
00095    */  
00096   public final int getCatchType() { return catch_type; }  
00097   /**
00098    * @return Exclusive end index of the region where the handler is active.
00099    */  
00100   public final int getEndPC() { return end_pc; }  
00101   /**
00102    * @return Starting address of exception handler, relative to the code.
00103    */  
00104   public final int getHandlerPC() { return handler_pc; }  
00105   /**
00106    * @return Inclusive start index of the region where the handler is active.
00107    */
00108   public final int getStartPC() { return start_pc; }  
00109   /**
00110    * @param catch_type.
00111    */
00112   public final void setCatchType(int catch_type) {
00113     this.catch_type = catch_type;
00114   }  
00115   /**
00116    * @param end_pc end of handled block
00117    */
00118   public final void setEndPC(int end_pc) {
00119     this.end_pc = end_pc;
00120   }  
00121   /**
00122    * @param handler_pc where the actual code is
00123    */
00124   public final void setHandlerPC(int handler_pc) {
00125     this.handler_pc = handler_pc;
00126   }  
00127   /**
00128    * @param start_pc start of handled block
00129    */
00130   public final void setStartPC(int start_pc) {
00131     this.start_pc = start_pc;
00132   }  
00133   /**
00134    * @return String representation.
00135    */ 
00136   public final String toString() {
00137     return "CodeException(start_pc = " + start_pc + 
00138       ", end_pc = " + end_pc +
00139       ", handler_pc = " + handler_pc + ", catch_type = " + catch_type + ")";
00140   }  
00141   public final String toString(ConstantPool cp) {
00142     return toString(cp, true);
00143   }  
00144   /**
00145    * @return String representation.
00146    */ 
00147   public final String toString(ConstantPool cp, boolean verbose) {
00148     String str;
00149 
00150     if(catch_type == 0)
00151       str = "<Any exception>(0)";
00152     else
00153       str = Utility.compactClassName(cp.getConstantString(catch_type, CONSTANT_Class)) +
00154     (verbose? "(" + catch_type + ")" : "");
00155 
00156     return start_pc + "\t" + end_pc + "\t" + handler_pc + "\t" + str;
00157   }  
00158 }

Generated at Thu Feb 7 06:42:36 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001