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: JavaxEjbEJBsVisitor.java 2057 2007-11-21 15:35:32Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.deployment.annotations.analyzer.classes;
025:
026: import java.util.ArrayList;
027: import java.util.List;
028:
029: import org.ow2.easybeans.deployment.annotations.analyzer.JavaxEjbEJBVisitor;
030: import org.ow2.easybeans.deployment.annotations.impl.JEjbEJB;
031: import org.ow2.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
032:
033: /**
034: * This class manages the handling of @{@link javax.ejb.EJBs} annotation.
035: * @author Florent Benoit
036: */
037: public class JavaxEjbEJBsVisitor extends
038: JavaxEjbEJBVisitor<ClassAnnotationMetadata> {
039:
040: /**
041: * Type of annotation.
042: */
043: public static final String TYPE = "Ljavax/ejb/EJBs;";
044:
045: /**
046: * List of jEjbEJB object.
047: */
048: private List<JEjbEJB> jEjbEJBs = null;
049:
050: /**
051: * Object is added to the list.
052: */
053: private boolean isAdded = false;
054:
055: /**
056: * Constructor.
057: * @param annotationMetadata linked to a class or method metadata
058: */
059: public JavaxEjbEJBsVisitor(
060: final ClassAnnotationMetadata annotationMetadata) {
061: super (annotationMetadata);
062: jEjbEJBs = new ArrayList<JEjbEJB>();
063: }
064:
065: /**
066: * Visits a primitive value of the annotation.<br>
067: * @param name the value name.
068: * @param value the actual value, whose type must be {@link Byte},
069: * {@link Boolean}, {@link Character}, {@link Short},
070: * {@link Integer}, {@link Long}, {@link Float}, {@link Double},
071: * {@link String} or {@link org.ow2.easybeans.asm.Type}.
072: */
073: @Override
074: public void visit(final String name, final Object value) {
075: // list not empty, need to create another reference
076: // at the first item found
077: if (jEjbEJBs.size() > 0 && isAdded) {
078: setJEjbEJB(new JEjbEJB());
079: isAdded = false;
080: }
081:
082: // do super code
083: super .visit(name, value);
084: }
085:
086: /**
087: * Visits the end of the annotation. <br>
088: * Creates the object and store it.
089: */
090: @Override
091: public void visitEnd() {
092: // add object in the list
093: if (!isAdded) {
094: jEjbEJBs.add(getJEjbEJB());
095: isAdded = true;
096: }
097:
098: // update list
099: getAnnotationMetadata().setJEjbEJBs(jEjbEJBs);
100: }
101:
102: /**
103: * @return type of the annotation (its description)
104: */
105: @Override
106: public String getType() {
107: return TYPE;
108: }
109:
110: }
|