KickJava   Java API By Example, From Geeks To Geeks.

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


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 name 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 names can be arbitrary, but they must not conflict with the names
40  * of the methods defined by the EJB architecture (ejbCreate, ejbActivate, etc.)
41  *
42  */

43 public class BusinessMethodName extends EjbTest implements EjbCheck {
44     
45     
46     Result result = null;
47     ComponentNameConstructor compName = null;
48     
49     /**
50      * Enterprise Bean's business(...) methods name test.
51      * Each enterprise Bean class must define zero or more business(...) methods.
52      * The method signatures must follow these rules:
53      *
54      * The method names can be arbitrary, but they must not conflict with the names
55      * of the methods defined by the EJB architecture (ejbCreate, ejbActivate, etc.)
56      *
57      * @param descriptor the Enterprise Java Bean deployment descriptor
58      *
59      * @return <code>Result</code> the results for this assertion
60      */

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

97     
98     private void commonToBothInterfaces(String JavaDoc intf,EjbDescriptor descriptor) {
99         try {
100             Class JavaDoc intfClass = Class.forName(intf, false, getVerifierContext().getClassLoader());
101             
102             for (Method remoteMethod : intfClass.getMethods()) {
103                 
104                 // we don't test the EJB methods
105
if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBObject"))
106                     continue;
107                 
108                 Class JavaDoc beanClass = Class.forName(descriptor.getEjbClassName(),
109                                                 false,
110                                                 getVerifierContext().getClassLoader());
111                 for (Method method : beanClass.getMethods()) {
112                     if (method.getName().equals(remoteMethod.getName())) {
113                         
114                         // The method name must not be start with "ejb", to avoid
115
// conflicting with callback methods used by EJB architecture
116
// also, ignore .class$ compiler generated methods
117
if (method.getName().startsWith("ejb") ||
118                                 method.getName().equals("class$") ||
119                                 method.getName().equals("setSessionContext")) {
120                             
121                             addErrorDetails(result, compName);
122                             result.failed(smh.getLocalString
123                                             (getClass().getName() + ".failed",
124                                             "Error: Business method [ {0} ] was " +
125                                             "found, but was not properly named. " +
126                                             "[ {1} ] must not conflict with the " +
127                                             "names of the methods defined by the " +
128                                             "EJB architecture",
129                                             new Object JavaDoc[] {method.getName(),method.getName()}));
130                         }
131                     }
132                 }
133             }
134             
135         } catch (ClassNotFoundException JavaDoc e) {
136             Verifier.debug(e);
137             addErrorDetails(result, compName);
138             result.failed(smh.getLocalString
139                             (getClass().getName() + ".failedException",
140                             "Error: Remote interface [ {0} ] or bean class [ {1} ] " +
141                             "does not exist or is not loadable within bean [ {2} ].",
142                             new Object JavaDoc[] {intf,descriptor.getEjbClassName(),descriptor.getName()}));
143         }
144     }
145 }
146
Popular Tags