1 4 5 package com.tc.aspectwerkz.definition.deployer; 6 7 import com.tc.aspectwerkz.DeploymentModel; 8 import com.tc.aspectwerkz.annotation.AspectAnnotationParser; 9 import com.tc.aspectwerkz.aspect.AdviceType; 10 import com.tc.aspectwerkz.definition.AspectDefinition; 11 import com.tc.aspectwerkz.definition.DefinitionParserHelper; 12 import com.tc.aspectwerkz.definition.SystemDefinition; 13 import com.tc.aspectwerkz.reflect.impl.asm.AsmClassInfo; 14 import com.tc.aspectwerkz.reflect.ClassInfo; 15 import com.tc.aspectwerkz.reflect.MethodInfo; 16 import com.tc.aspectwerkz.transform.inlining.AspectModelManager; 17 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 27 public class AspectDefinitionBuilder implements DefinitionBuilder { 28 private final List m_advices = new ArrayList (); 29 private final List m_pointcuts = new ArrayList (); 30 private final AspectDefinition m_aspectDef; 31 private final ClassInfo m_classInfo; 32 private final SystemDefinition m_systemDef; 33 34 public AspectDefinitionBuilder(final String aspectClass, 35 final DeploymentModel deploymentModel, 36 final String containerClassName, 37 final SystemDefinition systemDef, 38 final ClassLoader loader) { 39 m_classInfo = AsmClassInfo.getClassInfo(aspectClass, loader); 40 m_aspectDef = new AspectDefinition(aspectClass, m_classInfo, systemDef); 41 m_aspectDef.setDeploymentModel(deploymentModel); 42 m_aspectDef.setContainerClassName(containerClassName); 43 m_systemDef = systemDef; 44 AspectModelManager.defineAspect(m_classInfo, m_aspectDef, loader); 45 try { 46 AspectAnnotationParser.parse(m_classInfo, m_aspectDef, loader); 47 } catch(Throwable t) { 48 System.err.println("### Unable to retrieve annotation data for "+aspectClass+"; "+t.toString()); 49 } 50 } 51 52 56 public void addAdvice( 57 final AdviceType type, 58 final String pointcut, 59 final String fqn) { 60 addAdvice(type.toString(), pointcut, fqn); 61 } 62 63 public void addAdvice( 64 final String type, 65 final String pointcut, 66 final String fqn) { 67 MethodInfo methodInfo = DefinitionParserHelper.createMethodInfoForAdviceFQN(fqn, m_aspectDef, m_classInfo); 68 m_advices.add(new AdviceDefinitionBuilder(fqn, type, pointcut, methodInfo, m_aspectDef)); 69 } 70 71 public void addPointcut(final String name, final String expression) { 72 m_pointcuts.add(new PointcutDefinitionBuilder(name, expression, m_aspectDef)); 73 } 74 75 public void build() { 76 for (Iterator it = m_advices.iterator(); it.hasNext();) { 77 ((DefinitionBuilder) it.next()).build(); 78 } 79 for (Iterator it = m_pointcuts.iterator(); it.hasNext();) { 80 ((DefinitionBuilder) it.next()).build(); 81 } 82 m_systemDef.addAspect(m_aspectDef); 83 } 84 85 public AspectDefinition getAspectDefinition() { 86 return m_aspectDef; 87 } 88 } 89 | Popular Tags |