KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > session > createmethod > HomeInterfaceCreateMethodExceptionRemote


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.session.createmethod;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import com.sun.enterprise.deployment.EjbDescriptor;
27 import com.sun.enterprise.deployment.EjbSessionDescriptor;
28 import java.lang.ClassLoader JavaDoc;
29 import com.sun.enterprise.tools.verifier.tests.*;
30 import java.util.*;
31 import java.lang.reflect.*;
32 import com.sun.enterprise.tools.verifier.*;
33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
34 import com.sun.enterprise.tools.verifier.tests.ejb.EjbUtils;
35
36 /**
37  * Session beans home interface create method throws RemoteException test.
38  *
39  * The following are the requirements for the enterprise Bean's home interface
40  * signature:
41  *
42  * An Session Bean's home interface defines zero or more create(...) methods.
43  *
44  * The throws clause must include java.rmi.RemoteException.
45  */

46 public class HomeInterfaceCreateMethodExceptionRemote extends EjbTest implements EjbCheck {
47
48
49     /**
50      * Session beans home interface create method throws RemoteException test.
51      *
52      * The following are the requirements for the enterprise Bean's home interface
53      * signature:
54      *
55      * An Session Bean's home interface defines zero or more create(...) methods.
56      *
57      * The throws clause must include java.rmi.RemoteException.
58      *
59      * @param descriptor the Enterprise Java Bean deployment descriptor
60      *
61      * @return <code>Result</code> the results for this assertion
62      */

63     public Result check(EjbDescriptor descriptor) {
64
65     Result result = getInitializedResult();
66     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
67
68     if (descriptor instanceof EjbSessionDescriptor) {
69         boolean oneFailed = false;
70         boolean foundAtLeastOneRemote = false;
71         // RULE: Session home interface are only allowed to have create
72
// methods which must throw java.rmi.RemoteException
73
if(descriptor.getHomeClassName() == null || "".equals(descriptor.getHomeClassName())) {
74         result.addNaDetails(smh.getLocalString
75                        ("tests.componentNameConstructor",
76                     "For [ {0} ]",
77                     new Object JavaDoc[] {compName.toString()}));
78         result.addNaDetails(smh.getLocalString
79                     (getClass().getName() + ".notApplicable1",
80                      "No Remote Home Interface for this ejb",
81                      new Object JavaDoc[] {}));
82         return result;
83         }
84         try {
85         Context context = getVerifierContext();
86         ClassLoader JavaDoc jcl = context.getClassLoader();
87         Class JavaDoc c = Class.forName(descriptor.getHomeClassName(), false, getVerifierContext().getClassLoader());
88         Method methods[] = c.getDeclaredMethods();
89         Class JavaDoc [] methodExceptionTypes;
90         boolean throwsRemoteException = false;
91
92
93         for (int i=0; i< methods.length; i++) {
94             // clear these from last time thru loop
95
throwsRemoteException = false;
96
97             if (methods[i].getName().startsWith("create")) {
98             // set this once to indicate that test is applicable, if you didn't
99
// find any create methods, that's an error, as session beans can
100
// have one or more create methods, & when you have zero, test
101
// is failed
102
if (!foundAtLeastOneRemote) {
103                 foundAtLeastOneRemote = true;
104             }
105
106             methodExceptionTypes = methods[i].getExceptionTypes();
107                
108             // methods must also throw java.rmi.RemoteException
109
if (EjbUtils.isValidRemoteException(methodExceptionTypes)) {
110                 throwsRemoteException = true;
111             }
112
113             //report for this particular create method found in home interface
114
// now display the appropriate results for this particular create
115
// method
116
if (throwsRemoteException ) {
117                 result.addGoodDetails(smh.getLocalString
118                        ("tests.componentNameConstructor",
119                     "For [ {0} ]",
120                     new Object JavaDoc[] {compName.toString()}));
121                 result.addGoodDetails(smh.getLocalString
122                           (getClass().getName() + ".debug1",
123                            "For Home Interface [ {0} ] Method [ {1} ]",
124                            new Object JavaDoc[] {c.getName(),methods[i].getName()}));
125                 result.addGoodDetails(smh.getLocalString
126                           (getClass().getName() + ".passed",
127                            "The create method which must throw java.rmi.RemoteException was found."));
128             } else if (!throwsRemoteException) {
129                 oneFailed = true;
130                 result.addErrorDetails(smh.getLocalString
131                        ("tests.componentNameConstructor",
132                     "For [ {0} ]",
133                     new Object JavaDoc[] {compName.toString()}));
134                 result.addErrorDetails(smh.getLocalString
135                            (getClass().getName() + ".debug1",
136                             "For Home Interface [ {0} ] Method [ {1} ]",
137                             new Object JavaDoc[] {c.getName(),methods[i].getName()}));
138                 result.addErrorDetails(smh.getLocalString
139                            (getClass().getName() + ".failed",
140                             "Error: A create method was found, but did not throw java.rmi.RemoteException." ));
141             } // end of reporting for this particular 'create' method
142
} // if the home interface found a "create" method
143
} // for all the methods within the home interface class, loop
144

145
146         } catch (ClassNotFoundException JavaDoc e) {
147         Verifier.debug(e);
148         result.addErrorDetails(smh.getLocalString
149                        ("tests.componentNameConstructor",
150                     "For [ {0} ]",
151                     new Object JavaDoc[] {compName.toString()}));
152         result.failed(smh.getLocalString
153                   (getClass().getName() + ".failedException",
154                    "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]",
155                    new Object JavaDoc[] {descriptor.getHomeClassName(), descriptor.getName()}));
156         }
157
158         if (!foundAtLeastOneRemote) {
159         result.addErrorDetails(smh.getLocalString
160                        ("tests.componentNameConstructor",
161                     "For [ {0} ]",
162                     new Object JavaDoc[] {compName.toString()}));
163         result.addErrorDetails(smh.getLocalString
164                        (getClass().getName() + ".debug3",
165                     "For Home Interface [ {0} ]",
166                     new Object JavaDoc[] {descriptor.getHomeClassName()}));
167         result.addErrorDetails(smh.getLocalString
168                        (getClass().getName() + ".failed1",
169                     "No create method was found in [ {0} ]",
170                     new Object JavaDoc[] {descriptor.getHomeClassName()}));
171         result.setStatus(result.FAILED);
172         } else {
173         if (oneFailed) {
174             result.setStatus(result.FAILED);
175         } else {
176             result.setStatus(result.PASSED);
177         }
178         }
179          
180         return result;
181         
182     } else {
183         result.addErrorDetails(smh.getLocalString
184                        ("tests.componentNameConstructor",
185                     "For [ {0} ]",
186                     new Object JavaDoc[] {compName.toString()}));
187         result.notApplicable(smh.getLocalString
188                  (getClass().getName() + ".notApplicable",
189                   "[ {0} ] expected {1} bean, but called with {2} bean.",
190                   new Object JavaDoc[] {getClass(),"Session","Entity"}));
191         return result;
192     }
193     }
194 }
195
Popular Tags