KickJava   Java API By Example, From Geeks To Geeks.

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


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.tools.verifier.tests.ejb;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.*;
28 import java.util.*;
29 import com.sun.enterprise.tools.verifier.tests.*;
30
31
32 /** Session/Entity Bean bean-managed transaction demarcation type test.
33  * The Application Assembler must not define transaction attributes for an
34  * enterprise bean with bean-managed transaction demarcation.
35  */

36 public class TransactionDemarcationBeanManaged extends EjbTest implements EjbCheck {
37
38
39     /** Session/Entity Bean bean-managed transaction demarcation type test.
40      * The Application Assembler must not define transaction attributes for an
41      * enterprise bean with bean-managed transaction demarcation.
42      *
43      * @param descriptor the Enterprise Java Bean deployment descriptor
44      *
45      * @return <code>Result</code> the results for this assertion
46      */

47     public Result check(EjbDescriptor descriptor) {
48
49     Result result = getInitializedResult();
50     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
51
52     // hack try/catch block around test, to exit gracefully instead of
53
// crashing verifier on getMethodDescriptors() call, XML mods cause
54
// java.lang.ClassNotFoundException: verifier.ejb.hello.BogusEJB
55
// Replacing <ejb-class>verifier.ejb.hello.HelloEJB with
56
// <ejb-class>verifier.ejb.hello.BogusEJB...
57
try {
58         // The Application Assembler must not define transaction attributes for an
59
// enterprise bean with bean-managed transaction demarcation.
60
if ((descriptor instanceof EjbSessionDescriptor) ||
61         (descriptor instanceof EjbEntityDescriptor)) {
62         String JavaDoc transactionType = descriptor.getTransactionType();
63         if (EjbDescriptor.BEAN_TRANSACTION_TYPE.equals(transactionType)) {
64             ContainerTransaction containerTransaction = null;
65                     if (!descriptor.getMethodContainerTransactions().isEmpty()) {
66                         for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements();) {
67                 MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
68                             containerTransaction =
69                                                 (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor);
70             
71                 try {
72                 String JavaDoc transactionAttribute =
73                     containerTransaction.getTransactionAttribute();
74     
75                 // danny is doing this in the DOL, but is it possible to not have
76
// any value for containerTransaction.getTransactionAttribute()
77
// in the DOL? if it is possible to have blank value for this,
78
// then this check is needed here, otherwise we are done and we
79
// don't need this check here
80
if (ContainerTransaction.NOT_SUPPORTED.equals(transactionAttribute)
81                     || ContainerTransaction.SUPPORTS.equals(transactionAttribute)
82                     || ContainerTransaction.REQUIRED.equals(transactionAttribute)
83                     || ContainerTransaction.REQUIRES_NEW.equals(transactionAttribute)
84                     || ContainerTransaction.MANDATORY.equals(transactionAttribute)
85                     || ContainerTransaction.NEVER.equals(transactionAttribute)
86                     || (!transactionAttribute.equals(""))) {
87                     result.addErrorDetails(smh.getLocalString
88                                ("tests.componentNameConstructor",
89                                 "For [ {0} ]",
90                                 new Object JavaDoc[] {compName.toString()}));
91                     result.failed(smh.getLocalString
92                           (getClass().getName() + ".failed",
93                            "Error: TransactionAttribute [ {0} ] for method [ {1} ] is not valid. The Application Assembler must not define transaction attributes for an enterprise bean [ {2} ] with bean-managed transaction demarcation.",
94                            new Object JavaDoc[] {transactionAttribute, methodDescriptor.getName(),descriptor.getName()}));
95                 } else {
96                     result.addGoodDetails(smh.getLocalString
97                               ("tests.componentNameConstructor",
98                                "For [ {0} ]",
99                                new Object JavaDoc[] {compName.toString()}));
100                     result.passed(smh.getLocalString
101                           (getClass().getName() + ".passed",
102                            "Valid: TransactionAttribute [ {0} ] for method [ {1} ] is not defined for an enterprise bean [ {2} ] with bean-managed transaction demarcation.",
103                            new Object JavaDoc[] {transactionAttribute, methodDescriptor.getName(),descriptor.getName()}));
104                 }
105                 } catch (NullPointerException JavaDoc e) {
106                 result.addGoodDetails(smh.getLocalString
107                               ("tests.componentNameConstructor",
108                                "For [ {0} ]",
109                                new Object JavaDoc[] {compName.toString()}));
110                 result.passed(smh.getLocalString
111                           (getClass().getName() + ".passed1",
112                            "Valid: TransactionAttribute is null for method [ {0} ] in bean [ {1} ]",
113                            new Object JavaDoc[] {methodDescriptor.getName(),descriptor.getName()}));
114                 return result;
115                 }
116             }
117             } else {
118             result.addGoodDetails(smh.getLocalString
119                           ("tests.componentNameConstructor",
120                            "For [ {0} ]",
121                            new Object JavaDoc[] {compName.toString()}));
122             result.passed(smh.getLocalString
123                      (getClass().getName() + ".passed2",
124                       "Valid: There are no method permissions within this bean [ {0} ]",
125                       new Object JavaDoc[] {descriptor.getName()}));
126             }
127             return result;
128         } else {
129             // not container managed, but is a session/entity bean
130
result.addNaDetails(smh.getLocalString
131                     ("tests.componentNameConstructor",
132                      "For [ {0} ]",
133                      new Object JavaDoc[] {compName.toString()}));
134             result.notApplicable(smh.getLocalString
135                      (getClass().getName() + ".notApplicable2",
136                       "Bean [ {0} ] is not [ {1} ] managed, it is [ {2} ] managed.",
137                       new Object JavaDoc[] {descriptor.getName(),EjbDescriptor.BEAN_TRANSACTION_TYPE,transactionType}));
138         }
139         return result;
140         } else {
141         result.addNaDetails(smh.getLocalString
142                     ("tests.componentNameConstructor",
143                      "For [ {0} ]",
144                      new Object JavaDoc[] {compName.toString()}));
145         result.notApplicable(smh.getLocalString
146                      (getClass().getName() + ".notApplicable",
147                       "[ {0} ] not called \n with a Session or Entity bean.",
148                       new Object JavaDoc[] {getClass()}));
149         return result;
150         }
151     } catch (Throwable JavaDoc t) {
152         result.addErrorDetails(smh.getLocalString
153                    ("tests.componentNameConstructor",
154                     "For [ {0} ]",
155                     new Object JavaDoc[] {compName.toString()}));
156         result.failed(smh.getLocalString
157               (getClass().getName() + ".failedException",
158                "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]",
159                new Object JavaDoc[] {descriptor.getName(), t.getMessage(), descriptor.getName()}));
160         return result;
161     }
162     }
163 }
164
Popular Tags