1 22 package org.jboss.aop.instrument; 23 24 import org.jboss.aop.ClassAdvisor; 25 26 import javassist.CannotCompileException; 27 import javassist.CtMethod; 28 import javassist.CtNewMethod; 29 import javassist.Modifier; 30 import javassist.NotFoundException; 31 32 38 public class NonOptimizedMethodExecutionTransformer extends MethodExecutionTransformer 39 { 40 public NonOptimizedMethodExecutionTransformer(Instrumentor instrumentor) 41 { 42 super(instrumentor); 43 } 44 45 protected void transformMethod(MethodTransformation trans, boolean wrap) throws NotFoundException, CannotCompileException 46 { 47 String methodInfoField = addMethodInfoField(Modifier.PRIVATE | Modifier.STATIC, trans.getClazz(), trans); 48 String wrappedName = ClassAdvisor.notAdvisedMethodName(trans.getClazzName(), 50 trans.getMethod().getName()); 51 CtMethod wmethod = CtNewMethod.copy(trans.getMethod(), trans.getClazz(), null); 52 53 String originalName = trans.getOriginalName(); 54 wmethod.setName(wrappedName); 55 trans.getClazz().addMethod(wmethod); 56 copyAnnotations(trans.getMethod(), wmethod); 57 trans.getMethod().setName(wrappedName); 58 wmethod.setName(originalName); 59 60 trans.setWMethod(wmethod, wrappedName); 61 62 getWrapper().prepareForWrapping(wmethod, WrapperTransformer.SINGLE_TRANSFORMATION_INDEX); 64 65 66 if (wrap) 67 { 68 getWrapper().wrap(wmethod, WrapperTransformer.SINGLE_TRANSFORMATION_INDEX); 70 71 setWrapperBody(trans, methodInfoField); 73 } 74 } 75 76 protected void doWrap(MethodTransformation trans, String methodInfoFieldName)throws NotFoundException, Exception 77 { 78 setWrapperBody(trans, methodInfoFieldName); 79 } 80 81 protected void setWrapperBody(MethodTransformation trans, String methodInfoField) throws NotFoundException 83 { 84 boolean isStatic = Modifier.isStatic(trans.getMethod().getModifiers()); 88 String code = null; 89 String args = "null"; 90 if (trans.getMethod().getParameterTypes().length > 0) args = "$args"; 91 if (!isStatic) 92 { 93 code = 94 "{ " + 95 " " + methodInfoFromWeakReference("info", methodInfoField) + 96 " org.jboss.aop.ClassInstanceAdvisor instAdv = (org.jboss.aop.ClassInstanceAdvisor)_getInstanceAdvisor();" + 97 " if (info.getInterceptors() != (Object[])null || (instAdv != null && instAdv.hasInstanceAspects)) " + 98 " { " + 99 " Object[] ags = " + args + "; " + 100 " " + getAopReturnStr(trans.getMethod()) + Instrumentor.HELPER_FIELD_NAME + ".invokeMethod(instAdv, this, " + trans.getHash() + "L, ags, info); " + 101 " } " + 102 " else " + 103 " {" + 104 " " + getReturnStr(trans.getMethod()) + " " + trans.getWrappedName() + "($$); " + 105 " }" + 106 "}"; 107 } 108 else 109 { 110 code = 111 "{ " + 112 " " + methodInfoFromWeakReference("info", methodInfoField) + 113 " if (info.getInterceptors() != (Object[])null) " + 114 " { " + 115 " org.jboss.aop.ClassInstanceAdvisor ia = null; " + 116 " Object[] ags = " + args + "; " + 117 " Object target = null; " + 118 " " + getAopReturnStr(trans.getMethod()) + Instrumentor.HELPER_FIELD_NAME + ".invokeMethod(ia, target, " + trans.getHash() + "L, ags, info); " + 119 " } " + 120 " else " + 121 " {" + 122 " " + getReturnStr(trans.getMethod()) + " " + trans.getWrappedName() + "($$); " + 123 " }" + 124 "}"; 125 } 126 try 127 { 128 trans.setWMethodBody(code); 129 } 130 catch (CannotCompileException e) 131 { 132 e.printStackTrace(); 133 throw new RuntimeException ("code was: " + code + " for method " + trans.getOriginalName()); } 135 } 136 } 137 | Popular Tags |