1/* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved. 2 * 3 * This program and the accompanying materials are made available under 4 * the terms of the Common Public License v1.0 which accompanies this distribution, 5 * and is available at http://www.eclipse.org/legal/cpl-v10.html 6 * 7 * $Id: DeclaredExceptionTable.java,v 1.1.1.1 2004/05/09 16:57:47 vlad_r Exp $ 8 */ 9package com.vladium.jcd.cls.attribute; 10 11import java.io.IOException; 12 13import com.vladium.jcd.lib.UDataOutputStream; 14import com.vladium.util.IntVector; 15 16// ---------------------------------------------------------------------------- 17/** 18 * @author (C) 2001, Vlad Roubtsov 19 */ 20final class DeclaredExceptionTable implements IDeclaredExceptionTable 21{ 22 // public: ................................................................ 23 24 // ACCESSORS: 25 26 public int get (final int offset) 27 { 28 return m_exceptions.get (offset); 29 } 30 31 public int size () 32 { 33 return m_exceptions.size (); 34 } 35 36 public long length () 37 { 38 return (1 + m_exceptions.size ()) << 1; // use size() if class becomes non-final 39 } 40 41 // Cloneable: 42 43 /** 44 * Performs a deep copy. 45 */ 46 public Object clone () 47 { 48 try 49 { 50 final DeclaredExceptionTable _clone = (DeclaredExceptionTable) super.clone (); 51 52 // deep clone: 53 _clone.m_exceptions = (IntVector) m_exceptions.clone (); 54 55 return _clone; 56 } 57 catch (CloneNotSupportedException e) 58 { 59 throw new InternalError (e.toString ()); 60 } 61 } 62 63 // IClassFormatOutput: 64 65 public void writeInClassFormat (final UDataOutputStream out) throws IOException 66 { 67 int number_of_exceptions = m_exceptions.size (); // use size() if class becomes non-final 68 out.writeU2 (number_of_exceptions); 69 70 for (int i = 0; i < number_of_exceptions; i++) 71 { 72 out.writeU2 (get (i)); 73 } 74 } 75 76 77 // MUTATORS: 78 79 public int add (final int exception_index) 80 { 81 final int newoffset = m_exceptions.size (); // use size() if class becomes non-final 82 m_exceptions.add (exception_index); 83 84 return newoffset; 85 } 86 87 public int set (final int offset, final int exception_index) 88 { 89 return m_exceptions.set (offset, exception_index); 90 } 91 92 // protected: ............................................................. 93 94 // package: ............................................................... 95 96 97 DeclaredExceptionTable (final int capacity) 98 { 99 m_exceptions = capacity < 0 ? new IntVector () : new IntVector (capacity); 100 } 101 102 // private: ............................................................... 103 104 105 private IntVector m_exceptions; 106 107} // end of class 108// ---------------------------------------------------------------------------- 109