KickJava   Java API By Example, From Geeks To Geeks.

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


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: JavaxPersistencePersistenceContextVisitor.java 445 2006-05-10 16:28:59Z benoitf $
23  * --------------------------------------------------------------------------
24  */

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

39 public class JavaxPersistencePersistenceContextVisitor<T extends IPersistenceContext> extends AbsAnnotationVisitor<T> implements
40         AnnotationType {
41
42     /**
43      * Type of annotation.
44      */

45     public static final String JavaDoc TYPE = "Ljavax/persistence/PersistenceContext;";
46
47     /**
48      * name attribute of the annotation.
49      */

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

56     private static final String JavaDoc UNIT_NAME = "unitName";
57
58     /**
59      * Persistence Context type attribute of the annotation.
60      */

61     private static final String JavaDoc PERSISTENCECONTEXT_TYPE = "type";
62
63     /**
64      * Transaction type.
65      */

66     private static final String JavaDoc PERSISTENCECONTEXT_TTRANSACTION_TYPE = "TRANSACTION";
67
68
69     /**
70      * Persistence context information.
71      */

72     private JavaxPersistenceContext javaxPersistenceContext = null;
73
74     /**
75      * Constructor.
76      * @param annotationMetadata linked to a class or method or field metadata
77      */

78     public JavaxPersistencePersistenceContextVisitor(final T annotationMetadata) {
79         super(annotationMetadata);
80         javaxPersistenceContext = new JavaxPersistenceContext();
81     }
82
83     /**
84      * Visits a primitive value of the annotation.<br>
85      * @param name the value name.
86      * @param value the actual value, whose type must be {@link Byte},
87      * {@link Boolean}, {@link Character}, {@link Short},
88      * {@link Integer}, {@link Long}, {@link Float}, {@link Double},
89      * {@link String} or {@link org.objectweb.asm.Type}.
90      */

91     @Override JavaDoc
92     public void visit(final String JavaDoc name, final Object JavaDoc value) {
93         if (UNIT_NAME.equals(name)) {
94             javaxPersistenceContext.setUnitName((String JavaDoc) value);
95         } else if (NAME.equals(name)) {
96             javaxPersistenceContext.setName((String JavaDoc) value);
97         }
98     }
99
100     /**
101      * Visits an enumeration value of the annotation.
102      * @param name the value name.
103      * @param desc the class descriptor of the enumeration class.
104      * @param value the actual enumeration value.
105      */

106     @Override JavaDoc
107     public void visitEnum(final String JavaDoc name, final String JavaDoc desc, final String JavaDoc value) {
108        if (name.equals(PERSISTENCECONTEXT_TYPE)) {
109             if (PERSISTENCECONTEXT_TTRANSACTION_TYPE.equals(value)) {
110                 javaxPersistenceContext.setType(PersistenceContextType.TRANSACTION);
111             } else {
112                 javaxPersistenceContext.setType(PersistenceContextType.EXTENDED);
113             }
114
115         }
116     }
117
118
119     /**
120      * @return Internal object used representing &#64;{@link javax.persistence.PersistenceContext} annotation.
121      */

122     protected JavaxPersistenceContext getJavaxPersistenceContext() {
123         return javaxPersistenceContext;
124     }
125
126     /**
127      * Sets the javaxPersistenceContext object.
128      * @param javaxPersistenceContext the object which replaced the previous one.
129      */

130     protected void setJavaxPersistenceContext(final JavaxPersistenceContext javaxPersistenceContext) {
131         this.javaxPersistenceContext = javaxPersistenceContext;
132     }
133
134     /**
135      * Visits the end of the annotation.<br>
136      * Creates the object and store it.
137      */

138     @Override JavaDoc
139     public void visitEnd() {
140         // set flag on field
141
getAnnotationMetadata().setJavaxPersistenceContext(javaxPersistenceContext);
142     }
143
144     /**
145      * @return type of the annotation (its description)
146      */

147     public String JavaDoc getType() {
148         return TYPE;
149     }
150
151 }
152
Popular Tags