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: package com.tc.aspectwerkz.annotation;
05:
06: import com.tc.aspectwerkz.DeploymentModel;
07: import com.tc.aspectwerkz.expression.ExpressionInfo;
08: import com.tc.aspectwerkz.expression.ExpressionNamespace;
09: import com.tc.aspectwerkz.reflect.ClassInfo;
10: import com.tc.aspectwerkz.definition.DefinitionParserHelper;
11: import com.tc.aspectwerkz.definition.MixinDefinition;
12: import com.tc.aspectwerkz.definition.SystemDefinition;
13:
14: /**
15: * Extracts the mixin annotations from the class files and creates a meta-data representation of them.
16: *
17: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
18: */
19: public class MixinAnnotationParser {
20:
21: /**
22: * The sole instance.
23: */
24: private final static MixinAnnotationParser INSTANCE = new MixinAnnotationParser();
25:
26: /**
27: * Private constructor to prevent subclassing.
28: */
29: private MixinAnnotationParser() {
30: }
31:
32: /**
33: * Parse the attributes and create and return a meta-data representation of them.
34: *
35: * @param classInfo the class to extract attributes from
36: * @param mixinDef the mixin definition
37: */
38: public static void parse(final ClassInfo classInfo,
39: final MixinDefinition mixinDef) {
40: INSTANCE.doParse(classInfo, mixinDef);
41: }
42:
43: /**
44: * Parse the attributes and create and return a meta-data representation of them.
45: *
46: * @param classInfo the class to extract attributes from
47: * @param mixinDef the mixin definition
48: */
49: private void doParse(final ClassInfo classInfo,
50: final MixinDefinition mixinDef) {
51: if (classInfo == null) {
52: throw new IllegalArgumentException(
53: "class to parse can not be null");
54: }
55: final SystemDefinition systemDef = mixinDef
56: .getSystemDefinition();
57: com.tc.aspectwerkz.annotation.Mixin annotation = (Mixin) AsmAnnotations
58: .getAnnotation(AnnotationConstants.MIXIN, classInfo);
59: if (annotation != null) {
60: String expression = AspectAnnotationParser
61: .getExpressionElseValue(annotation.value(),
62: annotation.pointcut());
63: final ExpressionInfo expressionInfo = new ExpressionInfo(
64: expression, systemDef.getUuid());
65: ExpressionNamespace.getNamespace(systemDef.getUuid())
66: .addExpressionInfo(
67: DefinitionParserHelper.EXPRESSION_PREFIX
68: + expression.hashCode(),
69: expressionInfo);
70: mixinDef.addExpressionInfo(expressionInfo);
71: mixinDef.setTransient(annotation.isTransient());
72: if (annotation.deploymentModel() != null) {
73: mixinDef.setDeploymentModel(DeploymentModel
74: .getDeploymentModelFor(annotation
75: .deploymentModel()));
76: }
77: }
78: }
79: }
|