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