KickJava   Java API By Example, From Geeks To Geeks.

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


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.businessmethod;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import java.lang.reflect.*;
27 import java.util.Set JavaDoc;
28
29 import com.sun.enterprise.deployment.*;
30 import com.sun.enterprise.tools.verifier.*;
31 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
32 import com.sun.enterprise.tools.verifier.tests.ejb.MethodUtils;
33 import com.sun.enterprise.tools.verifier.tests.*;
34
35 /**
36  * Enterprise Bean's business(...) methods public test.
37  * Each enterprise Bean class must define zero or more business(...) methods.
38  * The method signatures must follow these rules:
39  *
40  * The method must be declared as public.
41  */

42 public class BusinessMethodPublic extends EjbTest implements EjbCheck {
43     Result result = null;
44     ComponentNameConstructor compName = null;
45     
46     /**
47      * Enterprise Bean's business(...) methods public test.
48      * Each enterprise Bean class must define zero or more business(...) methods.
49      * The method signatures must follow these rules:
50      *
51      * The method must be declared as public.
52      *
53      * @param descriptor the Enterprise Java Bean deployment descriptor
54      *
55      * @return <code>Result</code> the results for this assertion
56      */

57     public Result check(EjbDescriptor descriptor) {
58         
59         result = getInitializedResult();
60         compName = getVerifierContext().getComponentNameConstructor();
61         
62         if ((descriptor instanceof EjbSessionDescriptor) ||
63                 (descriptor instanceof EjbEntityDescriptor)) {
64             
65             if(descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName()))
66                 commonToBothInterfaces(descriptor.getRemoteClassName(),descriptor);
67             if(descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName()))
68                 commonToBothInterfaces(descriptor.getLocalClassName(),descriptor);
69             Set JavaDoc<String JavaDoc> localAndRemoteInterfaces = descriptor.getLocalBusinessClassNames();
70             localAndRemoteInterfaces.addAll(descriptor.getRemoteBusinessClassNames());
71             
72             for (String JavaDoc localOrRemoteIntf : localAndRemoteInterfaces) {
73                 commonToBothInterfaces(localOrRemoteIntf, descriptor);
74             }
75         }
76         if(result.getStatus() != Result.FAILED) {
77             addGoodDetails(result, compName);
78             result.passed(smh.getLocalString
79                             (getClass().getName() + ".passed",
80                             "Proper declaration of business method(s) found."));
81         }
82         return result;
83     }
84     
85     /**
86      * This method is responsible for the logic of the test. It is called for both local and remote interfaces.
87      * @param descriptor the Enterprise Java Bean deployment descriptor
88      * @param intf or component for the Remote/Local interface of the Ejb.
89      * This parameter may be optional depending on the test
90      */

91     private void commonToBothInterfaces(String JavaDoc intf,EjbDescriptor descriptor) {
92         try {
93             Class JavaDoc intfClass = Class.forName(intf, false, getVerifierContext().getClassLoader());
94             
95             for (Method remoteMethod : intfClass.getMethods()) {
96                 // we don't test the EJB methods
97
if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBObject")||
98                         remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBLocalObject"))
99                     continue;
100                 
101                 Class JavaDoc beanClass = Class.forName(descriptor.getEjbClassName(),
102                                                 false,
103                                                 getVerifierContext().getClassLoader());
104                 boolean foundOne = false;
105                 for (Method method : beanClass.getMethods()) {//getMethods returns only public methods
106
if(MethodUtils.methodEquals(method, remoteMethod)) {
107                         foundOne = true;
108                         break;
109                     }
110                 }
111                 if (!foundOne) {
112                     String JavaDoc methodToString = remoteMethod.toString().replace("abstract ","");
113                     addErrorDetails(result, compName);
114                     result.failed(smh.getLocalString
115                             (getClass().getName() + ".failed",
116                             "Error: public business method [ {0} ] not found in [ {1} ].",
117                             new Object JavaDoc[] {methodToString, beanClass.getName()}));
118                 }
119             }
120             
121         } catch (ClassNotFoundException JavaDoc e) {
122             Verifier.debug(e);
123             addErrorDetails(result, compName);
124             result.failed(smh.getLocalString
125                             (getClass().getName() + ".failedException",
126                             "Error: Remote interface [ {0} ] or bean class [ {1} ] " +
127                             "does not exist or is not loadable within bean [ {2} ].",
128                             new Object JavaDoc[] {intf,descriptor.getEjbClassName(),descriptor.getName()}));
129             
130         }
131     }
132 }
133
Popular Tags