KickJava   Java API By Example, From Geeks To Geeks.

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


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.Stateful 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.Stateful
39  *
40  * @author Shing Wai Chan
41  */

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

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

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

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

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

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