001: package com.bm.ejb3metadata.annotations.analyzer.classes;
002:
003: import static com.bm.ejb3metadata.annotations.ClassType.MDB;
004:
005: import org.ejb3unit.asm.AnnotationVisitor;
006: import org.ejb3unit.asm.Type;
007: import org.ejb3unit.asm.commons.EmptyVisitor;
008:
009: import com.bm.ejb3metadata.annotations.analyzer.AnnotationType;
010: import com.bm.ejb3metadata.annotations.impl.JActivationConfigProperty;
011: import com.bm.ejb3metadata.annotations.impl.JMessageDriven;
012: import com.bm.ejb3metadata.annotations.metadata.ClassAnnotationMetadata;
013:
014: /**
015: * This class manages the handling of @{@link javax.ejb.MessageDriven}
016: * annotation.
017: * @author Daniel Wiese
018: */
019: public class JavaxEjbMessageDrivenVisitor extends
020: AbsCommonEjbVisitor<JMessageDriven> implements AnnotationType {
021:
022: /**
023: * Type of annotation.
024: */
025: public static final String TYPE = "Ljavax/ejb/MessageDriven;";
026:
027: /**
028: * messageListenerInterface attribute of the annotation.
029: */
030: private static final String MESSAGE_LISTENER_INTERFACE = "messageListenerInterface";
031:
032: /**
033: * activationConfig attribute of the annotation.
034: */
035: private static final String ACTIVATION_CONFIG = "activationConfig";
036:
037: /**
038: * Message listener Interface.
039: */
040: private String messageListenerInterface = null;
041:
042: /**
043: * Constructor.
044: * @param classAnnotationMetadata linked to a class metadata
045: */
046: public JavaxEjbMessageDrivenVisitor(
047: final ClassAnnotationMetadata classAnnotationMetadata) {
048: super (classAnnotationMetadata);
049: }
050:
051: /**
052: * Visits a primitive value of the annotation.<br>
053: * @param name the value name.
054: * @param value the actual value, whose type must be {@link Byte},
055: * {@link Boolean}, {@link Character}, {@link Short},
056: * {@link Integer}, {@link Long}, {@link Float}, {@link Double},
057: * {@link String} or {@link Type}.
058: */
059: @Override
060: public void visit(final String name, final Object value) {
061: super .visit(name, value);
062: if (name.equals(MESSAGE_LISTENER_INTERFACE)) {
063: this .messageListenerInterface = ((Type) value)
064: .getInternalName();
065: }
066: }
067:
068: /**
069: * Visits an enumeration value of the annotation.
070: * @param name the value name.
071: * @param desc the class descriptor of the enumeration class.
072: * @param value the actual enumeration value.
073: */
074: @Override
075: public void visitEnum(final String name, final String desc,
076: final String value) {
077:
078: }
079:
080: /**
081: * Visits a nested annotation value of the annotation.
082: * @param name the value name.
083: * @param desc the class descriptor of the nested annotation class.
084: * @return a non null visitor to visit the actual nested annotation value.
085: * <i>The nested annotation value must be fully visited before
086: * calling other methods on this annotation visitor</i>.
087: */
088: @Override
089: public AnnotationVisitor visitAnnotation(final String name,
090: final String desc) {
091: return this ;
092: }
093:
094: /**
095: * Visits an array value of the annotation.
096: * @param name the value name.
097: * @return a non null visitor to visit the actual array value elements. The
098: * 'name' parameters passed to the methods of this visitor are
099: * ignored. <i>All the array values must be visited before calling
100: * other methods on this annotation visitor</i>.
101: */
102: @Override
103: public AnnotationVisitor visitArray(final String name) {
104: if (name.equals(ACTIVATION_CONFIG)) {
105: return new ActivationConfigPropertyVisitor();
106: }
107: return this ;
108: }
109:
110: /**
111: * Visits the end of the annotation. Creates the object and store it
112: */
113: @Override
114: public void visitEnd() {
115: super .visitEnd();
116:
117: // message listener interface
118: getJCommonBean().setMessageListenerInterface(
119: messageListenerInterface);
120:
121: // Set type
122: getAnnotationMetadata().setClassType(MDB);
123:
124: }
125:
126: /**
127: * @return type of the annotation (its description)
128: */
129: public String getType() {
130: return TYPE;
131: }
132:
133: /**
134: * Classes manages the parsing of activationConfig[] array of @{@link javax.ejb.MessageDriven}
135: * annotation.
136: * @author Florent Benoit
137: */
138: class ActivationConfigPropertyVisitor extends EmptyVisitor {
139:
140: /**
141: * Attribute for property name.
142: */
143: private static final String PROPERTY_NAME = "propertyName";
144:
145: /**
146: * Attribute for property value.
147: */
148: private static final String PROPERTY_VALUE = "propertyValue";
149:
150: /**
151: * Property name.
152: */
153: private String propertyName = null;
154:
155: /**
156: * Property value.
157: */
158: private String propertyValue = null;
159:
160: /**
161: * Visits a primitive value of the annotation.
162: * @param name the value name.
163: * @param value the actual value, whose type must be {@link Byte},
164: * {@link Boolean}, {@link Character}, {@link Short},
165: * {@link Integer}, {@link Long}, {@link Float},
166: * {@link Double}, {@link String} or {@link Type}.
167: */
168: @Override
169: public void visit(final String name, final Object value) {
170: if (name.equals(PROPERTY_NAME)) {
171: propertyName = (String) value;
172: } else if (name.equals(PROPERTY_VALUE)) {
173: propertyValue = (String) value;
174: }
175: }
176:
177: /**
178: * Visits the end of the annotation. Creates the object and store it
179: */
180: @Override
181: public void visitEnd() {
182: // Add an activation property
183: JActivationConfigProperty jActivationConfigProperty = new JActivationConfigProperty(
184: propertyName, propertyValue);
185: getJCommonBean().addActivationConfigProperty(
186: jActivationConfigProperty);
187:
188: }
189: }
190:
191: /**
192: * @return the object representing common bean.
193: */
194: @Override
195: public JMessageDriven getJCommonBean() {
196: JMessageDriven jMessageDriven = getAnnotationMetadata()
197: .getJMessageDriven();
198: if (jMessageDriven == null) {
199: jMessageDriven = new JMessageDriven();
200: getAnnotationMetadata().setJMessageDriven(jMessageDriven);
201: }
202: return jMessageDriven;
203: }
204:
205: }
|