001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: JavaxEjbMessageDrivenVisitor.java 2057 2007-11-21 15:35:32Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.deployment.annotations.analyzer.classes;
025:
026: import static org.ow2.easybeans.deployment.annotations.ClassType.MDB;
027:
028: import org.ow2.easybeans.asm.AnnotationVisitor;
029: import org.ow2.easybeans.asm.Type;
030: import org.ow2.easybeans.asm.commons.EmptyVisitor;
031:
032: import org.ow2.easybeans.deployment.annotations.analyzer.AnnotationType;
033: import org.ow2.easybeans.deployment.annotations.impl.JActivationConfigProperty;
034: import org.ow2.easybeans.deployment.annotations.impl.JMessageDriven;
035: import org.ow2.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
036:
037: /**
038: * This class manages the handling of @{@link javax.ejb.MessageDriven}
039: * annotation.
040: * @author Florent Benoit
041: */
042: public class JavaxEjbMessageDrivenVisitor extends
043: AbsCommonEjbVisitor<JMessageDriven> implements AnnotationType {
044:
045: /**
046: * Type of annotation.
047: */
048: public static final String TYPE = "Ljavax/ejb/MessageDriven;";
049:
050: /**
051: * messageListenerInterface attribute of the annotation.
052: */
053: private static final String MESSAGE_LISTENER_INTERFACE = "messageListenerInterface";
054:
055: /**
056: * activationConfig attribute of the annotation.
057: */
058: private static final String ACTIVATION_CONFIG = "activationConfig";
059:
060: /**
061: * Message listener Interface.
062: */
063: private String messageListenerInterface = null;
064:
065: /**
066: * Constructor.
067: * @param classAnnotationMetadata linked to a class metadata
068: */
069: public JavaxEjbMessageDrivenVisitor(
070: final ClassAnnotationMetadata classAnnotationMetadata) {
071: super (classAnnotationMetadata);
072: }
073:
074: /**
075: * Visits a primitive value of the annotation.<br>
076: * @param name the value name.
077: * @param value the actual value, whose type must be {@link Byte},
078: * {@link Boolean}, {@link Character}, {@link Short},
079: * {@link Integer}, {@link Long}, {@link Float}, {@link Double},
080: * {@link String} or {@link Type}.
081: */
082: @Override
083: public void visit(final String name, final Object value) {
084: super .visit(name, value);
085: if (name.equals(MESSAGE_LISTENER_INTERFACE)) {
086: this .messageListenerInterface = ((Type) value)
087: .getInternalName();
088: }
089: }
090:
091: /**
092: * Visits an enumeration value of the annotation.
093: * @param name the value name.
094: * @param desc the class descriptor of the enumeration class.
095: * @param value the actual enumeration value.
096: */
097: @Override
098: public void visitEnum(final String name, final String desc,
099: final String value) {
100:
101: }
102:
103: /**
104: * Visits a nested annotation value of the annotation.
105: * @param name the value name.
106: * @param desc the class descriptor of the nested annotation class.
107: * @return a non null visitor to visit the actual nested annotation value.
108: * <i>The nested annotation value must be fully visited before
109: * calling other methods on this annotation visitor</i>.
110: */
111: @Override
112: public AnnotationVisitor visitAnnotation(final String name,
113: final String desc) {
114: return this ;
115: }
116:
117: /**
118: * Visits an array value of the annotation.
119: * @param name the value name.
120: * @return a non null visitor to visit the actual array value elements. The
121: * 'name' parameters passed to the methods of this visitor are
122: * ignored. <i>All the array values must be visited before calling
123: * other methods on this annotation visitor</i>.
124: */
125: @Override
126: public AnnotationVisitor visitArray(final String name) {
127: if (name.equals(ACTIVATION_CONFIG)) {
128: return new ActivationConfigPropertyVisitor();
129: }
130: return this ;
131: }
132:
133: /**
134: * Visits the end of the annotation. Creates the object and store it
135: */
136: @Override
137: public void visitEnd() {
138: super .visitEnd();
139:
140: // message listener interface
141: getJCommonBean().setMessageListenerInterface(
142: messageListenerInterface);
143:
144: // Set type
145: getAnnotationMetadata().setClassType(MDB);
146:
147: }
148:
149: /**
150: * @return type of the annotation (its description)
151: */
152: public String getType() {
153: return TYPE;
154: }
155:
156: /**
157: * Classes manages the parsing of activationConfig[] array of @{@link javax.ejb.MessageDriven}
158: * annotation.
159: * @author Florent Benoit
160: */
161: class ActivationConfigPropertyVisitor extends EmptyVisitor {
162:
163: /**
164: * Attribute for property name.
165: */
166: private static final String PROPERTY_NAME = "propertyName";
167:
168: /**
169: * Attribute for property value.
170: */
171: private static final String PROPERTY_VALUE = "propertyValue";
172:
173: /**
174: * Property name.
175: */
176: private String propertyName = null;
177:
178: /**
179: * Property value.
180: */
181: private String propertyValue = null;
182:
183: /**
184: * Visits a primitive value of the annotation.
185: * @param name the value name.
186: * @param value the actual value, whose type must be {@link Byte},
187: * {@link Boolean}, {@link Character}, {@link Short},
188: * {@link Integer}, {@link Long}, {@link Float},
189: * {@link Double}, {@link String} or {@link Type}.
190: */
191: @Override
192: public void visit(final String name, final Object value) {
193: if (name.equals(PROPERTY_NAME)) {
194: propertyName = (String) value;
195: } else if (name.equals(PROPERTY_VALUE)) {
196: propertyValue = (String) value;
197: }
198: }
199:
200: /**
201: * Visits the end of the annotation. Creates the object and store it
202: */
203: @Override
204: public void visitEnd() {
205: // Add an activation property
206: JActivationConfigProperty jActivationConfigProperty = new JActivationConfigProperty(
207: propertyName, propertyValue);
208: getJCommonBean().addActivationConfigProperty(
209: jActivationConfigProperty);
210:
211: }
212: }
213:
214: /**
215: * @return the object representing common bean.
216: */
217: @Override
218: public JMessageDriven getJCommonBean() {
219: JMessageDriven jMessageDriven = getAnnotationMetadata()
220: .getJMessageDriven();
221: if (jMessageDriven == null) {
222: jMessageDriven = new JMessageDriven();
223: getAnnotationMetadata().setJMessageDriven(jMessageDriven);
224: }
225: return jMessageDriven;
226: }
227:
228: }
|