KickJava   Java API By Example, From Geeks To Geeks.

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


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.ejb.RmiIIOPUtils;
33 import com.sun.enterprise.tools.verifier.tests.*;
34
35 /**
36  * Enterprise Bean's business(...) methods argument RMI IIOP test.
37  * Each enterprise Bean class must define zero or more business(...) methods.
38  * The method signatures must follow these rules:
39  *
40  * The methods arguments must be legal types for RMI-IIOP.
41  */

42 public class BusinessMethodRmiIIOPArgs extends EjbTest implements EjbCheck {
43     
44     Result result = null;
45     ComponentNameConstructor compName = null;
46     /**
47      * Enterprise Bean's business(...) methods argument RMI IIOP test.
48      * Each enterprise Bean class must define zero or more business(...)
49      * methods. The method signatures must follow these rules:
50      *
51      * The methods arguments must be legal types for RMI-IIOP.
52      *
53      * @param descriptor the Enterprise Java Bean deployment descriptor
54      *
55      * @return <code>Result</code> the results for this assertion
56      */

57     public Result check(EjbDescriptor descriptor) {
58         
59         result = getInitializedResult();
60         compName = getVerifierContext().getComponentNameConstructor();
61         
62         if ((descriptor instanceof EjbSessionDescriptor) ||
63                 (descriptor instanceof EjbEntityDescriptor)) {
64             if(descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName()))
65                 commonToBothInterfaces(descriptor.getRemoteClassName(),descriptor);
66             
67             Set JavaDoc<String JavaDoc> remoteInterfaces = descriptor.getRemoteBusinessClassNames();
68             for (String JavaDoc remoteIntf : remoteInterfaces)
69                 commonToBothInterfaces(remoteIntf, descriptor);
70         }
71         if(result.getStatus() != Result.FAILED) {
72             addGoodDetails(result, compName);
73             result.passed(smh.getLocalString
74                     (getClass().getName() + ".passed",
75                     "Proper declaration of business method(s) found."));
76         }
77         return result;
78     }
79     
80     private void commonToBothInterfaces(String JavaDoc intf, EjbDescriptor descriptor) {
81         try {
82             Class JavaDoc intfClass = Class.forName(intf,
83                                             false,
84                                             getVerifierContext().getClassLoader());
85             
86             for (Method remoteMethod : intfClass.getMethods()) {
87                 // we don't test the EJB methods
88
if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBObject"))
89                     continue;
90                 
91                 Class JavaDoc beanClass = Class.forName(descriptor.getEjbClassName(),
92                                                 false,
93                                                 getVerifierContext().getClassLoader());
94                 for (Method method : beanClass.getMethods()) {
95                     
96                     if (method.getName().equals(remoteMethod.getName()) &&
97                             !RmiIIOPUtils.isValidRmiIIOPParameters(method.getParameterTypes())) {
98                     // The methods arguments types must be legal types for RMI-IIOP.
99
addErrorDetails(result, compName);
100                         result.failed(smh.getLocalString
101                                 (getClass().getName() + ".failed",
102                                 "Error: business method [ {0} ] was found, but " +
103                                 "business method has invalid parameter values. " +
104                                 "Business method parameter types must be valid " +
105                                 "types for RMI-IIOP.",
106                                 new Object JavaDoc[] {method.getName()}));
107                     }
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: Remote interface [ {0} ] or bean class [ {1} ] does " +
117                     "not exist or is not loadable within bean [ {2} ].",
118                     new Object JavaDoc[] {descriptor.getRemoteClassName(),
119                                   descriptor.getEjbClassName(),
120                                   descriptor.getName()}));
121         }
122     }
123 }
124
Popular Tags