01: package com.bm.ejb3metadata.annotations.analyzer;
02:
03: import com.bm.ejb3metadata.annotations.impl.JavaxPersistenceUnit;
04: import com.bm.ejb3metadata.annotations.metadata.interfaces.IPersistenceUnit;
05:
06: /**
07: * This class manages the handling of @{@link javax.persistence.PersistenceUnit}
08: * annotation.
09: * @param <T> An implementation of IPersistenceUnit interface.
10: * @author Daniel Wiese
11: */
12: public class JavaxPersistencePersistenceUnitVisitor<T extends IPersistenceUnit>
13: extends AbsAnnotationVisitor<T> implements AnnotationType {
14:
15: /**
16: * Type of annotation.
17: */
18: public static final String TYPE = "Ljavax/persistence/PersistenceUnit;";
19:
20: /**
21: * name attribute of the annotation.
22: */
23: private static final String NAME = "name";
24:
25: /**
26: * UnitName attribute of the annotation.
27: */
28: private static final String UNIT_NAME = "unitName";
29:
30: /**
31: * Persistence context information.
32: */
33: private JavaxPersistenceUnit javaxPersistenceUnit = null;
34:
35: /**
36: * Constructor.
37: * @param annotationMetadata linked to a class or method or field metadata
38: */
39: public JavaxPersistencePersistenceUnitVisitor(
40: final T annotationMetadata) {
41: super (annotationMetadata);
42: javaxPersistenceUnit = new JavaxPersistenceUnit();
43: }
44:
45: /**
46: * Visits a primitive value of the annotation.<br>
47: * @param name the value name.
48: * @param value the actual value, whose type must be {@link Byte},
49: * {@link Boolean}, {@link Character}, {@link Short},
50: * {@link Integer}, {@link Long}, {@link Float}, {@link Double},
51: * {@link String} or {@link org.ejb3unit.asm.Type}.
52: */
53: @Override
54: public void visit(final String name, final Object value) {
55: if (NAME.equals(name)) {
56: javaxPersistenceUnit.setName((String) value);
57: } else if (name.equals(UNIT_NAME)) {
58: javaxPersistenceUnit.setUnitName((String) value);
59: }
60: }
61:
62: /**
63: * @return Internal object used representing @{@link javax.persistence.PersistenceUnit} annotation.
64: */
65: protected JavaxPersistenceUnit getJavaxPersistenceUnit() {
66: return javaxPersistenceUnit;
67: }
68:
69: /**
70: * Sets the javaxPersistenceUnit object.
71: * @param javaxPersistenceUnit the object which replaced the previous one.
72: */
73: protected void setjavaxPersistenceUnit(
74: final JavaxPersistenceUnit javaxPersistenceUnit) {
75: this .javaxPersistenceUnit = javaxPersistenceUnit;
76: }
77:
78: /**
79: * Visits the end of the annotation.<br>
80: * Creates the object and store it.
81: */
82: @Override
83: public void visitEnd() {
84: // set flag on field
85: getAnnotationMetadata().setJavaxPersistenceUnit(
86: javaxPersistenceUnit);
87: }
88:
89: /**
90: * @return type of the annotation (its description)
91: */
92: public String getType() {
93: return TYPE;
94: }
95:
96: }
|