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