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