1 23 24 29 30 31 package com.sun.enterprise.tools.verifier.tests.ejb.ias.cmpmapping; 32 33 34 import java.util.*; 35 import com.sun.enterprise.deployment.EjbDescriptor; 36 import com.sun.enterprise.deployment.EjbSessionDescriptor; 37 import com.sun.enterprise.tools.verifier.*; 38 import com.sun.enterprise.tools.verifier.tests.*; 39 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 40 import com.sun.enterprise.tools.common.dd.ejb.SunEjbJar; 41 import com.sun.enterprise.tools.common.dd.ejb.Ejb; 42 import com.sun.enterprise.tools.common.dd.ResourceRef; 43 import com.sun.enterprise.tools.common.dd.DefaultResourcePrincipal; 44 import com.sun.enterprise.deployment.ResourceReferenceDescriptor; 45 import com.sun.enterprise.tools.verifier.tests.ejb.*; 46 import com.sun.enterprise.tools.common.dd.cmpmapping.*; 47 import com.sun.jdo.spi.persistence.support.ejb.ejbc.*; 48 import com.sun.enterprise.deployment.DescriptorConstants; 49 import com.sun.enterprise.deployment.IASEjbBundleDescriptor; 50 import com.sun.enterprise.deployment.IASEjbCMPEntityDescriptor; 51 import com.sun.ejb.codegen.GeneratorException; 52 import com.sun.enterprise.util.JarClassLoader; 53 import java.io.*; 54 import java.util.jar.*; 55 import java.util.zip.*; 56 import com.sun.enterprise.deployment.*; 57 import com.sun.enterprise.deployment.*; 58 59 public class ASSunCmpMappingTest extends EjbTest implements EjbCheck { 60 61 public Result check(EjbDescriptor descriptor) 62 { 63 Result result = getInitializedResult(); 64 ComponentNameConstructor compName = new ComponentNameConstructor(descriptor); 65 boolean oneFailed = false; 66 boolean notApp = false; 67 boolean initFailed=false; 68 69 if(descriptor.getEjbBundleDescriptor().getTestsDone().contains(getClass().getName())) 70 { 71 result.setStatus(Result.NOT_RUN); 72 result.addGoodDetails(smh.getLocalString("iasEjbJar.allReadyRun", 73 "NOT RUN [AS-EJB ias-ejb-jar] cmp-mapping is a JAR Level Test. This test has already been run once")); 74 return result; 75 } 76 descriptor.getEjbBundleDescriptor().setTestsDone(getClass().getName()); 77 78 IASEjbBundleDescriptor desc=(IASEjbBundleDescriptor)descriptor.getEjbBundleDescriptor(); 79 80 if(!mappingFileExist((EjbDescriptor)descriptor)) { 82 if(containsCMP(desc)){ result.warning(smh.getLocalString(getClass().getName()+".warning", 84 "WARNING [JDO-GEN-CMP-Validation] : CMP mapping file [ {0} ] not present, in the ejb archive [ {1} ].", 85 new Object [] {EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY, descriptor.getName()})); 86 return result; 87 }else{ 88 notApp = true; 89 result.notApplicable(smh.getLocalString 90 (getClass().getName() + ".notApplicable", 91 "NOT APPLICABLE [JDO-GEN-CMP-Validation] : There is no cmp present, within the ejb archive [ {0} ].", 92 new Object [] {descriptor.getName()})); 93 return result; 94 95 } 96 97 98 } 99 100 101 ClassLoader loader=getVerifierContext().getClassLoader(); 102 JDOCodeGenerator jdogen = new JDOCodeGenerator(); 103 104 Iterator ejbs=desc.getEjbs().iterator(); 105 if(ejbs.hasNext()) 107 { 108 try{ 109 jdogen.init(desc, loader); 110 111 }catch(Exception re){ 112 oneFailed = true; 113 initFailed=true; 114 115 result.failed(smh.getLocalString(getClass().getName()+".failed2", 116 "FAILED [JDO-GEN-CMP-Validation] : Unexpected exception occured while initializing JDOCodeGenerator, for the mapping file [ {0} ], "+ 117 "of the ejb archive [ {1} ] . "+ 118 "Check stacktrace for details : \n [ {2} ]" , 119 new Object []{EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY,descriptor.getName(),re.getMessage()})); 120 121 122 } 123 124 while ( !initFailed && ejbs.hasNext() ) { 125 EjbDescriptor ejbdesc = (EjbDescriptor) ejbs.next(); 126 127 if ( ejbdesc instanceof IASEjbCMPEntityDescriptor ) { 128 IASEjbCMPEntityDescriptor entd = (IASEjbCMPEntityDescriptor)ejbdesc; 129 try { 130 jdogen.validate(entd); 131 result.passed(smh.getLocalString(getClass().getName()+".passed", 132 "PASSED [JDO-GEN-CMP-Validation] : The descriptor entries, in the mapping file [ {0} ], "+ 133 "for CMP [ {1} ]"+ 134 "of the ejb archive [ {2} ] are valid. ", 135 new Object []{EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY,ejbdesc.getEjbClassName(),descriptor.getName()})); 136 } catch (GeneratorException e) { 137 oneFailed = true; 138 139 result.failed(smh.getLocalString(getClass().getName()+".failed", 140 "FAILED [JDO-GEN-CMP-Validation] : Atleast one entry , in the mapping file [ {0} ], "+ 141 "for CMP [ {1} ]"+ 142 "of the ejb archive [ {2} ] is not valid. "+ 143 "Check stacktrace for details : \n [ {3} ]" , 144 new Object []{EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY,ejbdesc.getEjbClassName(),descriptor.getName(),e.getMessage()})); 145 146 }catch (Exception e) { 147 oneFailed = true; 148 149 result.failed(smh.getLocalString(getClass().getName()+".failed1", 150 "FAILED [JDO-GEN-CMP-Validation] : Unexpected exception occured while validating , the mapping file [ {0} ], "+ 151 "for CMP [ {1} ]"+ 152 "of the ejb archive [ {2} ] . "+ 153 "Check stacktrace for details : \n [ {3} ]" , 154 new Object []{EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY,ejbdesc.getEjbClassName(),descriptor.getName(),e.getMessage()})); 155 156 157 } 158 159 } 160 } 162 } 163 else{ 164 165 notApp = true; 166 result.notApplicable(smh.getLocalString 167 (getClass().getName() + ".notApplicable", 168 "NOT APPLICABLE [JDO-GEN-CMP-Validation] : There is no cmp present, within the ejb archive [ {0} ].", 169 new Object [] {descriptor.getName()})); 170 } 171 172 173 jdogen.cleanup(); 174 175 176 if (oneFailed) { 177 result.setStatus(Result.FAILED); 178 } else if(notApp) { 179 result.setStatus(Result.NOT_APPLICABLE); 180 }else { 181 result.setStatus(Result.PASSED); 182 } 183 return result; 184 } 185 186 boolean mappingFileExist(EjbDescriptor descriptor){ try{ 188 if(descriptor.getEjbBundleDescriptor().getIasCmpMappings() != null) 189 return true; 190 else 191 return false; 192 }catch(Exception e){ 193 return false; 194 } 195 218 } 219 220 boolean containsCMP(IASEjbBundleDescriptor desc) { 222 223 if(desc == null || desc.getEjbs() == null ) 224 return false; 225 Iterator ejbs=desc.getEjbs().iterator(); 226 if(ejbs.hasNext()) 227 { 228 while ( ejbs.hasNext() ) { 229 EjbDescriptor ejbdesc = (EjbDescriptor) ejbs.next(); 230 if ( ejbdesc instanceof IASEjbCMPEntityDescriptor ) 232 return true; 233 } 234 } 235 return false; 236 237 } 238 239 240 } 241 242 243 | Popular Tags |