1 23 24 package com.sun.enterprise.deployment.archivist; 25 26 import java.io.File ; 27 import java.io.FileNotFoundException ; 28 import java.io.IOException ; 29 import java.util.Set ; 30 import java.util.logging.Level ; 31 import javax.enterprise.deploy.shared.ModuleType ; 32 import org.xml.sax.SAXParseException ; 33 34 import com.sun.enterprise.deployment.Application; 35 import com.sun.enterprise.deployment.Descriptor; 36 import com.sun.enterprise.deployment.EjbBundleDescriptor; 37 import com.sun.enterprise.deployment.RootDeploymentDescriptor; 38 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 39 import com.sun.enterprise.deployment.io.DeploymentDescriptorFile; 40 import com.sun.enterprise.deployment.io.DescriptorConstants; 41 import com.sun.enterprise.deployment.io.EjbDeploymentDescriptorFile; 42 import com.sun.enterprise.deployment.io.runtime.EjbRuntimeDDFile; 43 import com.sun.enterprise.deployment.util.DOLUtils; 44 import com.sun.enterprise.deployment.util.EjbBundleValidator; 45 import com.sun.enterprise.deployment.util.EjbBundleVisitor; 46 import com.sun.enterprise.deployment.util.EjbComponentAnnotationDetector; 47 import com.sun.enterprise.deployment.util.ModuleContentValidator; 48 import com.sun.enterprise.util.FileUtil; 49 import com.sun.enterprise.util.LocalStringManagerImpl; 50 51 57 public class EjbArchivist extends Archivist { 58 59 EjbBundleDescriptor descriptor = null; 60 61 64 DeploymentDescriptorFile standardDD = new EjbDeploymentDescriptorFile(); 65 66 private static LocalStringManagerImpl localStrings = 68 new LocalStringManagerImpl(EjbArchivist.class); 69 70 71 public EjbArchivist() { 72 } 73 74 79 public ModuleType getModuleType() { 80 return ModuleType.EJB; 81 } 82 83 86 public void setDescriptor(Descriptor descriptor) { 87 if (descriptor instanceof EjbBundleDescriptor) { 88 this.descriptor = (EjbBundleDescriptor) descriptor; 89 } else { 90 if (descriptor instanceof Application) { 91 Set ejbBundles = ((Application) descriptor).getEjbBundleDescriptors(); 94 if (ejbBundles.size()>0) { 95 this.descriptor = (EjbBundleDescriptor) ejbBundles.iterator().next(); 96 if (this.descriptor.getModuleDescriptor().isStandalone()) 97 return; 98 else 99 this.descriptor=null; 100 } 101 } 102 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.descriptorFailure", new Object [] {this}); 103 throw new RuntimeException ("Error setting descriptor " + descriptor + " in " + this); 104 } 105 } 106 107 111 public DeploymentDescriptorFile getStandardDDFile() { 112 return standardDD; 113 } 114 115 119 public DeploymentDescriptorFile getConfigurationDDFile() { 120 return new EjbRuntimeDDFile(); 121 } 122 123 128 public String getWebServicesDeploymentDescriptorPath() { 129 return DescriptorConstants.EJB_WEBSERVICES_JAR_ENTRY; 130 } 131 132 135 public Descriptor getDescriptor() { 136 return descriptor; 137 } 138 139 142 public Descriptor getDefaultBundleDescriptor() { 143 EjbBundleDescriptor ejbBundleDesc = 144 new EjbBundleDescriptor(); 145 return ejbBundleDesc; 146 } 147 148 154 protected void postOpen(RootDeploymentDescriptor descriptor, AbstractArchive archive) 155 throws IOException 156 { 157 super.postOpen(descriptor, archive); 158 EjbBundleDescriptor ejbBundle = (EjbBundleDescriptor) descriptor; 159 ModuleContentValidator mdv = new ModuleContentValidator(archive); 160 ejbBundle.visit((EjbBundleVisitor)mdv); 161 } 162 163 168 public void validate(ClassLoader aClassLoader) { 169 ClassLoader cl = aClassLoader; 170 if (cl==null) { 171 cl = classLoader; 172 } 173 if (cl==null) { 174 return; 175 } 176 descriptor.setClassLoader(cl); 177 descriptor.visit((EjbBundleVisitor) new EjbBundleValidator()); 178 } 179 180 185 protected void prepareForInclusion(AbstractArchive out) throws IOException { 186 187 String ejbClientJarUri = descriptor.getEjbClientJarUri(); 189 190 if( !ejbClientJarUri.equals("") ) { 193 String ejbClientJarPath = 194 ejbClientJarUri.replace(FileUtil.JAR_SEPARATOR_CHAR, File.separatorChar); 195 196 File ejbJarFile = new File (path); 197 File ejbClientJar = new File (ejbJarFile.getParentFile(), ejbClientJarPath); 198 if( ejbClientJar.exists() ) { 199 addFileToArchive(out, ejbClientJar.getAbsolutePath(), ejbClientJarUri); 203 String classPath = getClassPath(); 204 if (classPath==null) { 205 classPath=ejbClientJarUri; 206 } else { 207 classPath+=" " + ejbClientJarUri; 208 } 209 setClassPath(classPath); 210 } else { 211 throw new FileNotFoundException (localStrings.getLocalString("enterprise.deployment.noclientjarentry", "Warning: {0} not found as a client jar entry.", new Object [] {ejbClientJar.toString()})); 212 } 213 } 214 } 215 216 protected String getArchiveExtension() { 217 return EJB_EXTENSION; 218 } 219 220 protected boolean postHandles(AbstractArchive abstractArchive) 221 throws IOException { 222 EjbComponentAnnotationDetector detector = 223 new EjbComponentAnnotationDetector(); 224 return detector.hasAnnotationInArchive(abstractArchive); 225 } 226 227 @Override public void readPersistenceDeploymentDescriptors( 228 AbstractArchive archive, Descriptor descriptor) 229 throws IOException , SAXParseException { 230 if(logger.isLoggable(Level.FINE)) { 231 logger.logp(Level.FINE, "EjbArchivist", 232 "readPersistenceDeploymentDescriptors", "archive = {0}", 233 archive.getURI()); 234 } 235 readPersistenceDeploymentDescriptor(archive, "", descriptor); 240 } 241 } 242 | Popular Tags |