KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > annotation > MixinAnnotationParser


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 package com.tc.aspectwerkz.annotation;
5
6
7 import com.tc.aspectwerkz.DeploymentModel;
8 import com.tc.aspectwerkz.expression.ExpressionInfo;
9 import com.tc.aspectwerkz.expression.ExpressionNamespace;
10 import com.tc.aspectwerkz.reflect.ClassInfo;
11 import com.tc.aspectwerkz.definition.DefinitionParserHelper;
12 import com.tc.aspectwerkz.definition.MixinDefinition;
13 import com.tc.aspectwerkz.definition.SystemDefinition;
14
15 /**
16  * Extracts the mixin annotations from the class files and creates a meta-data representation of them.
17  *
18  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
19  */

20 public class MixinAnnotationParser {
21
22   /**
23    * The sole instance.
24    */

25   private final static MixinAnnotationParser INSTANCE = new MixinAnnotationParser();
26
27   /**
28    * Private constructor to prevent subclassing.
29    */

30   private MixinAnnotationParser() {
31   }
32
33   /**
34    * Parse the attributes and create and return a meta-data representation of them.
35    *
36    * @param classInfo the class to extract attributes from
37    * @param mixinDef the mixin definition
38    */

39   public static void parse(final ClassInfo classInfo, 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, final MixinDefinition mixinDef) {
50     if (classInfo == null) {
51       throw new IllegalArgumentException JavaDoc("class to parse can not be null");
52     }
53     final SystemDefinition systemDef = mixinDef.getSystemDefinition();
54     com.tc.aspectwerkz.annotation.Mixin annotation = (Mixin) AsmAnnotations.getAnnotation(AnnotationConstants.MIXIN, classInfo);
55     if (annotation != null) {
56       String JavaDoc expression = AspectAnnotationParser.getExpressionElseValue(
57               annotation.value(), annotation.pointcut()
58       );
59       final ExpressionInfo expressionInfo = new ExpressionInfo(expression, systemDef.getUuid());
60       ExpressionNamespace.getNamespace(systemDef.getUuid()).addExpressionInfo(
61               DefinitionParserHelper.EXPRESSION_PREFIX + expression.hashCode(),
62               expressionInfo
63       );
64       mixinDef.addExpressionInfo(expressionInfo);
65       mixinDef.setTransient(annotation.isTransient());
66       if (annotation.deploymentModel() != null) {
67         mixinDef.setDeploymentModel(DeploymentModel.getDeploymentModelFor(annotation.deploymentModel()));
68       }
69     }
70   }
71 }
Popular Tags