KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > deployment > annotations > analyzer > JavaxPersistencePersistenceUnitVisitor


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JavaxPersistencePersistenceUnitVisitor.java 445 2006-05-10 16:28:59Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.deployment.annotations.analyzer;
27
28 import org.objectweb.easybeans.deployment.annotations.impl.JavaxPersistenceUnit;
29 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.IPersistenceUnit;
30
31 /**
32  * This class manages the handling of @{@link javax.persistence.PersistenceUnit}
33  * annotation.
34  * @param <T> An implementation of IPersistenceUnit interface.
35  * @author Florent Benoit
36  */

37 public class JavaxPersistencePersistenceUnitVisitor<T extends IPersistenceUnit> extends AbsAnnotationVisitor<T> implements
38         AnnotationType {
39
40     /**
41      * Type of annotation.
42      */

43     public static final String JavaDoc TYPE = "Ljavax/persistence/PersistenceUnit;";
44
45     /**
46      * name attribute of the annotation.
47      */

48     private static final String JavaDoc NAME = "name";
49
50     /**
51      * UnitName attribute of the annotation.
52      */

53     private static final String JavaDoc UNIT_NAME = "unitName";
54
55     /**
56      * Persistence context information.
57      */

58     private JavaxPersistenceUnit javaxPersistenceUnit = null;
59
60     /**
61      * Constructor.
62      * @param annotationMetadata linked to a class or method or field metadata
63      */

64     public JavaxPersistencePersistenceUnitVisitor(final T annotationMetadata) {
65         super(annotationMetadata);
66         javaxPersistenceUnit = new JavaxPersistenceUnit();
67     }
68
69     /**
70      * Visits a primitive value of the annotation.<br>
71      * @param name the value name.
72      * @param value the actual value, whose type must be {@link Byte},
73      * {@link Boolean}, {@link Character}, {@link Short},
74      * {@link Integer}, {@link Long}, {@link Float}, {@link Double},
75      * {@link String} or {@link org.objectweb.asm.Type}.
76      */

77     @Override JavaDoc
78     public void visit(final String JavaDoc name, final Object JavaDoc value) {
79         if (NAME.equals(name)) {
80             javaxPersistenceUnit.setName((String JavaDoc) value);
81         } else if (name.equals(UNIT_NAME)) {
82             javaxPersistenceUnit.setUnitName((String JavaDoc) value);
83         }
84     }
85
86     /**
87      * @return Internal object used representing &#64;{@link javax.persistence.PersistenceUnit} annotation.
88      */

89     protected JavaxPersistenceUnit getJavaxPersistenceUnit() {
90         return javaxPersistenceUnit;
91     }
92
93     /**
94      * Sets the javaxPersistenceUnit object.
95      * @param javaxPersistenceUnit the object which replaced the previous one.
96      */

97     protected void setjavaxPersistenceUnit(final JavaxPersistenceUnit javaxPersistenceUnit) {
98         this.javaxPersistenceUnit = javaxPersistenceUnit;
99     }
100
101
102     /**
103      * Visits the end of the annotation.<br>
104      * Creates the object and store it.
105      */

106     @Override JavaDoc
107     public void visitEnd() {
108         // set flag on field
109
getAnnotationMetadata().setJavaxPersistenceUnit(javaxPersistenceUnit);
110     }
111
112     /**
113      * @return type of the annotation (its description)
114      */

115     public String JavaDoc getType() {
116         return TYPE;
117     }
118
119 }
120
Popular Tags