001 /* 002 Copyright (C) 2002-2003 Laurent Martelli <laurent@aopsys.com> 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public 015 License along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 017 USA */ 018 019 package org.objectweb.jac.core; 020 021 import org.aopalliance.intercept.Interceptor; 022 import org.objectweb.jac.util.ExtArrays; 023 024 public class WrappingChain { 025 public Interceptor[] chain; 026 027 public WrappingChain(Interceptor[] chain) { 028 this.chain = chain; 029 } 030 public WrappingChain() { 031 this.chain = ExtArrays.emptyInterceptorArray; 032 } 033 public void add(int rank,Interceptor interceptor) { 034 Interceptor[] newChain = new Interceptor[chain.length+1]; 035 System.arraycopy(chain,0,newChain,0,rank); 036 System.arraycopy(chain,rank,newChain,rank+1,chain.length-rank); 037 newChain[rank] = interceptor; 038 chain = newChain; 039 } 040 041 protected void ensureCapacity(int n) { 042 } 043 044 public boolean contains(Interceptor interceptor) { 045 for (int i=chain.length-1; i>=0; i--) { 046 if (chain[i]==interceptor) 047 return true; 048 } 049 return false; 050 } 051 public void remove(int rank) { 052 Interceptor[] newChain = new Interceptor[chain.length-1]; 053 System.arraycopy(chain,0,newChain,0,rank); 054 System.arraycopy(chain,rank+1,newChain,rank,chain.length-rank-1); 055 chain = newChain; 056 } 057 public int size() { 058 return chain.length; 059 } 060 public Interceptor get(int i) { 061 return chain[i]; 062 } 063 public String toString() { 064 String result = "["; 065 for (int i=0; i<chain.length;i++) { 066 if (i!=0) { 067 result += ","; 068 } 069 result += chain[i].toString(); 070 } 071 072 result += "]"; 073 return result; 074 } 075 }