KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > intf > remoteintf > RemoteInterfaceSuperInterface


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.intf.remoteintf;
24
25 import com.sun.enterprise.deployment.EjbDescriptor;
26 import com.sun.enterprise.deployment.EjbEntityDescriptor;
27 import com.sun.enterprise.deployment.EjbSessionDescriptor;
28 import com.sun.enterprise.tools.verifier.Result;
29 import com.sun.enterprise.tools.verifier.Verifier;
30 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
31 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
33 import com.sun.enterprise.tools.verifier.tests.ejb.RmiIIOPUtils;
34
35 import java.util.logging.Level JavaDoc;
36
37 /**
38  * Remote interface/business methods test.
39  * Verify the following:
40  *
41  * The remote interface is allowed to have superinterfaces. Use of interface
42  * inheritance is subject to the RMI-IIOP rules for the definition of remote
43  * interfaces.
44  *
45  */

46 public class RemoteInterfaceSuperInterface extends EjbTest implements EjbCheck {
47     
48     /**
49      * Remote interface/business methods test.
50      * Verify the following:
51      *
52      * The remote interface is allowed to have superinterfaces. Use of interface
53      * inheritance is subject to the RMI-IIOP rules for the definition of remote
54      * interfaces.
55      *
56      * @param descriptor the Enterprise Java Bean deployment descriptor
57      *
58      * @return <code>Result</code> the results for this assertion
59      */

60     public Result check(EjbDescriptor descriptor) {
61         
62         Result result = getInitializedResult();
63         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
64         
65         if (!(descriptor instanceof EjbSessionDescriptor) &&
66                 !(descriptor instanceof EjbEntityDescriptor)) {
67             addNaDetails(result, compName);
68             result.notApplicable(smh.getLocalString
69                     ("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable1",
70                     "Test apply only to session or entity beans."));
71             return result;
72         }
73         
74         if(descriptor.getRemoteClassName() == null || "".equals(descriptor.getRemoteClassName())){
75             addNaDetails(result, compName);
76             result.notApplicable(smh.getLocalString
77                     ("com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfaceTest.notApplicable",
78                     "Not Applicable because, EJB [ {0} ] does not have {1} Interface.",
79                     new Object JavaDoc[] {descriptor.getEjbClassName(), "Remote"}));
80             
81             return result;
82         }
83         
84         
85         boolean oneFailed = false;
86         try {
87             ClassLoader JavaDoc jcl = getVerifierContext().getClassLoader();
88             Class JavaDoc c = Class.forName(descriptor.getRemoteClassName(), false, jcl);
89             Class JavaDoc remote = c;
90             boolean validRemoteInterface = false;
91             boolean ok = false;
92             // walk up the class tree
93
do {
94                 Class JavaDoc[] interfaces = c.getInterfaces();
95                 if ( interfaces.length == 0 ) {
96                     ok = true;
97                 }
98                 for (Class JavaDoc intf : interfaces) {
99                     logger.log(Level.FINE, getClass().getName() + ".debug1",
100                             new Object JavaDoc[] {intf.getName()});
101                     
102                     // The remote interface is allowed to have superinterfaces. Use
103
// of interface inheritance is subject to the RMI-IIOP rules for
104
// the definition of remote interfaces.
105
// requirement is met if one superinterface complies.
106
if (!ok) {
107                         ok = RmiIIOPUtils.isValidRmiIIOPInterface(intf);
108                     }
109                     
110                     // check the methods now.
111
if (RmiIIOPUtils.isValidRmiIIOPInterfaceMethods(intf)) {
112                         // this interface is valid, continue
113
if (intf.getName().equals("javax.ejb.EJBObject")) {
114                             validRemoteInterface = true;
115                             break;
116                         }
117                     } else {
118                         oneFailed = true;
119                         addErrorDetails(result, compName);
120                         result.addErrorDetails(smh.getLocalString
121                                 (getClass().getName() + ".failed",
122                                 "Error: [ {0} ] does not properly conform to " +
123                                 "rules of RMI-IIOP for superinterfaces. All " +
124                                 "enterprise beans remote interfaces are allowed " +
125                                 "to have superinterfaces that conform to the " +
126                                 "rules of RMI-IIOP for superinterfaces . [ {1} ]" +
127                                 " is not a valid remote interface.",
128                                 new Object JavaDoc[] {intf.getName(),descriptor.getRemoteClassName()}));
129                     }
130                     
131                 }
132                 
133             } while ((((c=c.getSuperclass()) != null) && (!validRemoteInterface)));
134             
135             if (!ok) { // check that one superinterface met rmiiiop requirement
136
oneFailed = true;
137                 addErrorDetails(result, compName);
138                 result.addErrorDetails(smh.getLocalString
139                         (getClass().getName() + ".failed",
140                         "Error: [ {0} ] does not properly conform to rules of " +
141                         "RMI-IIOP for superinterfaces. All enterprise beans " +
142                         "remote interfaces are allowed to have superinterfaces " +
143                         "that conform to the rules of RMI-IIOP for superinterfaces. " +
144                         " [ {1} ] is not a valid remote interface.",
145                         new Object JavaDoc[] {remote.getName(),descriptor.getRemoteClassName()}));
146             }
147             
148             if (validRemoteInterface){
149                 addGoodDetails(result, compName);
150                 result.passed(smh.getLocalString
151                         (getClass().getName() + ".passed",
152                         "[ {0} ] properly conforms to rules of RMI-IIOP for superinterfaces.",
153                         new Object JavaDoc[] {descriptor.getRemoteClassName()}));
154             }
155         } catch (ClassNotFoundException JavaDoc e) {
156             Verifier.debug(e);
157             addGoodDetails(result, compName);
158             result.failed(smh.getLocalString
159                     (getClass().getName() + ".failedException",
160                     "Error: Remote interface [ {0} ] does not exist or is not " +
161                     "loadable within bean [ {1} ]",
162                     new Object JavaDoc[] {descriptor.getRemoteClassName(),descriptor.getName()}));
163             oneFailed = true;
164         }
165         if (oneFailed) {
166             result.setStatus(Result.FAILED);
167         } else {
168             result.setStatus(Result.PASSED);
169         }
170         return result;
171     }
172 }
173
Popular Tags