KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > definition > deployer > AspectDefinitionBuilder


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 /**
23  * TODO document class
24  *
25  * @author Jonas Bonér
26  */

27 public class AspectDefinitionBuilder implements DefinitionBuilder {
28   private final List JavaDoc m_advices = new ArrayList JavaDoc();
29   private final List JavaDoc m_pointcuts = new ArrayList JavaDoc();
30   private final AspectDefinition m_aspectDef;
31   private final ClassInfo m_classInfo;
32   private final SystemDefinition m_systemDef;
33
34   public AspectDefinitionBuilder(final String JavaDoc aspectClass,
35                                  final DeploymentModel deploymentModel,
36                                  final String JavaDoc containerClassName,
37                                  final SystemDefinition systemDef,
38                                  final ClassLoader JavaDoc 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 JavaDoc t) {
48       System.err.println("### Unable to retrieve annotation data for "+aspectClass+"; "+t.toString());
49     }
50   }
51
52   /**
53    * @deprecated
54    * FIXME remove this method - does not work with after returning and after throwing - use the one below
55    */

56   public void addAdvice(
57       final AdviceType type,
58       final String JavaDoc pointcut,
59       final String JavaDoc fqn) {
60     addAdvice(type.toString(), pointcut, fqn);
61   }
62
63   public void addAdvice(
64       final String JavaDoc type,
65       final String JavaDoc pointcut,
66       final String JavaDoc 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 JavaDoc name, final String JavaDoc expression) {
72     m_pointcuts.add(new PointcutDefinitionBuilder(name, expression, m_aspectDef));
73   }
74
75   public void build() {
76     for (Iterator JavaDoc it = m_advices.iterator(); it.hasNext();) {
77       ((DefinitionBuilder) it.next()).build();
78     }
79     for (Iterator JavaDoc 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