KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > homeintf > HomeMethodRmiIIOPReturn


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.homeintf;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import java.lang.ClassLoader JavaDoc;
27 import java.lang.reflect.Method JavaDoc;
28
29 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
30 import com.sun.enterprise.tools.verifier.tests.ejb.RmiIIOPUtils;
31 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
32 import com.sun.enterprise.tools.verifier.Result;
33 import com.sun.enterprise.tools.verifier.Verifier;
34 import com.sun.enterprise.deployment.EjbDescriptor;
35 import com.sun.enterprise.deployment.EjbSessionDescriptor;
36 import com.sun.enterprise.deployment.EjbEntityDescriptor;
37
38 /**
39  * Enterprise Bean's home methods argument RMI IIOP test.
40  * Each enterprise Bean class must define zero or more home methods.
41  * The method signatures must follow these rules:
42  *
43  * The methods return value must be legal types for RMI-IIOP.
44  */

45 public class HomeMethodRmiIIOPReturn extends EjbTest implements EjbCheck {
46
47
48
49     /**
50      * Enterprise Bean's home methods argument RMI IIOP test.
51      * Each enterprise Bean class must define zero or more home methods.
52      * The method signatures must follow these rules:
53      *
54      * The methods return value must be legal types for RMI-IIOP.
55      *
56      * @param descriptor the Enterprise Java Bean deployment descriptor
57      * @return <code>Result</code> the results for this assertion
58      */

59     public Result check(EjbDescriptor descriptor) {
60
61     Result result = getInitializedResult();
62 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
63
64     if ((descriptor instanceof EjbSessionDescriptor) ||
65         (descriptor instanceof EjbEntityDescriptor)) {
66         boolean oneFailed = false;
67         int foundAtLeastOne = 0;
68         try {
69         if(descriptor.getHomeClassName() == null || "".equals(descriptor.getHomeClassName())) {
70             addNaDetails(result, compName);
71             result.notApplicable(smh.getLocalString
72                      (getClass().getName() + ".notApplicable1",
73                       " [ {0} ] does not have a remote home interface. ",
74                       new Object JavaDoc[] {descriptor.getEjbClassName()}));
75             return result;
76         }
77         ClassLoader JavaDoc jcl = getVerifierContext().getClassLoader();
78         Class JavaDoc rc = Class.forName(descriptor.getHomeClassName(), false, jcl);
79
80         Class JavaDoc methodReturnType;
81         boolean homeMethodFound = false;
82         boolean isLegalRMIIIOPReturn = false;
83         for (Method JavaDoc remoteMethod : rc.getMethods()) {
84
85                     // we don't test the EJB methods
86
if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBHome"))
87                         continue;
88             if (remoteMethod.getName().startsWith("create") ||
89             remoteMethod.getName().startsWith("find") ||
90             remoteMethod.getName().startsWith("remove"))
91             continue;
92                                         
93             // reset flags from last time thru loop
94
Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, jcl);
95             // start do while loop here....
96
do {
97             
98             for (Method JavaDoc method : c.getDeclaredMethods()) {
99
100                 // reset flags from last time thru loop
101
homeMethodFound = false;
102                 isLegalRMIIIOPReturn = false;
103                 String JavaDoc methodName = "ejbHome" + Character.toUpperCase(remoteMethod.getName().charAt(0)) + remoteMethod.getName().substring(1);
104                 if (method.getName().equals(methodName)) {
105                 foundAtLeastOne++;
106                 homeMethodFound = true;
107                 // The methods arguments types must be legal types for
108
// RMI-IIOP. This means that their return values must
109
// be of valid types for RMI-IIOP,
110
methodReturnType = method.getReturnType();
111                 if (RmiIIOPUtils.isValidRmiIIOPReturnType(methodReturnType)) {
112                     // this is the right return type for method
113
isLegalRMIIIOPReturn = true;
114                 } // return valid
115

116                 // now display the appropriate results for this particular business
117
// method
118
if (homeMethodFound && isLegalRMIIIOPReturn ) {
119                     addGoodDetails(result, compName);
120                     result.addGoodDetails(smh.getLocalString
121                               (getClass().getName() + ".passed",
122                                "[ {0} ] properly declares ejbHome<METHOD> method [ {1} ] with valid RMI-IIOP return type.",
123                                new Object JavaDoc[] {descriptor.getEjbClassName(),method.getName()}));
124                 } else if (homeMethodFound && !isLegalRMIIIOPReturn) {
125                     oneFailed = true;
126                     addErrorDetails(result, compName);
127                     result.addErrorDetails(smh.getLocalString
128                                (getClass().getName() + ".failed",
129                                 "Error: ejbHome<METHOD> method [ {0} ] was found, but ejbHome<METHOD> method has illegal return value. ejbHome<METHOD> methods return type must be legal types for RMI-IIOP.",
130                                 new Object JavaDoc[] {method.getName()}));
131                 }
132                 }
133             }
134             if (oneFailed == true)
135                 break;
136             } while (((c = c.getSuperclass()) != null) && (!homeMethodFound));
137         }
138         if (foundAtLeastOne == 0) {
139             addNaDetails(result, compName);
140             result.notApplicable(smh.getLocalString
141                      (getClass().getName() + ".notApplicable1",
142                       " [ {0} ] does not declare any ejbHome<METHOD> methods. ",
143                       new Object JavaDoc[] {descriptor.getEjbClassName()}));
144         }
145         } catch (ClassNotFoundException JavaDoc e) {
146         Verifier.debug(e);
147         oneFailed = true;
148         addErrorDetails(result, compName);
149         result.failed(smh.getLocalString
150                   (getClass().getName() + ".failedException",
151                    "Error: Remote interface [ {0} ] or bean class [ {1} ] does not exist or is not loadable within bean [ {2} ].",
152                    new Object JavaDoc[] {descriptor.getRemoteClassName(),descriptor.getEjbClassName(),descriptor.getName()}));
153         }
154
155         if (oneFailed) {
156         result.setStatus(Result.FAILED);
157             } else if (foundAtLeastOne == 0) {
158                 result.setStatus(Result.NOT_APPLICABLE);
159         } else {
160         result.setStatus(Result.PASSED);
161         }
162
163         return result;
164  
165     } else {
166         addNaDetails(result, compName);
167         result.notApplicable(smh.getLocalString
168                  (getClass().getName() + ".notApplicable",
169                   "{0} expected {1} bean or {2} bean, but called with {3}.",
170                   new Object JavaDoc[] {getClass(),"Session","Entity",descriptor.getName()}));
171         return result;
172     }
173     }
174 }
175
Popular Tags