KickJava   Java API By Example, From Geeks To Geeks.

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


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.tests.ejb.EjbCheck;
28 import com.sun.enterprise.tools.verifier.*;
29 import java.lang.ClassLoader JavaDoc;
30 import java.util.*;
31 import java.lang.reflect.*;
32 import com.sun.enterprise.tools.verifier.tests.*;
33
34 /**
35  * ContainerTransaction Style 1 - Each container transaction element consists
36  * of a list of one or more method elements, and the trans-attribute element.
37  * The container transaction element specifies that all the listed methods are
38  * assigned the specified transaction attribute value.
39  *
40  * Style 1:
41  * <method>
42  * <ejb-name> EJBNAME</ejb-name>
43  * <method-name>*</method-name>
44  * </method>
45  * This style is used to specify a default value of the transaction attribute
46  * for the methods for which there is no Style 2 or Style 3 element specified.
47  * There must be at most one container transaction element that uses the Style 1
48  * method element for a given enterprise bean.
49  */

50 public class ContainerTransactionStyle1 extends EjbTest implements EjbCheck {
51
52
53     /**
54      * Each container transaction element consists of a list of one or more
55      * method elements, and the trans-attribute element. The container transaction
56      * element specifies that all the listed methods are assigned the specified
57      * transaction attribute value.
58      *
59      * Style 1:
60      * <method>
61      * <ejb-name> EJBNAME</ejb-name>
62      * <method-name>*</method-name>
63      * </method>
64      * This style is used to specify a default value of the transaction attribute
65      * for the methods for which there is no Style 2 or Style 3 element specified.
66      * There must be at most one container transaction element that uses the Style 1
67      * method element for a given enterprise bean.
68      *
69      * @param descriptor the Enterprise Java Bean deployment descriptor
70      *
71      * @return <code>Result</code> the results for this assertion
72      */

73     public Result check(EjbDescriptor descriptor) {
74
75     Result result = getInitializedResult();
76     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
77
78     // hack try/catch block around test, to exit gracefully instead of
79
// crashing verifier on getMethodDescriptors() call, XML mods cause
80
// java.lang.ClassNotFoundException: verifier.ejb.hello.BogusEJB
81
// Replacing <ejb-class>verifier.ejb.hello.HelloEJB with
82
// <ejb-class>verifier.ejb.hello.BogusEJB...
83
try {
84         boolean oneFailed = false;
85         boolean na = false;
86         int foundWildCard = 0;
87             if (!descriptor.getMethodContainerTransactions().isEmpty()) {
88         for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements();) {
89             MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
90   
91             if (methodDescriptor.getName().equals(MethodDescriptor.ALL_EJB_METHODS)) {
92             foundWildCard++;
93             }
94         }
95
96         // report for this particular set of Container tx's
97
// DOL only saves one container tx with "*", so can't fail...
98
if (foundWildCard == 1) {
99             result.addGoodDetails(smh.getLocalString
100                       ("tests.componentNameConstructor",
101                        "For [ {0} ]",
102                        new Object JavaDoc[] {compName.toString()}));
103             result.passed(smh.getLocalString
104                   (getClass().getName() + ".passed",
105                    "Container Transaction method name [ {0} ] defined only once in [ {1} ] bean.",
106                    new Object JavaDoc[] {MethodDescriptor.ALL_EJB_METHODS, descriptor.getName()}));
107         } else if (foundWildCard > 1) {
108             result.addErrorDetails(smh.getLocalString
109                        ("tests.componentNameConstructor",
110                         "For [ {0} ]",
111                         new Object JavaDoc[] {compName.toString()}));
112             result.failed(smh.getLocalString
113                   (getClass().getName() + ".failed",
114                    "Error: Container Transaction method name [ {0} ] is defined [ {1} ] times in [ {2} ] bean. Method name container transaction style [ {3} ] is allowed only once per bean.",
115                    new Object JavaDoc[] {MethodDescriptor.ALL_EJB_METHODS, new Integer JavaDoc(foundWildCard), descriptor.getName(),MethodDescriptor.ALL_EJB_METHODS}));
116         } else {
117             result.addNaDetails(smh.getLocalString
118                       ("tests.componentNameConstructor",
119                        "For [ {0} ]",
120                        new Object JavaDoc[] {compName.toString()}));
121             result.notApplicable(smh.getLocalString
122                      (getClass().getName() + ".notApplicable1",
123                       "Container Transaction method name [ {0} ] not defined in [ {1} ] bean.",
124                       new Object JavaDoc[] {MethodDescriptor.ALL_EJB_METHODS, descriptor.getName()}));
125         }
126         
127         } else { // if (methodDescriptorsIterator.hasNext())
128
result.addNaDetails(smh.getLocalString
129                       ("tests.componentNameConstructor",
130                        "For [ {0} ]",
131                        new Object JavaDoc[] {compName.toString()}));
132         result.notApplicable(smh.getLocalString
133                      (getClass().getName() + ".notApplicable",
134                       "There are no method permissions within this bean [ {0} ]",
135                       new Object JavaDoc[] {descriptor.getName()}));
136         }
137         return result;
138     } catch (Throwable JavaDoc t) {
139         result.addErrorDetails(smh.getLocalString
140                    ("tests.componentNameConstructor",
141                     "For [ {0} ]",
142                     new Object JavaDoc[] {compName.toString()}));
143         result.failed(smh.getLocalString
144               (getClass().getName() + ".failedException2",
145                "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]",
146                new Object JavaDoc[] {descriptor.getName(), t.getMessage(), descriptor.getName()}));
147         return result;
148     }
149     }
150 }
151
Popular Tags