KickJava   Java API By Example, From Geeks To Geeks.

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


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.messagebean;
26
27 import com.sun.enterprise.tools.verifier.Result;
28 import com.sun.enterprise.tools.verifier.SpecVersionMapper;
29 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
30 import com.sun.enterprise.deployment.EjbMessageBeanDescriptor;
31 import com.sun.enterprise.deployment.EjbDescriptor;
32 import com.sun.enterprise.deployment.MethodDescriptor;
33 import com.sun.enterprise.deployment.ContainerTransaction;
34
35 import java.util.Collection JavaDoc;
36 import java.util.Iterator JavaDoc;
37
38 /**
39  * Message-driven beans with container-managed transaction demarcation must use
40  * Required or NotSupported transaction attribute.
41  *
42  * @author Jerome Dochez
43  * @version
44  */

45 public class HasValidMethodDescriptor extends MessageBeanTest {
46
47   /**
48    * Run a verifier test against an individual declared message
49    * drive bean component
50    *
51    * @param descriptor the Enterprise Java Bean deployment descriptor
52    * @return <code>Result</code> the results for this assertion
53    */

54   public Result check(EjbMessageBeanDescriptor descriptor) {
55
56     Result result = getInitializedResult();
57     ComponentNameConstructor compName =
58       getVerifierContext().getComponentNameConstructor();
59
60     if (descriptor.getTransactionType().equals
61         (EjbDescriptor.CONTAINER_TRANSACTION_TYPE)) {
62
63       // returns the Message Listener methods and "ejbTimeout" if the bean is a
64
// TimedObject.
65
Collection JavaDoc methods = descriptor.getTransactionMethodDescriptors();
66
67       if (methods.size()==0) {
68         addNaDetails(result, compName);
69         result.notApplicable(smh.getLocalString
70             (getClass().getName()+".notApplicable1",
71              "Message-driven bean [ {0} ] does not define any method",
72              new Object JavaDoc[] {descriptor.getName()}));
73         return result;
74       }
75
76       Iterator JavaDoc iterator = methods.iterator();
77       while(iterator.hasNext())
78       {
79         MethodDescriptor method = (MethodDescriptor) iterator.next();
80         // if the MDB is also a TimedObject then don't check the
81
// transaction attribute of ejbTimeout. The
82
// timer/HasValidEjbTimeout test will check the transaction
83
// attribute for ejbTimeout
84

85         if( descriptor.isTimedObject() &&
86             (method.getName()).equals("ejbTimeout") )
87           continue;
88         ContainerTransaction txAttr = descriptor.
89           getContainerTransactionFor(method);
90         if(txAttr == null)
91         {
92             if(getVerifierContext().getJavaEEVersion().compareTo(SpecVersionMapper.JavaEEVersion_5)<0) {
93           // transaction attribute is not specified for method.
94
addErrorDetails(result, compName);
95           result.failed(smh.getLocalString
96               (getClass().getName()+".failed4",
97                "Error : Message-driven bean [ {0} ] method definition [ {1} ] does not have a valid container transaction descriptor.",
98                new Object JavaDoc[] {descriptor.getName(), method.getName()}));
99             } // default transaction attr in EJB 3.0 is REQUIRED
100
continue;
101         }
102         String JavaDoc ta = txAttr.getTransactionAttribute();
103         if (ContainerTransaction.REQUIRED.equals(ta) ||
104             ContainerTransaction.NOT_SUPPORTED.equals(ta)) {
105           addGoodDetails(result, compName);
106           result.passed(smh.getLocalString
107               (getClass().getName()+".passed",
108                "Message-driven bean [ {0} ] method definition [ {1} ] in assembly-descriptor is correct",
109                new Object JavaDoc[] {descriptor.getName(), method.getName()}));
110         } else {
111           addErrorDetails(result, compName);
112           result.failed(smh.getLocalString
113               (getClass().getName()+".failed3",
114                "Error : Message-driven bean [ {0} ] method definition [ {1} ] transaction attribute must be Required or NotSupported",
115                new Object JavaDoc[] {descriptor.getName(), method.getName()}));
116         }
117       }
118       return result;
119     } else {
120       addNaDetails(result, compName);
121       result.notApplicable(smh.getLocalString
122           (getClass().getName()+".notApplicable2",
123            "Message-driven bean [ {0} ] does not use container-managed transaction",
124            new Object JavaDoc[] {descriptor.getName()}));
125     }
126     return result;
127   }
128 }
129
Popular Tags