KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.ClassLoader JavaDoc;
28 import java.util.*;
29 import java.lang.reflect.*;
30 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
31 import com.sun.enterprise.tools.verifier.*;
32 import com.sun.enterprise.tools.verifier.tests.*;
33
34 /**
35  * ContainerTransaction Style 2 - 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 2:
41  * <method>
42  * <ejb-name> EJBNAME</ejb-name>
43  * <method-name>METHOD</method-name>
44  * </method>
45  * This style is used for referring to a specified method of the remote or home
46  * interface of the specified enterprise bean. If there are multiple methods
47  * with the same overloaded name, this style refers to all the methods with the
48  * same name. There must be at most one container transaction element that uses
49  * the Style 2 method element for a given method name. If there is also a
50  * container transaction element that uses Style 1 element for the same bean,
51  * the value specified by the Style 2 element takes precedence.
52  */

53 public class ContainerTransactionStyle2 extends EjbTest implements EjbCheck {
54
55     /**
56      * Each container transaction element consists of a list of one or more
57      * method elements, and the trans-attribute element. The container transaction
58      * element specifies that all the listed methods are assigned the specified
59      * transaction attribute value.
60      *
61      * Style 2:
62      * <method>
63      * <ejb-name> EJBNAME</ejb-name>
64      * <method-name>METHOD</method-name>
65      * </method>
66      * This style is used for referring to a specified method of the remote or home
67      * interface of the specified enterprise bean. If there are multiple methods
68      * with the same overloaded name, this style refers to all the methods with the
69      * same name. There must be at most one container transaction element that uses
70      * the Style 2 method element for a given method name. If there is also a
71      * container transaction element that uses Style 1 element for the same bean,
72      * the value specified by the Style 2 element takes precedence.
73      *
74      * @param descriptor the Enterprise Java Bean deployment descriptor
75      *
76      * @return <code>Result</code> the results for this assertion
77      */

78     public Result check(EjbDescriptor descriptor) {
79
80     Result result = getInitializedResult();
81     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
82
83     // hack try/catch block around test, to exit gracefully instead of
84
// crashing verifier on getMethodDescriptors() call, XML mods cause
85
// java.lang.ClassNotFoundException: verifier.ejb.hello.BogusEJB
86
// Replacing <ejb-class>verifier.ejb.hello.HelloEJB with
87
// <ejb-class>verifier.ejb.hello.BogusEJB...
88
try {
89         boolean oneFailed = false;
90             if (!descriptor.getMethodContainerTransactions().isEmpty()) {
91             int na = 0;
92         for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements();) {
93             MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
94                     // see if it's a style 2
95
if (methodDescriptor.getParameterClassNames() == null) {
96                     int foundIt = 0;
97
98                         // found style 2, now see if it's the only one
99
// for given method name
100
for (Enumeration eee = descriptor.getMethodContainerTransactions().keys(); eee.hasMoreElements();) {
101
102                     MethodDescriptor matchingMethodDescriptor = (MethodDescriptor) eee.nextElement();
103                             // see if this md is style 2 ?
104
if (matchingMethodDescriptor.getParameterClassNames() == null) {
105                                 // now see if it's the same name as previously
106
// encountered method name
107
if (methodDescriptor.getName().equals(matchingMethodDescriptor.getName())) {
108                         foundIt++;
109                                 }
110                             }
111                         } // report after this inner loop
112

113                          
114                 // report for this particular set of Container tx's
115
// DOL only saves one container tx with "*", so can't fail...
116
if (foundIt == 1) {
117                 result.addGoodDetails(smh.getLocalString
118                           ("tests.componentNameConstructor",
119                            "For [ {0} ]",
120                            new Object JavaDoc[] {compName.toString()}));
121                     result.passed(smh.getLocalString
122                       (getClass().getName() + ".passed",
123                        "Container Transaction method name [ {0} ] defined only once in [ {1} ] bean.",
124                        new Object JavaDoc[] {methodDescriptor.getName(), descriptor.getName()}));
125                 } else if (foundIt > 1) {
126                             if (!oneFailed) {
127                             oneFailed = false;
128                             }
129                 result.addErrorDetails(smh.getLocalString
130                            ("tests.componentNameConstructor",
131                             "For [ {0} ]",
132                             new Object JavaDoc[] {compName.toString()}));
133                     result.failed(smh.getLocalString
134                       (getClass().getName() + ".failed",
135                        "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.",
136                        new Object JavaDoc[] {methodDescriptor.getName(), new Integer JavaDoc(foundIt), descriptor.getName(),new Integer JavaDoc(2)}));
137                 } else {
138                             na++;
139                 result.addNaDetails(smh.getLocalString
140                         ("tests.componentNameConstructor",
141                          "For [ {0} ]",
142                          new Object JavaDoc[] {compName.toString()}));
143                     result.notApplicable(smh.getLocalString
144                          (getClass().getName() + ".notApplicable1",
145                           "Container Transaction method name [ {0} ] not defined in [ {1} ] bean.",
146                           new Object JavaDoc[] {methodDescriptor.getName(), descriptor.getName()}));
147                 }
148             } else { // not a style 2
149
na++;
150             result.addNaDetails(smh.getLocalString
151                         ("tests.componentNameConstructor",
152                          "For [ {0} ]",
153                          new Object JavaDoc[] {compName.toString()}));
154                 result.notApplicable(smh.getLocalString
155                          (getClass().getName() + ".notApplicable2",
156                           "Container Transaction method name [ {0} ] not defined as style{1} container transaction within [ {2} ].",
157                           new Object JavaDoc[] {methodDescriptor.getName(), new Integer JavaDoc(2), descriptor.getName()}));
158                     }
159             
160         } // for all method container tx's
161

162                 if (oneFailed) {
163                     result.setStatus(result.FAILED);
164                 } else if (na == descriptor.getMethodContainerTransactions().size()){
165                     result.setStatus(result.NOT_APPLICABLE);
166                 } else {
167                     result.setStatus(result.PASSED);
168                 }
169             return result;
170         } else { // if !descriptor.getMethodContainerTransactions().isEmpty
171
result.addNaDetails(smh.getLocalString
172                     ("tests.componentNameConstructor",
173                      "For [ {0} ]",
174                      new Object JavaDoc[] {compName.toString()}));
175         result.notApplicable(smh.getLocalString
176                      (getClass().getName() + ".notApplicable",
177                       "There are no container transactions within this bean [ {0} ]",
178                       new Object JavaDoc[] {descriptor.getName()}));
179             return result;
180         }
181     } catch (Throwable JavaDoc t) {
182         result.addErrorDetails(smh.getLocalString
183                    ("tests.componentNameConstructor",
184                     "For [ {0} ]",
185                     new Object JavaDoc[] {compName.toString()}));
186         result.failed(smh.getLocalString
187               (getClass().getName() + ".failedException2",
188                "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]",
189                new Object JavaDoc[] {descriptor.getName(), t.getMessage(), descriptor.getName()}));
190         return result;
191     }
192     }
193 }
194
Popular Tags