KickJava   Java API By Example, From Geeks To Geeks.

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


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.stateless;
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  * Stateless session beans home interface create method return test.
36  * The home interface of a stateless session Bean must have a create method that
37  * takes no arguments, and returns the session Bean's remote interface.
38  */

39 public class StatelessCreateReturn extends EjbTest implements EjbCheck {
40     boolean foundAtLeastOneCreate = false;
41     Result result = null;
42     ComponentNameConstructor compName = null;
43
44     /**
45      * Stateless session beans home interface create method return test.
46      * The home interface of a stateless session Bean must have a create method that
47      * takes no arguments, and returns the session Bean's remote interface.
48      *
49      * @param descriptor the Enterprise Java Bean deployment descriptor
50      *
51      * @return <code>Result</code> the results for this assertion
52      */

53     public Result check(EjbDescriptor descriptor) {
54
55         result = getInitializedResult();
56         compName = getVerifierContext().getComponentNameConstructor();
57
58         if (descriptor instanceof EjbSessionDescriptor) {
59             String JavaDoc stateType = ((EjbSessionDescriptor)descriptor).getSessionType();
60             if (EjbSessionDescriptor.STATELESS.equals(stateType)) {
61                 // RULE: Stateless session are only allowed to have create
62
// methods with no arguments, and returns the session Bean's
63
// remote interface. The home interface must not have any
64
// other create methods.
65
if (descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName()) &&
66                         descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName()) )
67                     commonToBothInterfaces(descriptor.getRemoteClassName(),descriptor.getHomeClassName(),(EjbSessionDescriptor)descriptor);
68
69                 if (descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName())&&
70                         descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName()))
71                     commonToBothInterfaces(descriptor.getLocalClassName(),descriptor.getLocalHomeClassName() ,(EjbSessionDescriptor)descriptor);
72
73                 if(result.getStatus() != Result.FAILED) {
74                     addGoodDetails(result, compName);
75                     result.passed(smh.getLocalString
76                             (getClass().getName() +".passed",
77                                     "create method is properly defined in the remote/local home interface"));
78                 }
79                 return result;
80             }
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 home for the Home interface of the Ejb.
89      * @param remote Remote/Local interface
90      */

91
92     private void commonToBothInterfaces(String JavaDoc remote, String JavaDoc home, EjbSessionDescriptor descriptor) {
93         try {
94             Class JavaDoc c = Class.forName(home, false, getVerifierContext().getClassLoader());
95             for (Method JavaDoc methods : c.getDeclaredMethods()) {
96                 if (methods.getName().startsWith("create")) {
97                     Class JavaDoc methodReturnType = methods.getReturnType();
98                     if (!(methodReturnType.getName().equals(remote))) {
99                         addErrorDetails(result, compName);
100                         result.addErrorDetails(smh.getLocalString
101                                 (getClass().getName() + ".debug1",
102                                         "For Home Interface [ {0} ] Method [ {1} ]",
103                                         new Object JavaDoc[] {home,methods.getName()}));
104                         result.addErrorDetails(smh.getLocalString
105                                 (getClass().getName() + ".failed",
106                                         "Error: A Create method was found, but the " +
107                                 "return type [ {0} ] was not the Remote/Local interface" ,
108                                         new Object JavaDoc[] {methodReturnType.getName()}));
109
110                     }
111                 }
112             }
113         } catch (ClassNotFoundException JavaDoc e) {
114             Verifier.debug(e);
115             addErrorDetails(result, compName);
116             result.failed(smh.getLocalString
117                     (getClass().getName() + ".failedException",
118                             "Error: Home/Local Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]",
119                             new Object JavaDoc[] {home, descriptor.getName()}));
120         }
121     }
122 }
123
Popular Tags