1 18 19 package org.objectweb.jac.core; 20 21 import java.lang.reflect.AccessibleObject ; 22 import java.lang.reflect.Constructor ; 23 import java.lang.reflect.Method ; 24 import java.util.Arrays ; 25 import org.aopalliance.intercept.ConstructorInvocation; 26 import org.aopalliance.intercept.Interceptor; 27 import org.aopalliance.intercept.Invocation; 28 import org.aopalliance.intercept.MethodInvocation; 29 import org.apache.log4j.Logger; 30 import org.objectweb.jac.core.rtti.AbstractMethodItem; 31 import org.objectweb.jac.core.rtti.ClassItem; 32 import org.objectweb.jac.core.rtti.ClassRepository; 33 import org.objectweb.jac.core.rtti.ConstructorItem; 34 import org.objectweb.jac.core.rtti.MethodItem; 35 import org.objectweb.jac.util.ExtArrays; 36 import org.objectweb.jac.util.Strings; 37 38 39 public class Interaction implements MethodInvocation, ConstructorInvocation { 40 static final Logger logger = Logger.getLogger("interaction"); 41 42 public final Wrappee wrappee; 43 public final AbstractMethodItem method; 44 public final Object [] args; 45 public int rank; 46 public String cur_AC; 47 public Interceptor[] wrappingChain; 48 49 public Interaction(WrappingChain wrappingChain, Wrappee wrappee, 50 AbstractMethodItem method, Object [] args) 51 { 52 logger.debug("new Interaction(wrappee="+wrappee+", method="+method+Strings.hash(method)+ 53 ", wrappingChain="+wrappingChain+ 54 (wrappingChain!=null ? Strings.hash(wrappingChain) : "")+ 55 ")"); 56 this.wrappingChain = 57 wrappingChain==null ? ExtArrays.emptyInterceptorArray : wrappingChain.chain; 58 this.wrappee = wrappee; 59 this.method = method; 60 this.args = args; 61 this.rank = 0; 62 } 63 64 public final Object proceed() { 65 rank += 1; 66 return Wrapping.nextWrapper(this); 67 } 68 69 public final Object invoke(Object substance) { 70 return method.invoke(substance,args); 71 } 72 73 public final Class getActualClass() { 74 if (wrappee!=null) 75 return wrappee.getClass(); 76 else 77 return method.getClassItem().getActualClass(); 78 } 79 80 ClassItem cli; 81 public final ClassItem getClassItem() { 82 if (cli==null) { 83 if (wrappee!=null) { 84 cli = ClassRepository.get().getClass(wrappee); 85 } else { 86 cli = method.getClassItem(); 87 } 88 } 89 return cli; 90 } 91 92 public String toString() { 93 return wrappee+"."+method+(args!=null?("("+Arrays.asList(args)+")"):"")+" rank="+rank; 94 } 95 96 97 public Constructor getConstructor() { 99 return ((ConstructorItem)method).getActualConstructor(); 100 } 101 102 103 public Method getMethod() { 104 return ((MethodItem)method).getActualMethod(); 105 } 106 107 public Object getArgument(int index) { 109 return args[index]; 110 } 111 112 public void setArgument(int index, Object argument) { 113 args[index]=argument; 114 } 115 116 public int getArgumentCount() { 117 return args.length; 118 } 119 120 public Object [] getArguments() { 121 return args; 122 } 123 124 public Object getThis() { 125 return wrappee; 126 } 127 128 public AccessibleObject getStaticPart() { 129 if(method instanceof ConstructorItem) { 130 return getConstructor(); 131 } else { 132 return getMethod(); 133 } 134 } 135 } 136 | Popular Tags |