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