01: package com.bm.ejb3metadata.annotations.analyzer.classes;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05:
06: import com.bm.ejb3metadata.annotations.analyzer.JavaxAnnotationResourceVisitor;
07: import com.bm.ejb3metadata.annotations.impl.JAnnotationResource;
08: import com.bm.ejb3metadata.annotations.metadata.ClassAnnotationMetadata;
09:
10: /**
11: * This class manages the handling of @{@link javax.annotation.Resources} annotation.
12: * @author Daniel Wiese
13: */
14: public class JavaxAnnotationResourcesVisitor extends
15: JavaxAnnotationResourceVisitor<ClassAnnotationMetadata> {
16:
17: /**
18: * Type of annotation.
19: */
20: public static final String TYPE = "Ljavax/annotation/Resources;";
21:
22: /**
23: * List of jAnnotationResource object.
24: */
25: private List<JAnnotationResource> jAnnotationResources = null;
26:
27: /**
28: * Object is added to the list.
29: */
30: private boolean isAdded = false;
31:
32: /**
33: * Constructor.
34: * @param annotationMetadata linked to a class or method metadata
35: */
36: public JavaxAnnotationResourcesVisitor(
37: final ClassAnnotationMetadata annotationMetadata) {
38: super (annotationMetadata);
39: jAnnotationResources = new ArrayList<JAnnotationResource>();
40: }
41:
42: /**
43: * Visits a primitive value of the annotation.<br>
44: * @param name the value name.
45: * @param value the actual value, whose type must be {@link Byte},
46: * {@link Boolean}, {@link Character}, {@link Short},
47: * {@link Integer}, {@link Long}, {@link Float}, {@link Double},
48: * {@link String} or {@link org.ejb3unit.asm.Type}.
49: */
50: @Override
51: public void visit(final String name, final Object value) {
52: // list not empty, need to create another reference
53: // at the first item found
54: if (jAnnotationResources.size() > 0 && isAdded) {
55: setJAnnotationResource(new JAnnotationResource());
56: isAdded = false;
57: }
58:
59: // do super code
60: super .visit(name, value);
61: }
62:
63: /**
64: * Visits the end of the annotation. <br>
65: * Creates the object and store it.
66: */
67: @Override
68: public void visitEnd() {
69: // add object in the list
70: if (!isAdded) {
71: jAnnotationResources.add(getJAnnotationResource());
72: isAdded = true;
73: }
74:
75: // update list
76: getAnnotationMetadata().setJAnnotationResources(
77: jAnnotationResources);
78: }
79:
80: /**
81: * @return type of the annotation (its description)
82: */
83: @Override
84: public String getType() {
85: return TYPE;
86: }
87:
88: }
|