KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > session > stateless > StatelessCreateNoArgs


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.stateless;
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.lang.reflect.*;
31 import com.sun.enterprise.tools.verifier.*;
32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
33
34 /**
35  * Stateless session are only allowed to have create methods with no arguments.
36  */

37 public class StatelessCreateNoArgs extends EjbTest implements EjbCheck {
38     Result result = null;
39     ComponentNameConstructor compName = null;
40
41     /**
42      * Stateless session are only allowed to have create methods with no arguments.
43      *
44      * @param descriptor the Enterprise Java Bean deployment descriptor
45      *
46      * @return <code>Result</code> the results for this assertion
47      */

48     public Result check(EjbDescriptor descriptor) {
49
50         result = getInitializedResult();
51         compName = getVerifierContext().getComponentNameConstructor();
52
53         if (descriptor instanceof EjbSessionDescriptor) {
54             String JavaDoc stateType = ((EjbSessionDescriptor)descriptor).getSessionType();
55             if (EjbSessionDescriptor.STATELESS.equals(stateType)) {
56                 // RULE: Stateless session are only allowed to have create
57
// methods with no arguments.
58
if(descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName()))
59                     commonToBothInterfaces(descriptor.getHomeClassName(),(EjbSessionDescriptor)descriptor);
60                 if(descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName()))
61                     commonToBothInterfaces(descriptor.getLocalHomeClassName(),(EjbSessionDescriptor)descriptor);
62             }
63         }
64         if (result.getStatus()!=Result.FAILED) {
65             addGoodDetails(result, compName);
66             result.passed(smh.getLocalString
67                     (getClass().getName() + ".passed",
68                             "The bean's Home Interface properly defines one create Method with no args"));
69         }
70         return result;
71     }
72
73     /**
74      * This method is responsible for the logic of the test. It is called for both local and remote interfaces.
75      * @param descriptor the Enterprise Java Bean deployment descriptor
76      * @param home for the Home interface of the Ejb.
77      *
78      */

79
80
81     private void commonToBothInterfaces(String JavaDoc home, EjbSessionDescriptor descriptor) {
82         try {
83
84             Class JavaDoc c = Class.forName(home, false, getVerifierContext().getClassLoader());
85             Method m = null;
86             for(Method methods : c.getDeclaredMethods()) {
87                 if (methods.getName().equals("create")) {
88                     m = methods;
89                     break;
90                 }
91             }
92             //check if this method m does not have any paramenter
93
if (m != null) {
94                 Class JavaDoc cc[] = m.getParameterTypes();
95                 if (cc.length > 0) {
96                     addErrorDetails(result, compName);
97                     result.failed(smh.getLocalString
98                             (getClass().getName() + ".failed",
99                             "Error: The create method has one or more parameters \n" +
100                             "within bean [ {0} ]. Stateless session are only allowed \n" +
101                             "to have create methods with no arguments.",
102                              new Object JavaDoc[] {home}));
103                 }
104             } else {
105                 // set status to FAILED, 'cause there is not even
106
// a create method to begin with, regardless of its parameters
107
addErrorDetails(result, compName);
108                 result.failed(smh.getLocalString
109                         (getClass().getName() + ".failed1",
110                                 "Error: No Create method exists within bean [ {0} ]",
111                                 new Object JavaDoc[] {home}));
112             }
113         } catch (ClassNotFoundException JavaDoc e) {
114             Verifier.debug(e);
115             addErrorDetails(result, compName);
116             result.failed(smh.getLocalString
117                     (getClass().getName() + ".failedException",
118                             "Error: Class [ {0} ] not found within bean [ {1} ]",
119                             new Object JavaDoc[] {home, descriptor.getName()}));
120         }
121     }
122 }
123
Popular Tags