KickJava   Java API By Example, From Geeks To Geeks.

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


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.TransactionManagement JavaDoc;
29 import javax.ejb.TransactionManagementType JavaDoc;
30
31 import com.sun.enterprise.deployment.EjbDescriptor;
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 import com.sun.enterprise.deployment.annotation.context.EjbContext;
37
38 /**
39  * This handler is responsible for handling the javax.ejb.TransactionManagement.
40  *
41  * @author Shing Wai Chan
42  */

43 public class TransactionManagementHandler extends AbstractAttributeHandler {
44     
45     public TransactionManagementHandler() {
46     }
47     
48     /**
49      * @return the annoation type this annotation handler is handling
50      */

51     public Class JavaDoc<? extends Annotation JavaDoc> getAnnotationType() {
52         return TransactionManagement JavaDoc.class;
53     }
54
55     protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo,
56             EjbContext[] ejbContexts) throws AnnotationProcessorException {
57         
58         TransactionManagement JavaDoc tmAn = (TransactionManagement JavaDoc)ainfo.getAnnotation();
59
60         String JavaDoc tmType =
61                 TransactionManagementType.CONTAINER.equals(tmAn.value())?
62                 EjbDescriptor.CONTAINER_TRANSACTION_TYPE :
63                 EjbDescriptor.BEAN_TRANSACTION_TYPE;
64
65         for (EjbContext ejbContext : ejbContexts) {
66             EjbDescriptor ejbDesc = ejbContext.getDescriptor();
67             // override by xml
68
if (ejbDesc.getTransactionType() == null) {
69                 ejbDesc.setTransactionType(tmType);
70             }
71         }
72
73         return getDefaultProcessedResult();
74     }
75
76     /**
77      * @return an array of annotation types this annotation handler would
78      * require to be processed (if present) before it processes it's own
79      * annotation type.
80      */

81     public Class JavaDoc<? extends Annotation JavaDoc>[] getTypeDependencies() {
82         return getEjbAnnotationTypes();
83     }
84 }
85
Popular Tags