1 23 package com.sun.enterprise.tools.verifier.ejb; 24 25 import java.io.File ; 26 import java.io.FileInputStream ; 27 import java.util.Iterator ; 28 import java.util.Set ; 29 30 import com.sun.ejb.codegen.GeneratorException; 31 import com.sun.enterprise.deployment.*; 32 import com.sun.enterprise.deployment.io.EjbDeploymentDescriptorFile; 33 import com.sun.enterprise.deployment.util.EjbBundleValidator; 34 import com.sun.enterprise.deployment.util.ModuleDescriptor; 35 import com.sun.enterprise.tools.verifier.*; 36 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 37 import com.sun.enterprise.tools.verifier.tests.dd.ParseDD; 38 import com.sun.enterprise.tools.verifier.wsclient.WebServiceClientCheckMgrImpl; 39 import com.sun.enterprise.util.io.FileUtils; 40 import com.sun.jdo.spi.persistence.support.ejb.ejbc.JDOCodeGenerator; 41 42 45 public class EjbCheckMgrImpl extends CheckMgr implements JarCheck { 46 47 50 private static final String testsListFileName = "TestNamesEjb.xml"; private static final String sunONETestsListFileName = getSunPrefix() 52 .concat(testsListFileName); 53 private JDOCodeGenerator jdc = new JDOCodeGenerator(); 55 56 public EjbCheckMgrImpl(FrameworkContext frameworkContext) { 57 this.frameworkContext = frameworkContext; 58 } 59 60 65 public void check(Descriptor descriptor) throws Exception { 66 checkPersistenceUnits(EjbBundleDescriptor.class.cast(descriptor)); 68 checkWebServices(descriptor); 70 checkWebServicesClient(descriptor); 72 73 if (frameworkContext.isPartition() && 74 !frameworkContext.isEjb()) 75 return; 76 77 EjbBundleDescriptor bundleDescriptor = (EjbBundleDescriptor) descriptor; 78 setDescClassLoader(bundleDescriptor); 79 try { 82 EjbBundleValidator validator = new EjbBundleValidator(); 83 validator.accept(bundleDescriptor); 84 } catch (Exception e) { 85 } 87 if (bundleDescriptor.containsCMPEntity()) { 89 try { 90 jdc.init(bundleDescriptor, context.getClassLoader(), 93 getAbstractArchiveUri(bundleDescriptor), 94 frameworkContext.isPortabilityMode()); 95 } catch (Throwable ex) { 96 context.setJDOException(ex); 97 } 98 } 99 context.setJDOCodeGenerator(jdc); 101 102 if (bundleDescriptor.getSpecVersion().compareTo("2.1") < 0) { EjbDeploymentDescriptorFile ddf = new EjbDeploymentDescriptorFile(); 105 File file = new File (getAbstractArchiveUri(bundleDescriptor), 106 ddf.getDeploymentDescriptorPath()); 107 FileInputStream is = new FileInputStream (file); 108 try { 109 if (is != null) { 110 Result result = new ParseDD().validateEJBDescriptor(is); 111 result.setComponentName(new File (bundleDescriptor.getModuleDescriptor(). 112 getArchiveUri()).getName()); 113 setModuleName(result); 114 frameworkContext.getResultManager().add(result); 115 } 116 } finally { 117 try { 118 if(is != null) { 119 is.close(); 120 } 121 } catch (Exception e) {} 122 } 123 } 124 125 for (Iterator itr = bundleDescriptor.getEjbs().iterator(); 126 itr.hasNext();) { 127 EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next(); 128 super.check(ejbDescriptor); 129 } 130 131 if (bundleDescriptor.containsCMPEntity() && 132 context.getJDOException() == null) { 133 try { 134 jdc.cleanup(); 135 } catch (GeneratorException ge) { 136 } context.setJDOCodeGenerator(null); 138 } 139 } 140 141 147 protected String getTestsListFileName() { 148 return testsListFileName; 149 } 150 151 154 protected String getSunONETestsListFileName() { 155 return sunONETestsListFileName; 156 } 157 158 protected void checkWebServicesClient(Descriptor descriptor) 159 throws Exception { 160 if (frameworkContext.isPartition() && 161 !frameworkContext.isWebServicesClient()) 162 return; 163 EjbBundleDescriptor desc = (EjbBundleDescriptor) descriptor; 164 WebServiceClientCheckMgrImpl webServiceClientCheckMgr = new WebServiceClientCheckMgrImpl( 165 frameworkContext); 166 if (desc.hasWebServiceClients()) { 167 Set ejbdescs = desc.getEjbs(); 168 Iterator ejbIt = ejbdescs.iterator(); 169 170 while (ejbIt.hasNext()) { 171 EjbDescriptor ejbDesc = (EjbDescriptor) ejbIt.next(); 172 context.setEjbDescriptorForServiceRef(ejbDesc); 173 Set serviceRefDescriptors = ejbDesc.getServiceReferenceDescriptors(); 174 Iterator it = serviceRefDescriptors.iterator(); 175 while (it.hasNext()) { 176 webServiceClientCheckMgr.setVerifierContext(context); 177 webServiceClientCheckMgr.check( 178 (ServiceReferenceDescriptor) it.next()); 179 } 180 } 181 context.setEjbDescriptorForServiceRef(null); 182 } 183 } 184 185 protected String getSchemaVersion(Descriptor descriptor) { 186 return getBundleDescriptor(descriptor).getSpecVersion(); 187 } 188 189 protected void setModuleName(Result r) { 190 r.setModuleName(Result.EJB); 191 } 192 193 protected EjbBundleDescriptor getBundleDescriptor(Descriptor descriptor) { 194 return ((EjbDescriptor) descriptor).getEjbBundleDescriptor(); 195 } 196 197 201 protected boolean isApplicable(TestInformation test, Descriptor descriptor) { 202 String testName = test.getClassName(); 203 if(descriptor instanceof EjbSessionDescriptor && 204 (testName.indexOf("tests.ejb.entity")>=0 || testName.indexOf("tests.ejb.messagebean")>=0)) return false; 207 if(descriptor instanceof EjbEntityDescriptor && 208 (testName.indexOf("tests.ejb.session")>=0 || testName.indexOf("tests.ejb.messagebean")>=0)) return false; 211 if(descriptor instanceof EjbMessageBeanDescriptor && 212 (testName.indexOf("tests.ejb.session")>=0 || testName.indexOf("tests.ejb.entity")>=0)) return false; 215 return true; 216 } 217 218 private String getAbstractArchiveUri(EjbBundleDescriptor desc) { 219 String archBase = context.getAbstractArchive().getArchiveUri(); 220 ModuleDescriptor mdesc = desc.getModuleDescriptor(); 221 if(mdesc.isStandalone()) { 222 return archBase; 223 } else { 224 return archBase + File.separator + 225 FileUtils.makeFriendlyFileName(mdesc.getArchiveUri()); 226 } 227 } 228 229 private void setDescClassLoader(EjbBundleDescriptor bundleDescriptor) { 230 Iterator bundleItr = bundleDescriptor.getEjbs().iterator(); 231 while (bundleItr.hasNext()) { 232 EjbDescriptor descriptor = (EjbDescriptor) bundleItr.next(); 233 if (descriptor instanceof IASEjbCMPEntityDescriptor) { 234 ((IASEjbCMPEntityDescriptor) (descriptor)).setClassLoader( 235 context.getClassLoader()); 236 } 237 } 238 } 239 240 protected ComponentNameConstructor getComponentNameConstructor( 241 Descriptor descriptor) { 242 return new ComponentNameConstructor((EjbDescriptor)descriptor); 243 } 244 245 } 246 | Popular Tags |