KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > annotation > handlers > StatelessHandler


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.deployment.annotation.handlers;
24
25 import java.lang.annotation.Annotation JavaDoc;
26 import java.lang.reflect.AnnotatedElement JavaDoc;
27
28 import javax.ejb.Stateless JavaDoc;
29
30 import com.sun.enterprise.deployment.EjbDescriptor;
31 import com.sun.enterprise.deployment.EjbSessionDescriptor;
32
33 import com.sun.enterprise.deployment.annotation.AnnotationInfo;
34 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException;
35 import com.sun.enterprise.deployment.annotation.HandlerProcessingResult;
36
37 /**
38  * This handler is responsible for handling the javax.ejb.Stateless
39  *
40  * @author Shing Wai Chan
41  */

42 public class StatelessHandler extends AbstractEjbHandler {
43     
44     /** Creates a new instance of StatelessHandler */
45     public StatelessHandler() {
46     }
47     
48     /**
49      * @return the annoation type this annotation handler is handling
50      */

51     public Class JavaDoc<? extends Annotation JavaDoc> getAnnotationType() {
52         return Stateless JavaDoc.class;
53     }
54
55     /**
56      * Return the name attribute of given annotation.
57      * @param annotation
58      * @return name
59      */

60     protected String JavaDoc getAnnotatedName(Annotation JavaDoc annotation) {
61         Stateless JavaDoc slAn = (Stateless JavaDoc)annotation;
62         return slAn.name();
63     }
64
65     /**
66      * Check if the given EjbDescriptor matches the given Annotation.
67      * @param ejbDesc
68      * @param annotation
69      * @return boolean check for validity of EjbDescriptor
70      */

71     protected boolean isValidEjbDescriptor(EjbDescriptor ejbDesc,
72             Annotation JavaDoc annotation) {
73         return EjbSessionDescriptor.TYPE.equals(ejbDesc.getType());
74     }
75
76     /**
77      * Create a new EjbDescriptor for a given elementName and AnnotationInfo.
78      * @param elementName
79      * @param ainfo
80      * @return a new EjbDescriptor
81      */

82     protected EjbDescriptor createEjbDescriptor(String JavaDoc elementName,
83             AnnotationInfo ainfo) throws AnnotationProcessorException {
84
85         AnnotatedElement JavaDoc ae = ainfo.getAnnotatedElement();
86         Class JavaDoc ejbClass = (Class JavaDoc)ae;
87         EjbSessionDescriptor newDescriptor = new EjbSessionDescriptor();
88         newDescriptor.setName(elementName);
89         newDescriptor.setEjbClassName(ejbClass.getName());
90         newDescriptor.setSessionType(EjbSessionDescriptor.STATELESS);
91         return newDescriptor;
92     }
93
94     /**
95      * Set Annotation information to Descriptor.
96      * This method will also be invoked for an existing descriptor with
97      * annotation as user may not specific a complete xml.
98      * @param ejbDesc
99      * @param ainfo
100      * @return HandlerProcessingResult
101      */

102     protected HandlerProcessingResult setEjbDescriptorInfo(
103             EjbDescriptor ejbDesc, AnnotationInfo ainfo)
104             throws AnnotationProcessorException {
105
106         EjbSessionDescriptor ejbSessionDesc = (EjbSessionDescriptor)ejbDesc;
107         ejbSessionDesc.setStateless(true);
108
109         Stateless JavaDoc sless = (Stateless JavaDoc) ainfo.getAnnotation();
110
111         doDescriptionProcessing(sless.description(), ejbDesc);
112         doMappedNameProcessing(sless.mappedName(), ejbDesc);
113
114         return setBusinessAndHomeInterfaces(ejbDesc, ainfo);
115     }
116 }
117
Popular Tags