001: package com.bm.ejb3metadata.annotations.analyzer;
002:
003: import org.ejb3unit.asm.Type;
004:
005: import com.bm.ejb3metadata.annotations.impl.JEjbEJB;
006: import com.bm.ejb3metadata.annotations.metadata.interfaces.IEjbEJB;
007:
008: /**
009: * This class manages the handling of @{@link javax.ejb.EJB} annotation.
010: * @param <T> An implementation of IAnnotationEJB interface.
011: * @author Daniel Wiese
012: */
013: public class JavaxEjbEJBVisitor<T extends IEjbEJB> extends
014: AbsAnnotationVisitor<T> implements AnnotationType {
015:
016: /**
017: * Name attribute of the annotation.
018: */
019: private static final String NAME = "name";
020:
021: /**
022: * Bean interface attribute of the annotation.
023: */
024: private static final String BEAN_INTERFACE = "beanInterface";
025:
026: /**
027: * Bean name attribute of the annotation.
028: */
029: private static final String BEAN_NAME = "beanName";
030:
031: /**
032: * Mapped name attribute of the annotation.
033: */
034: private static final String MAPPED_NAME = "mappedName";
035:
036: /**
037: * Type of annotation.
038: */
039: public static final String TYPE = "Ljavax/ejb/EJB;";
040:
041: /**
042: * Internal object used representing @{@link javax.ejb.EJB} annotation.
043: */
044: private JEjbEJB jEjbEJB = null;
045:
046: /**
047: * Constructor.
048: * @param annotationMetadata linked to a class or method metadata
049: */
050: public JavaxEjbEJBVisitor(final T annotationMetadata) {
051: super (annotationMetadata);
052: jEjbEJB = new JEjbEJB();
053: }
054:
055: /**
056: * Visits a primitive value of the annotation.<br>
057: * @param name the value name.
058: * @param value the actual value, whose type must be {@link Byte},
059: * {@link Boolean}, {@link Character}, {@link Short},
060: * {@link Integer}, {@link Long}, {@link Float}, {@link Double},
061: * {@link String} or {@link org.ejb3unit.asm.Type}.
062: */
063: @Override
064: public void visit(final String name, final Object value) {
065: if (name.equals(NAME)) {
066: jEjbEJB.setName((String) value);
067: } else if (name.equals(BEAN_INTERFACE)) {
068: Type type = (Type) value;
069: jEjbEJB.setBeanInterface(type.getClassName());
070: } else if (name.equals(BEAN_NAME)) {
071: jEjbEJB.setBeanName((String) value);
072: } else if (name.equals(MAPPED_NAME)) {
073: jEjbEJB.setMappedName((String) value);
074: }
075: }
076:
077: /**
078: * Visits the end of the annotation. <br>
079: * Creates the object and store it.
080: */
081: @Override
082: public void visitEnd() {
083: // add object
084: getAnnotationMetadata().setJEjbEJB(jEjbEJB);
085: }
086:
087: /**
088: * @return type of the annotation (its description)
089: */
090: public String getType() {
091: return TYPE;
092: }
093:
094: /**
095: * @return Internal object used representing @{@link javax.ejb.EJB} annotation.
096: */
097: protected JEjbEJB getJEjbEJB() {
098: return jEjbEJB;
099: }
100:
101: /**
102: * Sets the jEjbEJB object.
103: * @param jEjbEJB the object which replaced the previous one.
104: */
105: protected void setJEjbEJB(final JEjbEJB jEjbEJB) {
106: this.jEjbEJB = jEjbEJB;
107: }
108:
109: }
|