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