KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
33
34 /**
35  * Enterprise Bean's business(...) methods static test.
36  * Each enterprise Bean class must define zero or more business(...) methods.
37  * The method signatures must follow these rules:
38  *
39  * The method must not be declared as static.
40  */

41 public class BusinessMethodStatic extends EjbTest implements EjbCheck {
42     
43     Result result = null;
44     ComponentNameConstructor compName = null;
45     
46     /**
47      * Enterprise Bean's business(...) methods static 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 static.
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
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 both local and remote interfaces.
87      * @param intf or home Interface of the Ejb
88      * @param descriptor the Enterprise Java Bean deployment descriptor
89      * This parameter may be optional depending on the test
90      */

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