KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > session > HomeInterfaceNoFinderMethodNames


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.session;
24
25 import java.lang.reflect.Method JavaDoc;
26
27 import com.sun.enterprise.deployment.EjbDescriptor;
28 import com.sun.enterprise.deployment.EjbSessionDescriptor;
29 import com.sun.enterprise.tools.verifier.Result;
30 import com.sun.enterprise.tools.verifier.Verifier;
31 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
34
35 /**
36  * Session beans home interface no finder methods name test.
37  *
38  * The following are the requirements for the enterprise Bean's home interface
39  * signature:
40  *
41  * Since all session objects hide their identity, there is no need to provide
42  * a finder for them. The home interface for a session object must not define
43  * any finder methods.
44  */

45 public class HomeInterfaceNoFinderMethodNames extends EjbTest implements EjbCheck {
46     Result result = null;
47     ComponentNameConstructor compName = null;
48
49     /**
50      * Session beans home interface no finder methods name test.
51      *
52      * The following are the requirements for the enterprise Bean's home interface
53      * signature:
54      *
55      * Since all session objects hide their identity, there is no need to provide
56      * a finder for them. The home interface for a session object must not define
57      * any finder methods.
58      *
59      * @param descriptor the Enterprise Java Bean deployment descriptor
60      *
61      * @return <code>Result</code> the results for this assertion
62      */

63     public Result check(EjbDescriptor descriptor) {
64
65         result = getInitializedResult();
66         compName = getVerifierContext().getComponentNameConstructor();
67
68         if (descriptor instanceof EjbSessionDescriptor) {
69             // RULE: Session home interface are not allowed to have any
70
// finder methods
71
if(descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName()))
72                 commonToBothInterfaces(descriptor.getHomeClassName(),(EjbSessionDescriptor)descriptor);
73             if(descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName()))
74                 commonToBothInterfaces(descriptor.getLocalHomeClassName(),(EjbSessionDescriptor)descriptor);
75         }
76         if(result.getStatus() != Result.FAILED) {
77             addGoodDetails(result, compName);
78             result.passed(smh.getLocalString
79                     (getClass().getName() + ".passed",
80                     "Valid: no finder methods were found. Session bean's home interface" +
81                     " is not allowed to have any finder methods."));
82         }
83         return result;
84     }
85
86     /**
87      * This method is responsible for the logic of the test. It is called for both local and remote interfaces.
88      * @param descriptor the Enterprise Java Bean deployment descriptor
89      * @param home for the Home interface of the Ejb.
90      */

91
92     private void commonToBothInterfaces(String JavaDoc home, EjbSessionDescriptor descriptor) {
93         try {
94             Class JavaDoc c = Class.forName(home,
95                                 false,
96                                 getVerifierContext().getClassLoader());
97             for(Method JavaDoc methods : c.getDeclaredMethods()) {
98                 if(methods.getName().startsWith("find")) {
99                     addErrorDetails(result, compName);
100                     result.failed(smh.getLocalString
101                             (getClass().getName() + ".debug1",
102                                     "For Home Interface [ {0} ] Method [ {1} ]",
103                                     new Object JavaDoc[] {c.getName(),methods.getName()}));
104                     result.addErrorDetails(smh.getLocalString
105                             (getClass().getName() + ".failed",
106                                     "Improperly named method [ {0} ] was found. Session bean's home interface is not allowed to have any finder methods.",
107                                     new Object JavaDoc[] {methods.getName()}));
108                 }
109             }
110
111         } catch (ClassNotFoundException JavaDoc e) {
112             Verifier.debug(e);
113             addErrorDetails(result, compName);
114             result.failed(smh.getLocalString
115                     (getClass().getName() + ".failedException",
116                             "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]",
117                             new Object JavaDoc[] {home, descriptor.getName()}));
118         }
119     }
120 }
121
Popular Tags