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: JavaxEjbEJBVisitor.java 2059 2007-11-22 17:22:33Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.deployment.annotations.analyzer;
025:
026: import org.ow2.easybeans.asm.Type;
027:
028: import org.ow2.easybeans.deployment.annotations.impl.JEjbEJB;
029: import org.ow2.easybeans.deployment.annotations.metadata.interfaces.IEjbEJB;
030:
031: /**
032: * This class manages the handling of @{@link javax.ejb.EJB} annotation.
033: * @param <T> An implementation of IAnnotationEJB interface.
034: * @author Florent Benoit
035: */
036: public class JavaxEjbEJBVisitor<T extends IEjbEJB> extends
037: AbsAnnotationVisitor<T> implements AnnotationType {
038:
039: /**
040: * Name attribute of the annotation.
041: */
042: private static final String NAME = "name";
043:
044: /**
045: * Bean interface attribute of the annotation.
046: */
047: private static final String BEAN_INTERFACE = "beanInterface";
048:
049: /**
050: * Bean name attribute of the annotation.
051: */
052: private static final String BEAN_NAME = "beanName";
053:
054: /**
055: * Mapped name attribute of the annotation.
056: */
057: private static final String MAPPED_NAME = "mappedName";
058:
059: /**
060: * Type of annotation.
061: */
062: public static final String TYPE = "Ljavax/ejb/EJB;";
063:
064: /**
065: * Internal object used representing @{@link javax.ejb.EJB} annotation.
066: */
067: private JEjbEJB jEjbEJB = null;
068:
069: /**
070: * Constructor.
071: * @param annotationMetadata linked to a class or method metadata
072: */
073: public JavaxEjbEJBVisitor(final T annotationMetadata) {
074: super (annotationMetadata);
075: jEjbEJB = new JEjbEJB();
076: }
077:
078: /**
079: * Visits a primitive value of the annotation.<br>
080: * @param name the value name.
081: * @param value the actual value, whose type must be {@link Byte},
082: * {@link Boolean}, {@link Character}, {@link Short},
083: * {@link Integer}, {@link Long}, {@link Float}, {@link Double},
084: * {@link String} or {@link org.ow2.easybeans.asm.Type}.
085: */
086: @Override
087: public void visit(final String name, final Object value) {
088: if (name.equals(NAME)) {
089: jEjbEJB.setName((String) value);
090: } else if (name.equals(BEAN_INTERFACE)) {
091: Type type = (Type) value;
092: jEjbEJB.setBeanInterface(type.getClassName());
093: } else if (name.equals(BEAN_NAME)) {
094: jEjbEJB.setBeanName((String) value);
095: } else if (name.equals(MAPPED_NAME)) {
096: jEjbEJB.setMappedName((String) value);
097: }
098: }
099:
100: /**
101: * Visits the end of the annotation. <br>
102: * Creates the object and store it.
103: */
104: @Override
105: public void visitEnd() {
106: // add object
107: getAnnotationMetadata().setJEjbEJB(jEjbEJB);
108: }
109:
110: /**
111: * @return type of the annotation (its description)
112: */
113: public String getType() {
114: return TYPE;
115: }
116:
117: /**
118: * @return Internal object used representing @{@link javax.ejb.EJB} annotation.
119: */
120: protected JEjbEJB getJEjbEJB() {
121: return jEjbEJB;
122: }
123:
124: /**
125: * Sets the jEjbEJB object.
126: * @param jEjbEJB the object which replaced the previous one.
127: */
128: protected void setJEjbEJB(final JEjbEJB jEjbEJB) {
129: this.jEjbEJB = jEjbEJB;
130: }
131:
132: }
|