KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
37  * Enterprise Bean's business(...) methods argument RMI IIOP test.
38  * Each enterprise Bean class must define zero or more business(...) methods.
39  * The method signatures must follow these rules:
40  *
41  * The methods return value must be legal types for RMI-IIOP.
42  */

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

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