KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > timer > HasValidEjbTimeoutDescriptor


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
24
25 package com.sun.enterprise.tools.verifier.tests.ejb.timer;
26
27 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
28 import com.sun.enterprise.deployment.*;
29 import com.sun.enterprise.tools.verifier.*;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32
33 /**
34  * Check that the transaction attributes for the ejbTimeout method are one
35  * of the following -
36  * RequiresNew or NotSupported
37  *
38  * @version
39  * @author Anisha Malhotra
40  */

41 public class HasValidEjbTimeoutDescriptor extends EjbTest {
42     Result result = null;
43     ComponentNameConstructor compName = null;
44     /**
45      * Run a verifier test to check the transaction attributes of the
46      * ejbTimeout method. The allowed attributes are -
47      * RequiresNew or NotSupported.
48      *
49      * @param descriptor the Enterprise Java Bean deployment descriptor
50      *
51      * @return <code>Result</code> the results for this assertion
52      */

53     public Result check(EjbDescriptor descriptor) {
54
55         result = getInitializedResult();
56         compName = getVerifierContext().getComponentNameConstructor();
57
58         if(descriptor.isTimedObject()) {
59
60             if (descriptor.getTransactionType().equals
61                     (EjbDescriptor.CONTAINER_TRANSACTION_TYPE)) {
62                 MethodDescriptor methodDesc = descriptor.getEjbTimeoutMethod();
63                 ContainerTransaction txAttr =
64                         descriptor.getContainerTransactionFor(methodDesc);
65                 String JavaDoc version = getVerifierContext().getJavaEEVersion();
66                 if(txAttr != null) {
67                     String JavaDoc ta = txAttr.getTransactionAttribute();
68                     if ((version.compareTo(SpecVersionMapper.JavaEEVersion_5) >= 0) &&
69                             !(ContainerTransaction.REQUIRES_NEW.equals(ta)
70                             || ContainerTransaction.NOT_SUPPORTED.equals(ta)
71                             || ContainerTransaction.REQUIRED.equals(ta))) {
72                         addErrorDetails(result, compName);
73                         result.failed(smh.getLocalString
74                                 (getClass().getName()+".failed1",
75                                 "Error : Bean [ {0} ] Transaction attribute for timeout method" +
76                                 "must be Required, RequiresNew or NotSupported",
77                                 new Object JavaDoc[] {descriptor.getName()}));
78                     } else if ((version.compareTo(SpecVersionMapper.JavaEEVersion_5) < 0) &&
79                             !(ContainerTransaction.REQUIRES_NEW.equals(ta)
80                             || ContainerTransaction.NOT_SUPPORTED.equals(ta))) {
81                         addErrorDetails(result, compName);
82                         result.failed(smh.getLocalString
83                                 (getClass().getName()+".failed2",
84                                 "Error : Bean [ {0} ] Transaction attribute for ejbTimeout " +
85                                 "must be RequiresNew or NotSupported",
86                                 new Object JavaDoc[] {descriptor.getName()}));
87
88                     }
89                 } else if(version.compareTo(SpecVersionMapper.JavaEEVersion_5)<0) {
90                     // Transaction attribute for ejbTimeout not specified in the DD
91
addErrorDetails(result, compName);
92                     result.failed(smh.getLocalString
93                             (getClass().getName()+".failed3",
94                             "Transaction attribute for Timeout is not specified for [ {0} ]",
95                             new Object JavaDoc[] {descriptor.getName()}));
96                 }
97             }
98         }
99
100         if (result.getStatus() != Result.FAILED) {
101             addGoodDetails(result, compName);
102             result.passed(smh.getLocalString
103                     (getClass().getName()+".passed",
104                     "Transaction attributes are properly specified"));
105
106         }
107         return result;
108     }
109 }
110
Popular Tags