Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*     */ package org.jboss.aop.instrument;
  /*     */ 
  /*     */ import  javassist.CannotCompileException;
  /*     */ import  javassist.CtClass;
  /*     */ import  javassist.CtConstructor;
  /*     */ import  javassist.CtField;
  /*     */ import  javassist.CtMethod;
  /*     */ import  javassist.CtNewMethod;
  /*     */ import  javassist.NotFoundException;
 /*     */ 
 /*     */ public class GeneratedAdvisorConstructionTransformer extends ConstructionTransformer
 /*     */ {
 /*     */   public GeneratedAdvisorConstructionTransformer(Instrumentor instrumentor)
 /*     */   {
 /*  47 */     super(instrumentor);
 /*     */   }
 /*     */ 
 /*     */   protected void generateConstructionInfoField(CtConstructor constructorint indexthrows NotFoundException, CannotCompileException
 /*     */   {
 /*  52 */     CtClass genadvisor = ((GeneratedAdvisorInstrumentor)this.).getGenadvisor();
 /*  53 */     String ciname = addConstructionInfoField(4, genadvisorconstructorindex);
 /*     */ 
 /*  59 */     addJoinpoint(constructorcinameindex);
 /*     */ 
 /*  61 */     long constructorHash = JavassistMethodHashing.constructorHash(constructor);
 /*  62 */     ((GeneratedAdvisorInstrumentor)this.).initialiseConstructionInfoField(cinameindexconstructorHash);
 /*     */   }
 /*     */ 
 /*     */   private void addJoinpoint(CtConstructor constructorString cinameint indexthrows CannotCompileException, NotFoundException
 /*     */   {
 /*  67 */     CtClass clazz = constructor.getDeclaringClass();
 /*  68 */     CtClass joinpoint = createJoinpointClass(clazzconstructorcinameindex);
 /*  69 */     CtClass genadvisor = ((GeneratedAdvisorInstrumentor)this.).getGenadvisor();
 /*  70 */     CtField field = new CtField(joinpoint, ConstructionJoinPointGenerator.getGeneratedJoinPointFieldName(clazz.getSimpleName(), index), genadvisor);
 /*     */ 
 /*  74 */     field.setModifiers(4);
 /*  75 */     genadvisor.addField(field);
 /*     */   }
 /*     */ 
 /*     */   private CtClass createJoinpointClass(CtClass clazz, CtConstructor constructorString cinameint indexthrows CannotCompileException, NotFoundException
 /*     */   {
 /*  80 */     return ConstructionJoinPointGenerator.createJoinpointBaseClass((GeneratedAdvisorInstrumentor)this.clazzconstructorcinameindex);
 /*     */   }
 /*     */ 
 /*     */   protected void generateNotMatchedConstructionInfoField(CtConstructor constructorint index)
 /*     */     throws NotFoundException, CannotCompileException
 /*     */   {
 /*  91 */     generateConstructionInfoField(constructorindex);
 /*     */   }
 /*     */ 
 /*     */   protected boolean addInfoAsWeakReference()
 /*     */   {
 /*  96 */     return false;
 /*     */   }
 /*     */ 
 /*     */   public static String constructionFactory(String className)
 /*     */   {
 /* 101 */     if (className.indexOf('.') >= 0) throw new RuntimeException("constructorFactory() takes a simple class name:" + className);
 /* 102 */     return className + "_construction_" + "$aop";
 /*     */   }
 /*     */ 
 /*     */   protected void insertInterception(CtConstructor constructorint indexthrows Exception
 /*     */   {
 /* 107 */     String constructionWrapperName = constructor.getDeclaringClass().getSimpleName() + "_con_" + "$aop";
 /*     */ 
 /* 109 */     String body = createInterceptingWrapperBody(constructorindex);
 /* 110 */     CtMethod wrapper = createWrapperMethod(constructorconstructionWrapperNamebody);
 /* 111 */     insertWrapperCallInCtor(constructorconstructionWrapperName);
 /*     */   }
 /*     */ 
 /*     */   private CtMethod createWrapperMethod(CtConstructor constructorString wrapperNameString body)
 /*     */     throws CannotCompileException, NotFoundException
 /*     */   {
 /* 117 */     CtClass genadvisor = ((GeneratedAdvisorInstrumentor)this.).getGenadvisor();
 /* 118 */     CtClass[] params = constructor.getParameterTypes();
 /* 119 */     CtClass[] wrapperParams = new CtClass[params.length + 1];
 /* 120 */     wrapperParams[0] = constructor.getDeclaringClass();
 /* 121 */     System.arraycopy(params, 0, wrapperParams, 1, params.length);
 /*     */ 
 /* 123 */     CtMethod wrapper = CtNewMethod.make(CtClass.voidType, wrapperNamewrapperParamsconstructor.getExceptionTypes(), bodygenadvisor);
 /*     */ 
 /* 130 */     genadvisor.addMethod(wrapper);
 /* 131 */     return wrapper;
 /*     */   }
 /*     */ 
 /*     */   private void insertWrapperCallInCtor(CtConstructor constructorString wrapperNamethrows NotFoundException, CannotCompileException
 /*     */   {
 /* 136 */     String wrapperCall = "((" + GeneratedAdvisorInstrumentor.getAdvisorFQN(constructor.getDeclaringClass()) + ")" + "getCurrentAdvisor$aop()" + ")." + wrapperName + "(this" + (constructor.getParameterTypes().length == 0 ? "" : ", $$") + ");";
 /*     */ 
 /* 139 */     constructor.insertAfter(wrapperCallfalse);
 /*     */   }
 /*     */ 
 /*     */   private String createInterceptingWrapperBody(CtConstructor constructorint indexthrows NotFoundException, CannotCompileException
 /*     */   {
 /* 144 */     String joinpointName = ConstructionJoinPointGenerator.getGeneratedJoinPointFieldName(constructor.getDeclaringClass().getSimpleName(), index);
 /* 145 */     String infoName = getConstructionInfoFieldName(constructor.getDeclaringClass().getSimpleName(), index);
 /* 146 */     String code = "{   if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" + "   {" + "      super." + "generateJoinPointClass" + "(" + infoName + ");" + "   }" + "   if (" + joinpointName + " != null)" + "   { " + "    " + joinpointName + "." + "invokeJoinpoint" + "($$);" + "   }" + "}";
 /*     */ 
/* 158 */     return code;
/*     */   }
/*     */ }
/* Location:           /home/mnovotny/projects/EMBEDDED_JBOSS_BETA3_COMMUNITY/embedded/output/lib/embedded-jboss/lib/jboss-embedded-all.jar
 * Qualified Name:     org.jboss.aop.instrument.GeneratedAdvisorConstructionTransformer
 * JD-Core Version:    0.6.0
 */
New to GrepCode? Check out our FAQ X