KickJava   Java API By Example, From Geeks To Geeks.

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


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.messagebean;
24
25 import com.sun.enterprise.tools.verifier.Result;
26 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
27 import com.sun.enterprise.tools.verifier.tests.ejb.MethodUtils;
28 import com.sun.enterprise.deployment.EjbMessageBeanDescriptor;
29
30 import java.lang.reflect.Method JavaDoc;
31 import java.lang.reflect.Modifier JavaDoc;
32
33 /**
34  * Message listener methods must not be declared as final or static.
35  *
36  * @author Vikas Awasthi
37  */

38 public class MessageListenerMethodModifiers extends MessageBeanTest {
39
40     public Result check(EjbMessageBeanDescriptor descriptor) {
41         Result result = getInitializedResult();
42         ComponentNameConstructor compName =
43                             getVerifierContext().getComponentNameConstructor();
44
45         ClassLoader JavaDoc cl = getVerifierContext().getClassLoader();
46         try {
47             Class JavaDoc intfCls = Class.forName(descriptor.getMessageListenerType(), false, cl);
48             Class JavaDoc ejbCls = Class.forName(descriptor.getEjbClassName(), false, cl);
49             Method JavaDoc[] intfMethods = intfCls.getMethods();
50             for (Method JavaDoc method : intfMethods) {
51                 for (Method JavaDoc ejbMethod : ejbCls.getMethods()) {
52                     // if matching method is found then check the assertion
53
if (MethodUtils.methodEquals(ejbMethod, method)) {
54                         if(Modifier.isFinal(ejbMethod.getModifiers()) ||
55                                 Modifier.isStatic(ejbMethod.getModifiers())) {
56                             addErrorDetails(result, compName);
57                             result.failed(smh.getLocalString
58                                     (getClass().getName() + ".failed",
59                                             "Wrong method [ {0} ]",
60                                             new Object JavaDoc[]{ejbMethod}));
61                         }
62                         break;
63                     }
64                 }// another test will report failure if listener method is not found
65
}
66         } catch (ClassNotFoundException JavaDoc e) {} // will be caught in other tests
67

68         if(result.getStatus() != Result.FAILED) {
69             addGoodDetails(result, compName);
70             result.passed(smh.getLocalString
71                             (getClass().getName() + ".passed",
72                             "Valid message listener method(s)."));
73         }
74         return result;
75     }
76 }
77
Popular Tags