01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04:
05: package com.tc.aspectwerkz.definition.deployer;
06:
07: import com.tc.aspectwerkz.DeploymentModel;
08: import com.tc.aspectwerkz.annotation.AspectAnnotationParser;
09: 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: /**
23: * TODO document class
24: *
25: * @author Jonas Bonér
26: */
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, final ClassLoader loader) {
38: m_classInfo = AsmClassInfo.getClassInfo(aspectClass, loader);
39: m_aspectDef = new AspectDefinition(aspectClass, m_classInfo,
40: systemDef);
41: m_aspectDef.setDeploymentModel(deploymentModel);
42: m_aspectDef.setContainerClassName(containerClassName);
43: m_systemDef = systemDef;
44: AspectModelManager.defineAspect(m_classInfo, m_aspectDef,
45: loader);
46: try {
47: AspectAnnotationParser.parse(m_classInfo, m_aspectDef,
48: loader);
49: } catch (Throwable t) {
50: System.err
51: .println("### Unable to retrieve annotation data for "
52: + aspectClass + "; " + t.toString());
53: }
54: }
55:
56: /**
57: * @deprecated
58: * FIXME remove this method - does not work with after returning and after throwing - use the one below
59: */
60: public void addAdvice(final AdviceType type, final String pointcut,
61: final String fqn) {
62: addAdvice(type.toString(), pointcut, fqn);
63: }
64:
65: public void addAdvice(final String type, final String pointcut,
66: final String fqn) {
67: MethodInfo methodInfo = DefinitionParserHelper
68: .createMethodInfoForAdviceFQN(fqn, m_aspectDef,
69: m_classInfo);
70: m_advices.add(new AdviceDefinitionBuilder(fqn, type, pointcut,
71: methodInfo, m_aspectDef));
72: }
73:
74: public void addPointcut(final String name, final String expression) {
75: m_pointcuts.add(new PointcutDefinitionBuilder(name, expression,
76: m_aspectDef));
77: }
78:
79: public void build() {
80: for (Iterator it = m_advices.iterator(); it.hasNext();) {
81: ((DefinitionBuilder) it.next()).build();
82: }
83: for (Iterator it = m_pointcuts.iterator(); it.hasNext();) {
84: ((DefinitionBuilder) it.next()).build();
85: }
86: m_systemDef.addAspect(m_aspectDef);
87: }
88:
89: public AspectDefinition getAspectDefinition() {
90: return m_aspectDef;
91: }
92: }
|