KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > StatefulSessionBeanInjection


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
24
25 package com.sun.enterprise.tools.verifier.tests.web;
26
27 import com.sun.enterprise.deployment.EjbDescriptor;
28 import com.sun.enterprise.deployment.EjbReferenceDescriptor;
29 import com.sun.enterprise.deployment.EjbSessionDescriptor;
30 import com.sun.enterprise.deployment.InjectionTarget;
31 import com.sun.enterprise.tools.verifier.Result;
32 import com.sun.enterprise.deployment.WebBundleDescriptor;
33 import java.util.Set JavaDoc;
34
35 /**
36  * Assertion
37  *
38  * A stateful session bean should not be injected into a servlet.
39  *
40  * @author bshankar@sun.com
41  */

42 public class StatefulSessionBeanInjection extends WebTest implements WebCheck {
43     
44     final static String JavaDoc className = StatefulSessionBeanInjection.class.getName();
45     
46     public Result check(WebBundleDescriptor descriptor) {
47         // initialize the result object
48
Result result = getInitializedResult();
49         addWarningDetails(result,
50                 getVerifierContext().getComponentNameConstructor());
51         result.setStatus(Result.PASSED); //default status is PASSED
52

53         Set JavaDoc<EjbReferenceDescriptor> s = descriptor.getEjbReferenceDescriptors();
54         if (s == null) return result;
55         
56         for(EjbReferenceDescriptor ejbRefDesc : s) {
57             EjbDescriptor ejbDescriptor = ejbRefDesc.getEjbDescriptor();
58             if (ejbDescriptor instanceof EjbSessionDescriptor) { // instaceof returns false if ejbDescriptor=null.
59
String JavaDoc stateType = ((EjbSessionDescriptor)ejbDescriptor).getSessionType();
60                 if(EjbSessionDescriptor.STATEFUL.equals(stateType)) {
61                     Set JavaDoc<InjectionTarget> injectionTargets = ejbRefDesc.getInjectionTargets();
62                     if(injectionTargets != null) {
63                         for(InjectionTarget it : injectionTargets) {
64                             String JavaDoc itClassName = it.getClassName();
65                             result.warning(smh.getLocalString(className + ".warning",
66                                     "Found a stateful session bean [ {0} ] injected into [ {1} ].",
67                                     new Object JavaDoc[]{ejbDescriptor.getEjbClassName(), itClassName}));
68                         }
69                     }
70                 }
71             }
72         }
73         return result;
74     }
75     
76 }
77
Popular Tags