KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > deployment > annotations > analyzer > classes > JavaxPersistencePersistenceContextsVisitor


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

25
26 package org.objectweb.easybeans.deployment.annotations.analyzer.classes;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.List JavaDoc;
30
31 import org.objectweb.easybeans.deployment.annotations.analyzer.JavaxPersistencePersistenceContextVisitor;
32 import org.objectweb.easybeans.deployment.annotations.impl.JavaxPersistenceContext;
33 import org.objectweb.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
34
35 /**
36  * This class manages the handling of @{@link javax.persistence.PersistenceContexts}
37  * annotation.
38  * @author Florent Benoit
39  */

40 public class JavaxPersistencePersistenceContextsVisitor extends
41         JavaxPersistencePersistenceContextVisitor<ClassAnnotationMetadata> {
42
43     /**
44      * Type of annotation.
45      */

46     public static final String JavaDoc TYPE = "Ljavax/persistence/PersistenceContexts;";
47
48     /**
49      * List of JavaxPersistenceContext object.
50      */

51     private List JavaDoc<JavaxPersistenceContext> javaxPersistenceContexts = null;
52
53     /**
54      * Object is added to the list.
55      */

56     private boolean isAdded = false;
57
58     /**
59      * Constructor.
60      * @param annotationMetadata linked to a class or method metadata
61      */

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

75     @Override JavaDoc
76     public void visit(final String JavaDoc name, final Object JavaDoc value) {
77         // list not empty, need to create another reference
78
// at the first item found
79
if (javaxPersistenceContexts.size() > 0 && isAdded) {
80             setJavaxPersistenceContext(new JavaxPersistenceContext());
81             isAdded = false;
82         }
83
84         // do super code
85
super.visit(name, value);
86     }
87
88     /**
89      * Visits the end of the annotation. <br>
90      * Creates the object and store it.
91      */

92     @Override JavaDoc
93     public void visitEnd() {
94         // add object in the list
95
if (!isAdded) {
96             javaxPersistenceContexts.add(getJavaxPersistenceContext());
97             isAdded = true;
98         }
99
100         // update list
101
getAnnotationMetadata().setJavaxPersistencePersistenceContexts(javaxPersistenceContexts);
102     }
103
104     /**
105      * @return type of the annotation (its description)
106      */

107     @Override JavaDoc
108     public String JavaDoc getType() {
109         return TYPE;
110     }
111
112 }
113
Popular Tags