KickJava   Java API By Example, From Geeks To Geeks.

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


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.ejb30;
24
25 import com.sun.enterprise.tools.verifier.Result;
26 import com.sun.enterprise.tools.verifier.tests.ejb.MethodUtils;
27 import com.sun.enterprise.deployment.EjbMessageBeanDescriptor;
28
29 import java.lang.reflect.Method JavaDoc;
30
31 /**
32  * The message driven bean class must implement the message listener interface
33  * or the methods of the message listener interface.
34  *
35  * @author Vikas Awasthi
36  */

37 public class MDBImplementsListenerMethods extends MessageBeanTest {
38     
39     public Result check(EjbMessageBeanDescriptor descriptor) {
40
41         try {
42             ClassLoader JavaDoc cl = getVerifierContext().getClassLoader();
43             Class JavaDoc intfCls = Class.forName(descriptor.getMessageListenerType(), false, cl);
44             Class JavaDoc ejbCls = Class.forName(descriptor.getEjbClassName(), false, cl);
45             
46             if(!intfCls.isAssignableFrom(ejbCls)) {
47                 Method JavaDoc[] methods = intfCls.getMethods();
48                 for (Method JavaDoc method : methods) {
49                     boolean foundOne = false;
50                     for (Method JavaDoc ejbMethod : ejbCls.getMethods()) {
51                         if(MethodUtils.methodEquals(ejbMethod, method)) {
52                             foundOne = true;
53                             break;
54                         }
55                     }
56                     if(!foundOne) {
57                         addErrorDetails(result, compName);
58                         result.failed(
59                                 smh.getLocalString(getClass().getName()+".failed",
60                                 "Message bean [ {0} ] neither implements listener " +
61                                 "interface [ {1} ] nor implements listener " +
62                                 "interface method [ {2} ]",
63                                 new Object JavaDoc[] {ejbCls.getSimpleName(), intfCls.getName(), method}));
64                     }
65                 }
66             }
67         } catch (ClassNotFoundException JavaDoc e) {
68             //ignore as this error will be caught by other tests
69
logger.fine(descriptor.getEjbClassName() + " Not found");
70         }
71         
72         if(result.getStatus() != Result.FAILED) {
73             addGoodDetails(result, compName);
74             result.passed(
75                     smh.getLocalString(getClass().getName()+".passed",
76                             "Valid Message bean [ {0} ]",
77                             new Object JavaDoc[] {descriptor.getEjbClassName()}));
78         }
79
80         return result;
81     }
82 }
83
Popular Tags