FileDocCategorySizeDatePackage
AbstractPUMatchingEMandEMFRefTest.javaAPI DocGlassfish v2 API5991Fri May 04 22:33:26 BST 2007com.sun.enterprise.tools.verifier.tests

AbstractPUMatchingEMandEMFRefTest

public abstract class AbstractPUMatchingEMandEMFRefTest extends VerifierTest implements VerifierCheck
For every entity manager reference and entity manager factory reference in a component (ejb/servlet/app-client etc), there must be a matching persistence unit defined in the scope of that component.
author
Sanjeeb.Sahoo@Sun.COM

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

        
        // initialize the result object
        Result result = getInitializedResult();
        addErrorDetails(result,
                getVerifierContext().getComponentNameConstructor());
        result.setStatus(Result.PASSED); //default status is PASSED
        
        BundleDescriptor bundleDescriptor = getBundleDescriptor(descriptor);
        
        for (EntityManagerReferenceDescriptor emRefDesc : getEntityManagerReferenceDescriptors(descriptor)) {
            String referringUnitName = emRefDesc.getUnitName();
            PersistenceUnitDescriptor pu = bundleDescriptor.findReferencedPU(referringUnitName);
            if (pu == null) {
                result.failed(smh.getLocalString(
                        className + "failed",
                        "There is no unique persistence unit found by name " +
                        "[ {0} ] in the scope of this component.",
                        new Object[]{referringUnitName}));
            } else {
                result.passed(smh.getLocalString(
                        className + "passed",
                        "Found a persistence unit by name [ {0} ] in the scope of this component",
                        new Object[]{referringUnitName}));
            }
        }
        for (EntityManagerFactoryReferenceDescriptor emfRefDesc : getEntityManagerFactoryReferenceDescriptors(descriptor)) {
            String referringUnitName = emfRefDesc.getUnitName();
            PersistenceUnitDescriptor pu = bundleDescriptor.findReferencedPU(referringUnitName);
            if (pu == null) {
                result.failed(smh.getLocalString(
                        className + "failed",
                        "There is no unique persistence unit found by name " +
                        "[ {0} ] in the scope of this component.",
                        new Object[]{referringUnitName}));
            } else {
                result.passed(smh.getLocalString(
                        className + "passed",
                        "Found a persistence unit by name [ {0} ] in the scope of this component",
                        new Object[]{referringUnitName}));
            }
        }
        
        StringBuilder visiblePUNames = new StringBuilder();
        final Map<String, PersistenceUnitDescriptor> visiblePUs =
                bundleDescriptor.getVisiblePUs();
        int count = 0;
        for(String puName : visiblePUs.keySet()) {
            visiblePUNames.append(puName);
            if(visiblePUs.size() != ++count) { // end not yet reached
                visiblePUNames.append(", ");
            }
        }
        String message = smh.getLocalString(className + ".puList",
                "PUs that are visible to this component are: [ {0} ]",
                new Object[]{visiblePUNames});
        result.addErrorDetails(message);
        result.addGoodDetails(message);
        
        return result;
    
protected abstract BundleDescriptorgetBundleDescriptor(Descriptor descriptor)

protected abstract java.util.CollectiongetEntityManagerFactoryReferenceDescriptors(Descriptor descriptor)

protected abstract java.util.CollectiongetEntityManagerReferenceDescriptors(Descriptor descriptor)