KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > entity > findermethod > HomeInterfaceFindMethodExceptionRemote


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.entity.findermethod;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import com.sun.enterprise.deployment.EjbDescriptor;
27 import com.sun.enterprise.deployment.EjbEntityDescriptor;
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  * Entity beans home interface find<METHOD> method throws
38  * java.rmi.RemoteException test.
39  *
40  * The following are the requirements for the enterprise Bean's home interface
41  * find<METHOD> signature:
42  *
43  * An Entity Bean's home interface defines one or more find<METHOD>(...)
44  * methods.
45  *
46  * The throws clause must include java.rmi.RemoteException.
47  */

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

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

143   
144         } catch (ClassNotFoundException JavaDoc e) {
145             Verifier.debug(e);
146             result.addErrorDetails(smh.getLocalString
147                        ("tests.componentNameConstructor",
148                         "For [ {0} ]",
149                         new Object JavaDoc[] {compName.toString()}));
150             result.failed(smh.getLocalString
151                   (getClass().getName() + ".failedException",
152                    "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]",
153                    new Object JavaDoc[] {descriptor.getHomeClassName(), descriptor.getName()}));
154         }
155   
156         if (oneFailed) {
157             result.setStatus(result.FAILED);
158         } else {
159             result.setStatus(result.PASSED);
160         }
161         return result;
162         } else { //if (CONTAINER_PERSISTENCE.equals(persistence))
163
result.addNaDetails(smh.getLocalString
164                    ("tests.componentNameConstructor",
165                     "For [ {0} ]",
166                     new Object JavaDoc[] {compName.toString()}));
167         result.notApplicable(smh.getLocalString
168                      (getClass().getName() + ".notApplicable2",
169                       "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.",
170                       new Object JavaDoc[] {EjbEntityDescriptor.BEAN_PERSISTENCE,descriptor.getName(),persistence}));
171         return result;
172         }
173         
174     } else {
175         result.addNaDetails(smh.getLocalString
176                    ("tests.componentNameConstructor",
177                     "For [ {0} ]",
178                     new Object JavaDoc[] {compName.toString()}));
179         result.notApplicable(smh.getLocalString
180                  (getClass().getName() + ".notApplicable",
181                   "{0} expected {1} bean, but called with {2} bean",
182                   new Object JavaDoc[] {getClass(),"Entity","Session"}));
183         return result;
184     }
185     }
186 }
187
Popular Tags