1 2 24 25 package com.sun.enterprise.deployment.archivist; 26 27 import java.io.InputStream ; 28 import java.io.IOException ; 29 import java.util.jar.Attributes ; 30 import java.util.jar.Attributes.Name; 31 import java.util.jar.Manifest ; 32 import java.util.logging.Level ; 33 import java.util.Vector ; 34 import java.util.Iterator ; 35 import javax.enterprise.deploy.shared.ModuleType ; 36 import org.xml.sax.SAXParseException ; 37 38 import com.sun.enterprise.deployment.ApplicationClientDescriptor; 39 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 40 import com.sun.enterprise.deployment.Descriptor; 41 import com.sun.enterprise.deployment.Application; 42 import com.sun.enterprise.deployment.io.AppClientDeploymentDescriptorFile; 43 import com.sun.enterprise.deployment.io.DeploymentDescriptorFile; 44 import com.sun.enterprise.deployment.io.runtime.AppClientRuntimeDDFile; 45 import com.sun.enterprise.deployment.node.appclient.AppClientNode; 46 import com.sun.enterprise.deployment.RootDeploymentDescriptor; 47 import com.sun.enterprise.deployment.util.AppClientVisitor; 48 import com.sun.enterprise.deployment.util.ApplicationValidator; 49 import com.sun.enterprise.deployment.util.DOLUtils; 50 import com.sun.enterprise.deployment.util.ModuleContentValidator; 51 import com.sun.enterprise.deployment.util.ModuleDescriptor; 52 53 59 public class AppClientArchivist extends Archivist { 60 61 ApplicationClientDescriptor descriptor = null; 62 DeploymentDescriptorFile standardDD = new AppClientDeploymentDescriptorFile(); 63 64 65 public AppClientArchivist() { 66 handleRuntimeInfo = true; 67 } 68 69 74 public ModuleType getModuleType() { 75 return ModuleType.CAR; 76 } 77 78 81 public void setDescriptor(Descriptor descriptor) { 82 if (descriptor instanceof ApplicationClientDescriptor) { 83 this.descriptor = (ApplicationClientDescriptor) descriptor; 84 } else { 85 if (descriptor instanceof Application) { 86 java.util.Set appClientBundles = ((Application) descriptor).getApplicationClientDescriptors(); 89 if (appClientBundles.size()>0) { 90 this.descriptor = (ApplicationClientDescriptor) appClientBundles.iterator().next(); 91 if (this.descriptor.getModuleDescriptor().isStandalone()) 92 return; 93 else 94 this.descriptor=null; 95 } 96 } 97 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.descriptorFailure", new Object [] {this}); 98 throw new RuntimeException ("Error setting descriptor " + descriptor + " in " + this); 99 } 100 } 101 102 106 public DeploymentDescriptorFile getStandardDDFile() { 107 return standardDD; 108 } 109 110 114 public DeploymentDescriptorFile getConfigurationDDFile() { 115 return new AppClientRuntimeDDFile(); 116 } 117 118 121 public Descriptor getDescriptor() { 122 return descriptor; 123 } 124 125 128 public Descriptor getDefaultBundleDescriptor() { 129 ApplicationClientDescriptor appClientDesc = 130 new ApplicationClientDescriptor(); 131 return appClientDesc; 132 } 133 134 139 public void validate(ClassLoader aClassLoader) { 140 ClassLoader cl = aClassLoader; 141 if (cl==null) { 142 cl = classLoader; 143 } 144 if (cl==null) { 145 return; 146 } 147 descriptor.setClassLoader(cl); 148 descriptor.visit((AppClientVisitor) new ApplicationValidator()); 149 } 150 151 156 protected void postStandardDDsRead(RootDeploymentDescriptor descriptor, 157 AbstractArchive archive) throws IOException { 158 super.postStandardDDsRead(descriptor, archive); 159 ApplicationClientDescriptor appClient = (ApplicationClientDescriptor)descriptor; 161 Manifest m = archive.getManifest(); 162 appClient.setMainClassName(getMainClassName(m)); 163 } 164 165 171 protected void postOpen(RootDeploymentDescriptor descriptor, AbstractArchive archive) 172 throws IOException 173 { 174 175 super.postOpen(descriptor, archive); 176 177 ApplicationClientDescriptor appClient = (ApplicationClientDescriptor) descriptor; 178 ModuleContentValidator mdv = new ModuleContentValidator(archive); 179 appClient.visit(mdv); 180 } 181 182 189 protected ModuleDescriptor addToArchive(ApplicationArchivist appArch, String externalDD) 190 throws IOException , SAXParseException { 191 192 ModuleDescriptor module = super.addToArchive(appArch, externalDD); 193 if (module!=null) { 194 ApplicationClientDescriptor acd = (ApplicationClientDescriptor) module.getDescriptor(); 195 AbstractArchive jarFile = abstractArchiveFactory.openArchive(getArchiveUri()); 196 Manifest jarManifest = jarFile.getManifest(); 197 if (jarManifest!=null) { 198 String mainClassName = getMainClassName(jarManifest); 199 if (mainClassName!=null) { 200 acd.setMainClassName(mainClassName); 201 } 202 } 203 jarFile.close(); 204 } 205 return module; 206 } 207 208 215 protected void writeContents(AbstractArchive in, AbstractArchive out, Vector entriesToSkip) 216 throws IOException { 217 218 if (manifest==null) { 220 manifest = new Manifest (); 221 } 222 manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION_VALUE); 223 manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, 224 ((ApplicationClientDescriptor) getDescriptor()).getMainClassName()); 225 226 super.writeContents(in, out, entriesToSkip); 227 } 228 229 232 public String getMainClassName(Manifest m) { 233 if (m!=null) { 234 return m.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS); 235 } 236 return null; 237 } 238 239 protected boolean postHandles(AbstractArchive abstractArchive) 240 throws IOException { 241 if (getMainClassName(abstractArchive.getManifest()) != null) { 243 return true; 244 } 245 246 return false; 247 } 248 249 protected String getArchiveExtension() { 250 return APPCLIENT_EXTENSION; 251 } 252 253 @Override public void readPersistenceDeploymentDescriptors( 254 AbstractArchive archive, 255 Descriptor descriptor) 256 throws IOException , SAXParseException { 257 if (logger.isLoggable(Level.FINE)) { 258 logger.logp(Level.FINE, "AppClientArchivist", 259 "readPersistenceDeploymentDescriptors", "archive = {0}", 260 archive.getURI()); 261 } 262 readPersistenceDeploymentDescriptor(archive, "", descriptor); 267 } 268 } 269 | Popular Tags |