1 23 24 package com.sun.enterprise.deployment.archivist; 25 26 import java.io.File ; 27 import java.io.IOException ; 28 import java.util.logging.Level ; 29 import java.util.*; 30 import javax.enterprise.deploy.shared.ModuleType ; 31 import org.xml.sax.SAXParseException ; 32 33 import com.sun.enterprise.deployment.Application; 34 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 35 import com.sun.enterprise.deployment.deploy.shared.Archive; 36 import com.sun.enterprise.deployment.Descriptor; 37 import com.sun.enterprise.deployment.io.DeploymentDescriptorFile; 38 import com.sun.enterprise.deployment.io.DescriptorConstants; 39 import com.sun.enterprise.deployment.io.runtime.WebRuntimeDDFile; 40 import com.sun.enterprise.deployment.io.WebDeploymentDescriptorFile; 41 import com.sun.enterprise.deployment.RootDeploymentDescriptor; 42 import com.sun.enterprise.deployment.util.ApplicationValidator; 43 import com.sun.enterprise.deployment.util.DOLUtils; 44 import com.sun.enterprise.deployment.util.DOLLoadingContextFactory; 45 import com.sun.enterprise.deployment.util.ModuleContentValidator; 46 import com.sun.enterprise.deployment.util.WebBundleVisitor; 47 import com.sun.enterprise.deployment.WebBundleDescriptor; 48 49 50 57 public class WebArchivist extends Archivist { 58 59 private WebBundleDescriptor descriptor; 60 61 64 DeploymentDescriptorFile standardDD = new WebDeploymentDescriptorFile(); 65 66 67 public WebArchivist() { 68 } 69 70 75 public ModuleType getModuleType() { 76 return ModuleType.WAR; 77 } 78 79 84 public void setDescriptor(Descriptor descriptor) { 85 if (descriptor instanceof WebBundleDescriptor) { 86 this.descriptor = (WebBundleDescriptor) descriptor; 87 } else { 88 if (descriptor instanceof Application) { 89 java.util.Set webBundles = ((Application) descriptor).getWebBundleDescriptors(); 92 if (webBundles.size()>0) { 93 this.descriptor = (WebBundleDescriptor) webBundles.iterator().next(); 94 if (this.descriptor.getModuleDescriptor().isStandalone()) 95 return; 96 else 97 this.descriptor=null; 98 } 99 } 100 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.descriptorFailure", new Object [] {this}); 101 throw new RuntimeException ("Error setting descriptor " + descriptor + " in " + this); 102 } 103 } 104 105 110 public String getWebServicesDeploymentDescriptorPath() { 111 return DescriptorConstants.WEB_WEBSERVICES_JAR_ENTRY; 112 } 113 114 118 public DeploymentDescriptorFile getStandardDDFile() { 119 return standardDD; 120 } 121 122 126 public DeploymentDescriptorFile getConfigurationDDFile() { 127 return new WebRuntimeDDFile(); 128 } 129 130 133 public Descriptor getDescriptor() { 134 return descriptor; 135 } 136 137 140 public Descriptor getDefaultBundleDescriptor() { 141 WebBundleDescriptor webBundleDesc = 142 DOLLoadingContextFactory.getDefaultWebBundleDescriptor(); 143 return webBundleDesc; 144 } 145 146 152 protected void postOpen(RootDeploymentDescriptor descriptor, AbstractArchive archive) 153 throws IOException 154 { 155 super.postOpen(descriptor, archive); 156 WebBundleDescriptor webBundle = (WebBundleDescriptor) descriptor; 157 ModuleContentValidator mdv = new ModuleContentValidator(archive); 158 webBundle.visit(mdv); 159 } 160 161 166 public void validate(ClassLoader aClassLoader) { 167 ClassLoader cl = aClassLoader; 168 if (cl==null) { 169 cl = classLoader; 170 } 171 if (cl==null) { 172 return; 173 } 174 descriptor.setClassLoader(cl); 175 descriptor.visit((WebBundleVisitor) new ApplicationValidator()); 176 } 177 178 183 protected boolean postHandles(AbstractArchive abstractArchive) 184 throws IOException { 185 return false; 186 } 187 188 protected String getArchiveExtension() { 189 return WEB_EXTENSION; 190 } 191 192 195 public Vector getLibraries(AbstractArchive archive) { 196 197 Enumeration<String > entries = archive.entries(); 198 if (entries==null) 199 return null; 200 201 Vector libs = new Vector(); 202 while (entries.hasMoreElements()) { 203 204 String entryName = entries.nextElement(); 205 if (!entryName.startsWith("WEB-INF/lib")) { 206 continue; } 208 if (entryName.endsWith(".jar")) { 209 libs.add(entryName); 210 } 211 } 212 return libs; 213 } 214 215 @Override public void readPersistenceDeploymentDescriptors( 216 AbstractArchive archive, Descriptor descriptor) throws IOException , SAXParseException { 217 if(logger.isLoggable(Level.FINE)) { 218 logger.logp(Level.FINE, "WebArchivist", 219 "readPersistenceDeploymentDescriptors", "archive = {0}", 220 archive.getURI()); 221 } 222 Map<String , Archive> subArchives = new HashMap<String , Archive>(); 223 Enumeration entries = archive.entries(); 224 final String CLASSES_DIR = "WEB-INF/classes/"; 225 final String LIB_DIR = "WEB-INF/lib/"; 226 final String JAR_EXT = ".jar"; 227 try { 228 final String pathOfPersistenceXMLInsideClassesDir = 229 CLASSES_DIR+DescriptorConstants.PERSISTENCE_DD_ENTRY; 230 while(entries.hasMoreElements()){ 231 final String nextEntry = String .class.cast(entries.nextElement()); 232 if(pathOfPersistenceXMLInsideClassesDir.equals(nextEntry)) { 233 subArchives.put(CLASSES_DIR, archive.getSubArchive(CLASSES_DIR)); 234 } else if (nextEntry.startsWith(LIB_DIR) && nextEntry.endsWith(JAR_EXT)) { 235 String jarFile = nextEntry.substring(LIB_DIR.length(), nextEntry.length()-JAR_EXT.length()); 236 if(jarFile.indexOf('/') == -1) { subArchives.put(nextEntry, archive.getSubArchive(nextEntry)); 239 } else { 240 if(logger.isLoggable(Level.FINE)) { 241 logger.logp(Level.FINE, "WebArchivist", 242 "readPersistenceDeploymentDescriptors", 243 "skipping {0} as it exists inside a directory in {1}.", 244 new Object []{nextEntry, LIB_DIR}); 245 } 246 continue; 247 } 248 } 249 } 250 for(Map.Entry<String , Archive> pathToArchiveEntry : subArchives.entrySet()) { 251 readPersistenceDeploymentDescriptor(pathToArchiveEntry.getValue(), pathToArchiveEntry.getKey(), descriptor); 252 } 253 } finally { 254 for(Archive subArchive : subArchives.values()) { 255 subArchive.close(); 256 } 257 } 258 } 259 260 } 261 | Popular Tags |