1 23 24 25 26 package com.sun.enterprise.tools.verifier.tests.ejb.ias.cmpmapping; 27 28 29 import java.util.*; 30 import com.sun.enterprise.deployment.EjbDescriptor; 31 import com.sun.enterprise.deployment.EjbSessionDescriptor; 32 import com.sun.enterprise.tools.verifier.*; 33 import com.sun.enterprise.tools.verifier.tests.*; 34 35 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 36 37 import com.sun.enterprise.tools.common.dd.ejb.SunEjbJar; 38 import com.sun.enterprise.tools.common.dd.ejb.Ejb; 39 import com.sun.enterprise.tools.common.dd.ResourceRef; 40 import com.sun.enterprise.tools.common.dd.DefaultResourcePrincipal; 41 import com.sun.enterprise.deployment.ResourceReferenceDescriptor; 42 import com.sun.enterprise.tools.verifier.tests.ejb.*; 43 import com.sun.enterprise.tools.common.dd.cmpmapping.*; 44 45 public class ASEntityMappingTest extends EjbTest implements EjbCheck { 46 47 public Result check(EjbDescriptor descriptor) 48 { 49 Result result = getInitializedResult(); 50 ComponentNameConstructor compName = new ComponentNameConstructor(descriptor); 51 boolean oneFailed = false; 52 boolean notApp = false; 53 54 59 SunCmpMappings iasCmpMappings = descriptor.getEjbBundleDescriptor().getIasCmpMappings(); 60 String forPmConfig = com.sun.enterprise.deployment.EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY; 61 63 SunCmpMapping[] allIasCmpMapping=null; 64 SunCmpMapping iasCmpMapping=null; 65 66 EntityMapping[] entityMapping=null; 68 String ejbName=null; 69 String tableName=null; 70 71 72 if(iasCmpMappings!=null) 74 { 75 82 allIasCmpMapping=iasCmpMappings.getSunCmpMapping(); 84 85 for(int rep=0;rep<allIasCmpMapping.length;rep++){ 86 87 iasCmpMapping=allIasCmpMapping[rep]; 88 89 entityMapping=iasCmpMapping.getEntityMapping(); 91 92 if(entityMapping == null || entityMapping.length==0){ oneFailed = true; 94 95 result.failed(smh.getLocalString(getClass().getName()+".failed", 96 "FAILED [AS-CMP-MAPPING] : entity-mapping is NOT a valid entry, in the mapping file [ {0}], "+ 97 "of the ejb archive [ {1} ]. "+ 98 "Either null or empty.", 99 new Object []{forPmConfig,descriptor.getName()})); 100 continue; 101 102 } 103 104 for(int rep1=0;rep1<entityMapping.length;rep1++){ 105 106 ejbName=entityMapping[rep1].getEjbName(); 107 tableName=entityMapping[rep1].getTableName(); 108 109 if(validateEjbName(ejbName,descriptor)){ 110 111 result.passed(smh.getLocalString(getClass().getName()+".passed", 112 "PASSED [AS-CMP-MAPPING] : entity-mapping->ejb-name [{0} ] is a valid entry, in the mapping file [ {1}], "+ 113 "of the ejb archive [ {2} ]. ", 114 new Object []{ejbName,forPmConfig,descriptor.getName()})); 115 116 }else{ 117 oneFailed = true; 118 119 result.failed(smh.getLocalString(getClass().getName()+".failed1", 120 "FAILED [AS-CMP-MAPPING] : entity-mapping->ejb-name [{0} ] is NOT a valid entry, in the mapping file [ {1}], "+ 121 "of the ejb archive [ {2} ]. "+ 122 "Either null/empty or the ejb-name is not present in corresponding ejb-jar.xml.", 123 new Object []{ejbName,forPmConfig,descriptor.getName()})); 124 125 } 126 127 if(validateTableName(tableName)){ 128 129 result.passed(smh.getLocalString(getClass().getName()+".passed1", 130 "PASSED [AS-CMP-MAPPING] : entity-mapping->table-name [{0} ] is a valid entry, in the mapping file [ {1}], "+ 131 "of the ejb archive [ {2} ]. ", 132 new Object []{tableName,forPmConfig,descriptor.getName()})); 133 134 }else{ 135 oneFailed = true; 136 137 result.failed(smh.getLocalString(getClass().getName()+".failed2", 138 "FAILED [AS-CMP-MAPPING] : entity-mapping->table-name [{0} ] is NOT a valid entry, in the mapping file [ {1}], "+ 139 "of the ejb archive [ {2} ]. "+ 140 "Either null or empty.", 141 new Object []{tableName,forPmConfig,descriptor.getName()})); 142 143 } 144 145 } 146 147 } 148 149 150 152 } 153 else 154 { 155 notApp = true; 156 result.notApplicable(smh.getLocalString 157 (getClass().getName() + ".notApplicable", 158 "NOT APPLICABLE [AS-CMP-MAPPING] : There is no ias-cmp-mappings file present, within the ejb archive [ {0} ].", 159 new Object [] {descriptor.getName()})); 160 161 } 162 163 if (oneFailed) { 164 result.setStatus(Result.FAILED); 165 } else if(notApp) { 166 result.setStatus(Result.NOT_APPLICABLE); 167 }else { 168 result.setStatus(Result.PASSED); 169 } 170 171 172 return result; 173 } 174 175 boolean validateEjbName(String name,EjbDescriptor descriptor){ 176 boolean valid=false; 177 if(name !=null && !name.trim().equals("")){ 178 for (Iterator itr =descriptor.getEjbBundleDescriptor().getEjbs().iterator(); 180 itr.hasNext();) { 181 EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next(); 182 if (ejbDescriptor.getName().equals(name)) { 183 valid =true; 184 break; 185 } 186 } 187 } 188 return valid; 189 } 190 191 boolean validateTableName(String name){ 192 boolean valid=false; 193 if(name !=null && !name.trim().equals("")){ 194 valid =true; 195 } 196 return valid; 197 } 198 } 199 200 201 202 203 | Popular Tags |