1 18 19 package org.objectweb.jac.core; 20 21 22 import java.io.Serializable ; 23 import java.lang.reflect.Method ; 24 import java.util.Vector ; 25 import org.aopalliance.intercept.ConstructorInterceptor; 26 import org.aopalliance.intercept.ConstructorInvocation; 27 import org.aopalliance.intercept.Invocation; 28 import org.aopalliance.intercept.MethodInterceptor; 29 import org.aopalliance.intercept.MethodInvocation; 30 import org.objectweb.jac.core.rtti.ClassRepository; 31 32 52 53 public abstract class Wrapper 54 implements Serializable , MethodInterceptor, ConstructorInterceptor 55 { 56 57 protected static final ClassRepository cr = ClassRepository.get(); 58 59 62 63 public Wrapper(AspectComponent ac) { 64 this.ac = ac; 66 if (ac != null) { 67 ac.addWrapper(this); 69 } 71 } 72 73 74 protected final transient AspectComponent ac; 76 77 83 84 public static boolean defines(String methodName) { 85 if (ClassRepository.getDirectMethodAccess(Wrapper.class, methodName)[0] 86 != null) 87 return true; 88 return false; 89 } 90 91 98 99 public static Vector getExceptionHandlers(Class wrapperClass) { 100 Method [] methods = wrapperClass.getMethods(); 101 Vector ret = new Vector (); 102 for (int i = 0; i < methods.length; i++) { 103 Class [] pts = methods[i].getParameterTypes(); 104 if (pts.length > 0) { 105 Class cl = pts[0]; 106 boolean ok = false; 107 if (cl != null) { 108 while (cl != null 109 && (!cl.isPrimitive()) 110 && cl != Object .class) { 111 if (cl == Exception .class) { 112 ok = true; 113 } 114 cl = cl.getSuperclass(); 115 } 116 } 117 if (ok) { 118 ret.add(methods[i].getName()); 119 } 120 } 121 } 122 return ret; 123 } 124 125 130 131 public AspectComponent getAspectComponent() { 132 return ac; 133 137 } 138 139 145 146 public String getAspectComponentName() { 147 return ACManager.get().getName(ac); 148 } 149 150 161 166 169 170 public String toString() { 171 if (ac == null) { 172 return super.toString() + "(nobody)"; 173 } 174 return super.toString() + "(" + getAspectComponentName() + ")"; 175 } 176 177 248 public final Object proceed(Invocation invocation) { 249 Interaction interaction = (Interaction) invocation; 251 interaction.rank += 1; 252 return Wrapping.nextWrapper(interaction); 253 } 254 255 257 public final void attrdef(String name, Object value) { 258 Collaboration.get().addAttribute(name, value); 259 } 260 261 public final Object attr(String name) { 262 return Collaboration.get().getAttribute(name); 263 } 264 265 public Object invoke(MethodInvocation invocation) throws Throwable { 266 throw new Exception ("Wrapper "+this+" does not support method interception."); 267 } 268 269 public Object construct(ConstructorInvocation invocation) throws Throwable 270 { 271 throw new Exception ("Wrapper "+this+" does not support construction interception."); 272 } 273 274 } 275 | Popular Tags |