KickJava   Java API By Example, From Geeks To Geeks.

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


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: JavaxAnnotationResourceVisitor.java 413 2006-04-25 16:55:33Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.deployment.annotations.analyzer;
27
28 import static javax.annotation.Resource.AuthenticationType.APPLICATION;
29 import static javax.annotation.Resource.AuthenticationType.CONTAINER;
30
31 import org.objectweb.asm.Type;
32
33 import org.objectweb.easybeans.deployment.annotations.impl.JAnnotationResource;
34 import org.objectweb.easybeans.deployment.annotations.metadata.interfaces.IAnnotationResource;
35
36 /**
37  * This class manages the handling of @{@link javax.annotation.Resource}
38  * annotation.
39  * @param <T> An implementation of IAnnotationResource interface.
40  * @author Florent Benoit
41  */

42 public class JavaxAnnotationResourceVisitor<T extends IAnnotationResource> extends AbsAnnotationVisitor<T> implements
43         AnnotationType {
44
45     /**
46      * Name attribute of the annotation.
47      */

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

53     private static final String JavaDoc CLASS_TYPE = "type";
54
55     /**
56      * Atuthentication type attribute of the annotation.
57      */

58     private static final String JavaDoc AUTHENTICATION_TYPE = "authenticationType";
59
60     /**
61      * Shareable attribute of the annotation.
62      */

63     private static final String JavaDoc SHAREABLE = "shareable";
64
65     /**
66      * Description of the annotation.
67      */

68     private static final String JavaDoc DESCRIPTION = "description";
69
70     /**
71      * Mapped name attribute of the annotation.
72      */

73     private static final String JavaDoc MAPPED_NAME = "mappedName";
74
75     /**
76      * Type of annotation.
77      */

78     public static final String JavaDoc TYPE = "Ljavax/annotation/Resource;";
79
80     /**
81      * Internal object used representing &#64;{@link javax.annotation.Resource}
82      * annotation.
83      */

84     private JAnnotationResource jAnnotationResource = null;
85
86     /**
87      * Constructor.
88      * @param annotationMetadata linked to a class or method metadata
89      */

90     public JavaxAnnotationResourceVisitor(final T annotationMetadata) {
91         super(annotationMetadata);
92         jAnnotationResource = new JAnnotationResource();
93     }
94
95     /**
96      * Visits a primitive value of the annotation.<br>
97      * @param name the value name.
98      * @param value the actual value, whose type must be {@link Byte},
99      * {@link Boolean}, {@link Character}, {@link Short},
100      * {@link Integer}, {@link Long}, {@link Float}, {@link Double},
101      * {@link String} or {@link org.objectweb.asm.Type}.
102      */

103     @Override JavaDoc
104     public void visit(final String JavaDoc name, final Object JavaDoc value) {
105         if (name.equals(NAME)) {
106             jAnnotationResource.setName((String JavaDoc) value);
107         } else if (name.equals(CLASS_TYPE)) {
108             Type type = (Type) value;
109             jAnnotationResource.setType(type.getClassName());
110         } else if (name.equals(SHAREABLE)) {
111             jAnnotationResource.setShareable(((Boolean JavaDoc) value).booleanValue());
112         } else if (name.equals(DESCRIPTION)) {
113             jAnnotationResource.setDescription((String JavaDoc) value);
114         } else if (name.equals(MAPPED_NAME)) {
115             jAnnotationResource.setMappedName((String JavaDoc) value);
116         }
117     }
118
119     /**
120      * Visits an enumeration value of the annotation.
121      * @param name the value name.
122      * @param desc the class descriptor of the enumeration class.
123      * @param value the actual enumeration value.
124      */

125     @Override JavaDoc
126     public void visitEnum(final String JavaDoc name, final String JavaDoc desc, final String JavaDoc value) {
127         if (name.equals(AUTHENTICATION_TYPE)) {
128             if (CONTAINER.name().equals(value)) {
129                 jAnnotationResource.setAuthenticationType(CONTAINER);
130             } else if (APPLICATION.name().equals(value)) {
131                 jAnnotationResource.setAuthenticationType(APPLICATION);
132             }
133         }
134     }
135
136     /**
137      * Visits the end of the annotation. <br>
138      * Creates the object and store it.
139      */

140     @Override JavaDoc
141     public void visitEnd() {
142         // add object
143
getAnnotationMetadata().setJAnnotationResource(jAnnotationResource);
144     }
145
146     /**
147      * @return type of the annotation (its description)
148      */

149     public String JavaDoc getType() {
150         return TYPE;
151     }
152
153     /**
154      * @return Internal object used representing &#64;{@link javax.annotation.Resource}
155      * annotation.
156      */

157     protected JAnnotationResource getJAnnotationResource() {
158         return jAnnotationResource;
159     }
160
161     /**
162      * Sets the jAnnotationResource object.
163      * @param jAnnotationResource the object which replaced the previous one.
164      */

165     protected void setJAnnotationResource(final JAnnotationResource jAnnotationResource) {
166         this.jAnnotationResource = jAnnotationResource;
167     }
168
169 }
170
Popular Tags