1 23 24 25 package com.sun.enterprise.tools.verifier.tests.persistence; 26 27 import com.sun.enterprise.deployment.Descriptor; 28 import com.sun.enterprise.deployment.PersistenceUnitDescriptor; 29 import com.sun.enterprise.deployment.PersistenceUnitsDescriptor; 30 import com.sun.enterprise.tools.verifier.Result; 31 import com.sun.enterprise.tools.verifier.tests.VerifierCheck; 32 import com.sun.enterprise.tools.verifier.tests.VerifierTest; 33 import java.util.List ; 34 import java.util.ArrayList ; 35 36 46 public class DuplicatePUNameTest extends VerifierTest implements VerifierCheck { 47 public Result check(Descriptor descriptor) { 48 PersistenceUnitDescriptor pu = PersistenceUnitDescriptor.class.cast( 49 descriptor); 50 Result result = getInitializedResult(); 51 addErrorDetails(result, getVerifierContext().getComponentNameConstructor()); 52 result.setStatus(Result.PASSED); int count = 0; 54 for(PersistenceUnitDescriptor nextPU : getPUsInSameScope(pu)) { 55 result.addErrorDetails(smh.getLocalString(getClass().getName() + "puName", 56 "Found a persistence unit by name [ {0} ] in persistence unit root [ {1} ]", 57 new Object []{nextPU.getName(), nextPU.getPuRoot()})); 58 if (nextPU.getName().equals(pu.getName())) count++; 59 } 60 if (count != 1) { 61 result.failed(smh.getLocalString(getClass().getName() + "failed", 62 "There are [ {0} ] number of persistence units by name [ {1} ]", 63 new Object []{count, pu.getName()})); 64 } 65 return result; 66 } 67 68 71 private List <PersistenceUnitDescriptor> getPUsInSameScope(PersistenceUnitDescriptor pu) { 72 List <PersistenceUnitDescriptor> result; 73 if(pu.getParent().getParent().isApplication()) { 74 result = pu.getParent().getPersistenceUnitDescriptors(); 76 } else { 77 result = new ArrayList <PersistenceUnitDescriptor>(); 79 for (PersistenceUnitsDescriptor pus : pu.getParent().getParent().getPersistenceUnitsDescriptors()) { 80 for(PersistenceUnitDescriptor nextPU : pus.getPersistenceUnitDescriptors()) { 81 result.add(nextPU); 82 } 83 } 84 } 85 return result; 86 } 87 88 } 89 | Popular Tags |