KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > annotation > MixinAnnotationParser


1 /************1**************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package org.codehaus.aspectwerkz.annotation;
9
10 import org.codehaus.aspectwerkz.definition.MixinDefinition;
11 import org.codehaus.aspectwerkz.definition.SystemDefinition;
12 import org.codehaus.aspectwerkz.definition.DefinitionParserHelper;
13 import org.codehaus.aspectwerkz.reflect.ClassInfo;
14 import org.codehaus.aspectwerkz.annotation.instrumentation.asm.AsmAnnotations;
15 import org.codehaus.aspectwerkz.expression.ExpressionInfo;
16 import org.codehaus.aspectwerkz.expression.ExpressionNamespace;
17 import org.codehaus.aspectwerkz.DeploymentModel;
18 import org.codehaus.aspectwerkz.DeploymentModel;
19
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22
23 /**
24  * Extracts the mixin annotations from the class files and creates a meta-data representation of them.
25  *
26  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
27  */

28 public class MixinAnnotationParser {
29
30     /**
31      * The sole instance.
32      */

33     private final static MixinAnnotationParser INSTANCE = new MixinAnnotationParser();
34
35     /**
36      * Private constructor to prevent subclassing.
37      */

38     private MixinAnnotationParser() {
39     }
40
41     /**
42      * Parse the attributes and create and return a meta-data representation of them.
43      *
44      * @param classInfo the class to extract attributes from
45      * @param mixinDef the mixin definition
46      */

47     public static void parse(final ClassInfo classInfo, 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, final MixinDefinition mixinDef) {
58         if (classInfo == null) {
59             throw new IllegalArgumentException JavaDoc("class to parse can not be null");
60         }
61         if (classInfo == null) {
62             throw new IllegalArgumentException JavaDoc("class can not be null");
63         }
64         final SystemDefinition systemDef = mixinDef.getSystemDefinition();
65         final List JavaDoc annotations = AsmAnnotations.getAnnotations(AnnotationConstants.MIXIN, classInfo);
66         for (Iterator JavaDoc iterator = annotations.iterator(); iterator.hasNext();) {
67             Mixin annotation = (Mixin) iterator.next();
68             if (annotation != null) {
69                 String JavaDoc expression = AspectAnnotationParser.getExpressionElseValue(
70                         annotation.value(), annotation.pointcut()
71                 );
72                 final ExpressionInfo expressionInfo = new ExpressionInfo(expression, systemDef.getUuid());
73                 ExpressionNamespace.getNamespace(systemDef.getUuid()).addExpressionInfo(
74                         DefinitionParserHelper.EXPRESSION_PREFIX + expression.hashCode(),
75                         expressionInfo
76                 );
77                 mixinDef.addExpressionInfo(expressionInfo);
78                 mixinDef.setTransient(annotation.isTransient());
79                 if (annotation.deploymentModel() != null) {
80                     mixinDef.setDeploymentModel(DeploymentModel.getDeploymentModelFor(annotation.deploymentModel()));
81                 }
82             }
83         }
84     }
85 }
Popular Tags