FileDocCategorySizeDatePackage
StatefulSessionBeanInjection.javaAPI DocGlassfish v2 API4196Fri May 04 22:34:10 BST 2007com.sun.enterprise.tools.verifier.tests.web

StatefulSessionBeanInjection

public class StatefulSessionBeanInjection extends WebTest implements WebCheck
Assertion A stateful session bean should not be injected into a servlet.
author
bshankar@sun.com

Fields Summary
static final String
className
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(com.sun.enterprise.deployment.WebBundleDescriptor descriptor)

    
        
        // initialize the result object
        Result result = getInitializedResult();
        addWarningDetails(result,
                getVerifierContext().getComponentNameConstructor());
        result.setStatus(Result.PASSED); //default status is PASSED
        
        Set<EjbReferenceDescriptor> s = descriptor.getEjbReferenceDescriptors();
        if (s == null) return result;
        
        for(EjbReferenceDescriptor ejbRefDesc : s) {
            EjbDescriptor ejbDescriptor = ejbRefDesc.getEjbDescriptor();
            if (ejbDescriptor instanceof EjbSessionDescriptor) { // instaceof returns false if ejbDescriptor=null.
                String stateType = ((EjbSessionDescriptor)ejbDescriptor).getSessionType();
                if(EjbSessionDescriptor.STATEFUL.equals(stateType)) {
                    Set<InjectionTarget> injectionTargets = ejbRefDesc.getInjectionTargets();
                    if(injectionTargets != null) {
                        for(InjectionTarget it : injectionTargets) {
                            String itClassName = it.getClassName();
                            result.warning(smh.getLocalString(className + ".warning",
                                    "Found a stateful session bean [ {0} ] injected into [ {1} ].",
                                    new Object[]{ejbDescriptor.getEjbClassName(), itClassName}));
                        }
                    }
                }
            }
        }
        return result;