KickJava   Java API By Example, From Geeks To Geeks.

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


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: JavaxPersistencePersistenceUnitsVisitor.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.JavaxPersistencePersistenceUnitVisitor;
32 import org.objectweb.easybeans.deployment.annotations.impl.JavaxPersistenceUnit;
33 import org.objectweb.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
34
35 /**
36  * This class manages the handling of @{@link javax.persistence.PersistenceUnits}
37  * annotation.
38  * @author Florent Benoit
39  */

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

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

51     private List JavaDoc<JavaxPersistenceUnit> javaxPersistenceUnits = 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 JavaxPersistencePersistenceUnitsVisitor(final ClassAnnotationMetadata annotationMetadata) {
63         super(annotationMetadata);
64         javaxPersistenceUnits = new ArrayList JavaDoc<JavaxPersistenceUnit>();
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 (javaxPersistenceUnits.size() > 0 && isAdded) {
80             setjavaxPersistenceUnit(new JavaxPersistenceUnit());
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             javaxPersistenceUnits.add(getJavaxPersistenceUnit());
97             isAdded = true;
98         }
99
100         // update list
101
getAnnotationMetadata().setJavaxPersistencePersistenceUnits(javaxPersistenceUnits);
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