001: package com.bm.ejb3metadata.annotations.analyzer;
002:
003: import javax.persistence.PersistenceContextType;
004:
005: import com.bm.ejb3metadata.annotations.impl.JavaxPersistenceContext;
006: import com.bm.ejb3metadata.annotations.metadata.interfaces.IPersistenceContext;
007:
008: /**
009: * This class manages the handling of @{@link javax.persistence.PersistenceContext}
010: * annotation.
011: * @param <T> An implementation of IPersistenceContext interface.
012: * @author Daniel Wiese
013: */
014: public class JavaxPersistencePersistenceContextVisitor<T extends IPersistenceContext>
015: extends AbsAnnotationVisitor<T> implements AnnotationType {
016:
017: /**
018: * Type of annotation.
019: */
020: public static final String TYPE = "Ljavax/persistence/PersistenceContext;";
021:
022: /**
023: * name attribute of the annotation.
024: */
025: private static final String NAME = "name";
026:
027: /**
028: * UnitName attribute of the annotation.
029: */
030: private static final String UNIT_NAME = "unitName";
031:
032: /**
033: * Persistence Context type attribute of the annotation.
034: */
035: private static final String PERSISTENCECONTEXT_TYPE = "type";
036:
037: /**
038: * Transaction type.
039: */
040: private static final String PERSISTENCECONTEXT_TTRANSACTION_TYPE = "TRANSACTION";
041:
042: /**
043: * Persistence context information.
044: */
045: private JavaxPersistenceContext javaxPersistenceContext = null;
046:
047: /**
048: * Constructor.
049: * @param annotationMetadata linked to a class or method or field metadata
050: */
051: public JavaxPersistencePersistenceContextVisitor(
052: final T annotationMetadata) {
053: super (annotationMetadata);
054: javaxPersistenceContext = new JavaxPersistenceContext();
055: }
056:
057: /**
058: * Visits a primitive value of the annotation.<br>
059: * @param name the value name.
060: * @param value the actual value, whose type must be {@link Byte},
061: * {@link Boolean}, {@link Character}, {@link Short},
062: * {@link Integer}, {@link Long}, {@link Float}, {@link Double},
063: * {@link String} or {@link org.ejb3unit.asm.Type}.
064: */
065: @Override
066: public void visit(final String name, final Object value) {
067: if (UNIT_NAME.equals(name)) {
068: javaxPersistenceContext.setUnitName((String) value);
069: } else if (NAME.equals(name)) {
070: javaxPersistenceContext.setName((String) value);
071: }
072: }
073:
074: /**
075: * Visits an enumeration value of the annotation.
076: * @param name the value name.
077: * @param desc the class descriptor of the enumeration class.
078: * @param value the actual enumeration value.
079: */
080: @Override
081: public void visitEnum(final String name, final String desc,
082: final String value) {
083: if (name.equals(PERSISTENCECONTEXT_TYPE)) {
084: if (PERSISTENCECONTEXT_TTRANSACTION_TYPE.equals(value)) {
085: javaxPersistenceContext
086: .setType(PersistenceContextType.TRANSACTION);
087: } else {
088: javaxPersistenceContext
089: .setType(PersistenceContextType.EXTENDED);
090: }
091:
092: }
093: }
094:
095: /**
096: * @return Internal object used representing @{@link javax.persistence.PersistenceContext} annotation.
097: */
098: protected JavaxPersistenceContext getJavaxPersistenceContext() {
099: return javaxPersistenceContext;
100: }
101:
102: /**
103: * Sets the javaxPersistenceContext object.
104: * @param javaxPersistenceContext the object which replaced the previous one.
105: */
106: protected void setJavaxPersistenceContext(
107: final JavaxPersistenceContext javaxPersistenceContext) {
108: this .javaxPersistenceContext = javaxPersistenceContext;
109: }
110:
111: /**
112: * Visits the end of the annotation.<br>
113: * Creates the object and store it.
114: */
115: @Override
116: public void visitEnd() {
117: // set flag on field
118: getAnnotationMetadata().setJavaxPersistenceContext(
119: javaxPersistenceContext);
120: }
121:
122: /**
123: * @return type of the annotation (its description)
124: */
125: public String getType() {
126: return TYPE;
127: }
128:
129: }
|