KickJava   Java API By Example, From Geeks To Geeks.

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


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

47 public class RemoteHomeInterfaceSuperInterface extends EjbTest implements EjbCheck {
48     
49     /**
50      * Enterprise beans home interface test.
51      *
52      * The following are the requirements for the enterprise Bean's home interface
53      * signature:
54      *
55      * The home interface is allowed to have superinterfaces. Use of interface
56      * inheritance is subject to the RMI-IIOP rules for the definition of remote
57      * interfaces.
58      *
59      * @param descriptor the Enterprise Java Bean deployment descriptor
60      * @return <code>Result</code> the results for this assertion
61      */

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