KickJava   Java API By Example, From Geeks To Geeks.

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


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: JavaxAnnotationResourcesVisitor.java 9 2006-02-19 18:53:32Z 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.JavaxAnnotationResourceVisitor;
32 import org.objectweb.easybeans.deployment.annotations.impl.JAnnotationResource;
33 import org.objectweb.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
34
35 /**
36  * This class manages the handling of @{@link javax.annotation.Resources} annotation.
37  * @author Florent Benoit
38  */

39 public class JavaxAnnotationResourcesVisitor extends JavaxAnnotationResourceVisitor<ClassAnnotationMetadata> {
40
41     /**
42      * Type of annotation.
43      */

44     public static final String JavaDoc TYPE = "Ljavax/annotation/Resources;";
45
46     /**
47      * List of jAnnotationResource object.
48      */

49     private List JavaDoc<JAnnotationResource> jAnnotationResources = null;
50
51     /**
52      * Object is added to the list.
53      */

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

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

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

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

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