KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.Arrays JavaDoc;
29
30 import com.sun.enterprise.deployment.*;
31 import com.sun.enterprise.tools.verifier.*;
32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
33 import com.sun.enterprise.tools.verifier.tests.*;
34
35 /**
36  * Enterprise Bean's business(...) methods final 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 not be declared as final.
41  */

42 public class BusinessMethodFinal extends EjbTest implements EjbCheck {
43     Result result = null;
44     ComponentNameConstructor compName = null;
45     
46     /**
47      * Enterprise Bean's business(...) methods final 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 not be declared as final.
52      *
53      * @param descriptor the Enterprise Java Bean deployment descriptor
54      * @return <code>Result</code> the results for this assertion
55      */

56     public Result check(EjbDescriptor descriptor) {
57         
58         result = getInitializedResult();
59         compName = getVerifierContext().getComponentNameConstructor();
60         
61         if ((descriptor instanceof EjbSessionDescriptor) ||
62                 (descriptor instanceof EjbEntityDescriptor)) {
63             
64             if(descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName()))
65                 commonToBothInterfaces(descriptor.getRemoteClassName(),descriptor);
66             
67             if(descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName()))
68                 commonToBothInterfaces(descriptor.getLocalClassName(),descriptor);
69
70             Set JavaDoc<String JavaDoc> localAndRemoteInterfaces = descriptor.getLocalBusinessClassNames();
71             localAndRemoteInterfaces.addAll(descriptor.getRemoteBusinessClassNames());
72             
73             for (String JavaDoc localOrRemoteIntf : localAndRemoteInterfaces)
74                 commonToBothInterfaces(localOrRemoteIntf, descriptor);
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
87      * both local and remote interfaces.
88      * @param descriptor the Enterprise Java Bean deployment descriptor
89      * @param intf for the Home and Remote Interface of the Ejb
90      * This parameter may be optional depending on the test
91      */

92     
93     private void commonToBothInterfaces(String JavaDoc intf,EjbDescriptor descriptor) {
94         try {
95             Class JavaDoc intfClass = Class.forName(intf,
96                                             false,
97                                             getVerifierContext().getClassLoader());
98             
99             for (Method remoteMethod : intfClass.getMethods()) {
100                 
101                 // we don't test the EJB methods
102
if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBObject")||
103                         remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBLocalObject") ||
104                         remoteMethod.getDeclaringClass().getName().equals("java.lang.Object"))
105                     continue;
106                 
107                 Class JavaDoc beanClass = Class.forName(descriptor.getEjbClassName(),
108                                                 false,
109                                                 getVerifierContext().getClassLoader());
110                 for (Method method : beanClass.getMethods()) {
111                     
112                     if (method.getName().equals(remoteMethod.getName())) {
113                         Class JavaDoc parms[] = method.getParameterTypes();
114                         Class JavaDoc remoteParams[] = remoteMethod.getParameterTypes();
115                         
116                         if (Arrays.equals(parms, remoteParams) &&
117                                 Modifier.isFinal(method.getModifiers())) {
118                             addErrorDetails(result, compName);
119                             result.failed(smh.getLocalString
120                                     (getClass().getName() + ".failed",
121                                     "Error: final business method [ {0} ] was " +
122                                     "found, but business method cannot be declared as final.",
123                                     new Object JavaDoc[] {method.getName()}));
124                         }
125                     }
126                 }
127             }
128         } catch (ClassNotFoundException JavaDoc e) {
129             Verifier.debug(e);
130             addErrorDetails(result, compName);
131             result.failed(smh.getLocalString
132                             (getClass().getName() + ".failedException",
133                             "Error: Remote interface [ {0} ] or bean class [ {1} ] " +
134                             "does not exist or is not loadable within bean [ {2} ].",
135                             new Object JavaDoc[] {intf,descriptor.getEjbClassName(),descriptor.getName()}));
136         }
137     }
138 }
139
Popular Tags