1 18 19 package org.objectweb.jac.core; 20 21 import org.aopalliance.intercept.Interceptor; 22 import org.objectweb.jac.util.ExtArrays; 23 24 public class WrappingChain { 25 public Interceptor[] chain; 26 27 public WrappingChain(Interceptor[] chain) { 28 this.chain = chain; 29 } 30 public WrappingChain() { 31 this.chain = ExtArrays.emptyInterceptorArray; 32 } 33 public void add(int rank,Interceptor interceptor) { 34 Interceptor[] newChain = new Interceptor[chain.length+1]; 35 System.arraycopy(chain,0,newChain,0,rank); 36 System.arraycopy(chain,rank,newChain,rank+1,chain.length-rank); 37 newChain[rank] = interceptor; 38 chain = newChain; 39 } 40 41 protected void ensureCapacity(int n) { 42 } 43 44 public boolean contains(Interceptor interceptor) { 45 for (int i=chain.length-1; i>=0; i--) { 46 if (chain[i]==interceptor) 47 return true; 48 } 49 return false; 50 } 51 public void remove(int rank) { 52 Interceptor[] newChain = new Interceptor[chain.length-1]; 53 System.arraycopy(chain,0,newChain,0,rank); 54 System.arraycopy(chain,rank+1,newChain,rank,chain.length-rank-1); 55 chain = newChain; 56 } 57 public int size() { 58 return chain.length; 59 } 60 public Interceptor get(int i) { 61 return chain[i]; 62 } 63 public String toString() { 64 String result = "["; 65 for (int i=0; i<chain.length;i++) { 66 if (i!=0) { 67 result += ","; 68 } 69 result += chain[i].toString(); 70 } 71 72 result += "]"; 73 return result; 74 } 75 } 76 | Popular Tags |