KickJava   Java API By Example, From Geeks To Geeks.

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


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 ejbHome methods argument RMI IIOP test.
40  * Each enterprise Bean class may define zero or more ejbHome methods.
41  * The method signatures must follow these rules:
42  *
43  * The methods arguments must be legal types for RMI-IIOP.
44  */

45 public class HomeMethodRmiIIOPArgs extends EjbTest implements EjbCheck {
46
47
48
49     /**
50      * Enterprise Bean's ejbHome methods argument RMI IIOP test.
51      * Each enterprise Bean class may define zero or more ejbHome methods.
52      * The method signatures must follow these rules:
53      *
54      * The methods arguments 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             result.addNaDetails(smh.getLocalString
71                     ("tests.componentNameConstructor",
72                      "For [ {0} ]",
73                      new Object JavaDoc[] {compName.toString()}));
74             result.notApplicable(smh.getLocalString
75                      (getClass().getName() + ".notApplicable1",
76                       " [ {0} ] does not have a remote home interface. ",
77                       new Object JavaDoc[] {descriptor.getEjbClassName()}));
78             return result;
79         }
80
81         ClassLoader JavaDoc jcl = getVerifierContext().getClassLoader();
82         Class JavaDoc rc = Class.forName(descriptor.getHomeClassName(), false, jcl);
83
84         Class JavaDoc [] homeMethodParameterTypes;
85         boolean homeMethodFound = false;
86         boolean isLegalRMIIIOP = false;
87     
88         for (Method JavaDoc remoteMethod : rc.getMethods()) {
89
90                     // we don't test the EJB methods
91
if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBHome"))
92                         continue;
93             if (remoteMethod.getName().startsWith("create") ||
94             remoteMethod.getName().startsWith("find") ||
95             remoteMethod.getName().startsWith("remove"))
96             continue;
97                                         
98             // reset flags from last time thru loop
99
Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, jcl);
100             // start do while loop here....
101
do {
102             
103             for (Method JavaDoc method : c.getDeclaredMethods()) {
104                 isLegalRMIIIOP = false;
105                 homeMethodFound = false;
106                     
107                 String JavaDoc methodName = "ejbHome" + Character.toUpperCase(remoteMethod.getName().charAt(0)) + remoteMethod.getName().substring(1);
108                 
109                 if (method.getName().equals(methodName)) {
110                 foundAtLeastOne++;
111                 homeMethodFound = true;
112             
113                 // The methods arguments types must be legal types for RMI-IIOP.
114
homeMethodParameterTypes = method.getParameterTypes();
115                 if (RmiIIOPUtils.isValidRmiIIOPParameters(homeMethodParameterTypes)) {
116                     // these method parameters are valid, continue
117
isLegalRMIIIOP = true;
118                 }
119                 
120                 // now display the appropriate results for this particular ejbHome<Method>
121
// method
122
if (homeMethodFound && isLegalRMIIIOP ) {
123                     addGoodDetails(result, compName);
124                     result.addGoodDetails(smh.getLocalString
125                               (getClass().getName() + ".passed",
126                                "[ {0} ] properly declares ejbHome<Method> method " +
127                                 "[ {1} ] with valid RMI-IIOP parameter types.",
128                                new Object JavaDoc[] {descriptor.getEjbClassName(),method.getName()}));
129                 } else if (homeMethodFound && !isLegalRMIIIOP) {
130                     oneFailed = true;
131                     addErrorDetails(result, compName);
132                     result.addErrorDetails(smh.getLocalString
133                                (getClass().getName() + ".failed",
134                                 "Error: ejbHome<Method> method [ {0} ] was found, " +
135                                 "but ejbHome<Method> method has illegal parameter " +
136                                 "values. ejbHome<Method> methods arguments types " +
137                                 "must be legal types for RMI-IIOP.",
138                                 new Object JavaDoc[] {method.getName()}));
139                     break;
140                 }
141                 }
142             }
143             if (oneFailed == true)
144                 break;
145             } while (((c = c.getSuperclass()) != null) && (!homeMethodFound));
146         }
147         if (foundAtLeastOne == 0) {
148             addNaDetails(result, compName);
149             result.notApplicable(smh.getLocalString
150                      (getClass().getName() + ".notApplicable1",
151                       " [ {0} ] does not declare any ejbHome<Method> methods. ",
152                       new Object JavaDoc[] {descriptor.getEjbClassName()}));
153         }
154         } catch (ClassNotFoundException JavaDoc e) {
155         Verifier.debug(e);
156         oneFailed = true;
157         addErrorDetails(result, compName);
158         result.failed(smh.getLocalString
159                   (getClass().getName() + ".failedException",
160                    "Error: Remote interface [ {0} ] or bean class [ {1} ] does not " +
161                    "exist or is not loadable within bean [ {2} ].",
162                    new Object JavaDoc[] {descriptor.getRemoteClassName(),descriptor.getEjbClassName(),descriptor.getName()}));
163         }
164
165         if (oneFailed) {
166         result.setStatus(Result.FAILED);
167             } else if (foundAtLeastOne == 0) {
168                 result.setStatus(Result.NOT_APPLICABLE);
169         } else {
170         result.setStatus(Result.PASSED);
171         }
172
173         return result;
174  
175     } else {
176         addNaDetails(result, compName);
177         result.notApplicable(smh.getLocalString
178                  (getClass().getName() + ".notApplicable",
179                   "{0} expected {1} bean or {2} bean, but called with {3}.",
180                   new Object JavaDoc[] {getClass(),"Session","Entity",descriptor.getName()}));
181         return result;
182     }
183     }
184 }
185
Popular Tags