1 23 24 25 package com.sun.enterprise.tools.verifier.tests; 26 27 import com.sun.enterprise.deployment.*; 28 import com.sun.enterprise.tools.verifier.Result; 29 30 import java.util.Collection ; 31 import java.util.HashMap ; 32 import java.util.Map ; 33 34 41 public abstract class AbstractPUMatchingEMandEMFRefTest extends VerifierTest 42 implements VerifierCheck { 43 final static String className = AbstractPUMatchingEMandEMFRefTest.class.getName(); 44 public Result check(Descriptor descriptor) { 45 Result result = getInitializedResult(); 47 addErrorDetails(result, 48 getVerifierContext().getComponentNameConstructor()); 49 result.setStatus(Result.PASSED); 51 BundleDescriptor bundleDescriptor = getBundleDescriptor(descriptor); 52 53 for (EntityManagerReferenceDescriptor emRefDesc : getEntityManagerReferenceDescriptors(descriptor)) { 54 String referringUnitName = emRefDesc.getUnitName(); 55 PersistenceUnitDescriptor pu = bundleDescriptor.findReferencedPU(referringUnitName); 56 if (pu == null) { 57 result.failed(smh.getLocalString( 58 className + "failed", 59 "There is no unique persistence unit found by name " + 60 "[ {0} ] in the scope of this component.", 61 new Object []{referringUnitName})); 62 } else { 63 result.passed(smh.getLocalString( 64 className + "passed", 65 "Found a persistence unit by name [ {0} ] in the scope of this component", 66 new Object []{referringUnitName})); 67 } 68 } 69 for (EntityManagerFactoryReferenceDescriptor emfRefDesc : getEntityManagerFactoryReferenceDescriptors(descriptor)) { 70 String referringUnitName = emfRefDesc.getUnitName(); 71 PersistenceUnitDescriptor pu = bundleDescriptor.findReferencedPU(referringUnitName); 72 if (pu == null) { 73 result.failed(smh.getLocalString( 74 className + "failed", 75 "There is no unique persistence unit found by name " + 76 "[ {0} ] in the scope of this component.", 77 new Object []{referringUnitName})); 78 } else { 79 result.passed(smh.getLocalString( 80 className + "passed", 81 "Found a persistence unit by name [ {0} ] in the scope of this component", 82 new Object []{referringUnitName})); 83 } 84 } 85 86 StringBuilder visiblePUNames = new StringBuilder (); 87 final Map <String , PersistenceUnitDescriptor> visiblePUs = 88 bundleDescriptor.getVisiblePUs(); 89 int count = 0; 90 for(String puName : visiblePUs.keySet()) { 91 visiblePUNames.append(puName); 92 if(visiblePUs.size() != ++count) { visiblePUNames.append(", "); 94 } 95 } 96 String message = smh.getLocalString(className + ".puList", 97 "PUs that are visible to this component are: [ {0} ]", 98 new Object []{visiblePUNames}); 99 result.addErrorDetails(message); 100 result.addGoodDetails(message); 101 102 return result; 103 } 104 105 protected abstract BundleDescriptor getBundleDescriptor( 106 Descriptor descriptor); 107 108 protected abstract Collection <EntityManagerReferenceDescriptor> 109 getEntityManagerReferenceDescriptors(Descriptor descriptor); 110 111 protected abstract Collection <EntityManagerFactoryReferenceDescriptor> 112 getEntityManagerFactoryReferenceDescriptors(Descriptor descriptor); 113 114 } 115 | Popular Tags |