01: /************1**************************************************************************
02: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package org.codehaus.aspectwerkz.annotation;
08:
09: import org.codehaus.aspectwerkz.definition.MixinDefinition;
10: import org.codehaus.aspectwerkz.definition.SystemDefinition;
11: import org.codehaus.aspectwerkz.definition.DefinitionParserHelper;
12: import org.codehaus.aspectwerkz.reflect.ClassInfo;
13: import org.codehaus.aspectwerkz.annotation.instrumentation.asm.AsmAnnotations;
14: import org.codehaus.aspectwerkz.expression.ExpressionInfo;
15: import org.codehaus.aspectwerkz.expression.ExpressionNamespace;
16: import org.codehaus.aspectwerkz.DeploymentModel;
17: import org.codehaus.aspectwerkz.DeploymentModel;
18:
19: import java.util.Iterator;
20: import java.util.List;
21:
22: /**
23: * Extracts the mixin annotations from the class files and creates a meta-data representation of them.
24: *
25: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
26: */
27: public class MixinAnnotationParser {
28:
29: /**
30: * The sole instance.
31: */
32: private final static MixinAnnotationParser INSTANCE = new MixinAnnotationParser();
33:
34: /**
35: * Private constructor to prevent subclassing.
36: */
37: private MixinAnnotationParser() {
38: }
39:
40: /**
41: * Parse the attributes and create and return a meta-data representation of them.
42: *
43: * @param classInfo the class to extract attributes from
44: * @param mixinDef the mixin definition
45: */
46: public static void parse(final ClassInfo classInfo,
47: final MixinDefinition mixinDef) {
48: INSTANCE.doParse(classInfo, mixinDef);
49: }
50:
51: /**
52: * Parse the attributes and create and return a meta-data representation of them.
53: *
54: * @param classInfo the class to extract attributes from
55: * @param mixinDef the mixin definition
56: */
57: private void doParse(final ClassInfo classInfo,
58: final MixinDefinition mixinDef) {
59: if (classInfo == null) {
60: throw new IllegalArgumentException(
61: "class to parse can not be null");
62: }
63: if (classInfo == null) {
64: throw new IllegalArgumentException("class can not be null");
65: }
66: final SystemDefinition systemDef = mixinDef
67: .getSystemDefinition();
68: final List annotations = AsmAnnotations.getAnnotations(
69: AnnotationConstants.MIXIN, classInfo);
70: for (Iterator iterator = annotations.iterator(); iterator
71: .hasNext();) {
72: Mixin annotation = (Mixin) iterator.next();
73: if (annotation != null) {
74: String expression = AspectAnnotationParser
75: .getExpressionElseValue(annotation.value(),
76: annotation.pointcut());
77: final ExpressionInfo expressionInfo = new ExpressionInfo(
78: expression, systemDef.getUuid());
79: ExpressionNamespace
80: .getNamespace(systemDef.getUuid())
81: .addExpressionInfo(
82: DefinitionParserHelper.EXPRESSION_PREFIX
83: + expression.hashCode(),
84: expressionInfo);
85: mixinDef.addExpressionInfo(expressionInfo);
86: mixinDef.setTransient(annotation.isTransient());
87: if (annotation.deploymentModel() != null) {
88: mixinDef.setDeploymentModel(DeploymentModel
89: .getDeploymentModelFor(annotation
90: .deploymentModel()));
91: }
92: }
93: }
94: }
95: }
|