1 23 24 package com.sun.enterprise.instance; 25 26 27 import java.io.IOException ; 28 import java.io.OutputStream ; 29 import java.util.Iterator ; 30 31 import javax.enterprise.deploy.shared.ModuleType ; 32 33 import com.sun.enterprise.deployment.Application; 34 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 35 import com.sun.enterprise.deployment.archivist.Archivist; 36 import com.sun.enterprise.deployment.archivist.ArchivistFactory; 37 import com.sun.enterprise.deployment.BundleDescriptor; 38 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 39 import com.sun.enterprise.deployment.io.DeploymentDescriptorFile; 40 import com.sun.enterprise.deployment.util.ModuleDescriptor; 41 import com.sun.enterprise.deployment.WebBundleDescriptor; 42 import com.sun.enterprise.deployment.WebServicesDescriptor; 43 import com.sun.enterprise.deployment.WebService; 44 45 51 public class DescriptorArchivist { 52 53 54 public DescriptorArchivist() { 55 } 56 57 62 public void write(Application application, AbstractArchive in, 63 AbstractArchive out) throws IOException { 64 if (application.isVirtual()) { 65 ModuleDescriptor aModule = (ModuleDescriptor) application.getModules().next(); 66 Archivist moduleArchivist = ArchivistFactory.getArchivistForType(aModule.getModuleType()); 67 write(aModule.getDescriptor(), moduleArchivist, in, out); 68 } else { 69 71 for (Iterator modules = application.getModules();modules.hasNext();) { 73 ModuleDescriptor aModule = (ModuleDescriptor) modules.next(); 74 Archivist moduleArchivist = ArchivistFactory.getArchivistForType(aModule.getModuleType()); 75 if (aModule.getAlternateDescriptor()!=null) { 76 78 String ddPath = aModule.getAlternateDescriptor(); 80 DeploymentDescriptorFile ddFile = 81 moduleArchivist.getStandardDDFile(); 82 83 BundleDescriptor bundle = 84 (BundleDescriptor)aModule.getDescriptor(); 85 if (!bundle.isFullFlag()) { 86 if (ddFile != null) { 87 OutputStream os = out.putNextEntry(ddPath); 88 ddFile.write(bundle, os); 89 out.closeEntry(); 90 } 91 } else { 92 if (aModule.getModuleType().equals(ModuleType.WAR)) { 93 WebBundleDescriptor webBundle = 94 (WebBundleDescriptor) aModule.getDescriptor(); 95 if (webBundle.hasWebServices()) { 96 if (ddFile != null) { 97 OutputStream os = out.putNextEntry(ddPath); 98 ddFile.write(webBundle, os); 99 out.closeEntry(); 100 } 101 } else { 102 Archivist.copyAnEntry(in, out, ddPath); 103 } 104 } else { 105 Archivist.copyAnEntry(in, out, ddPath); 106 } 107 } 108 109 String runtimeDDPath = "sun-" + ddPath; 110 DeploymentDescriptorFile confDDFile = moduleArchivist.getConfigurationDDFile(); 111 if (confDDFile!=null) { 112 OutputStream os = out.putNextEntry(runtimeDDPath); 113 confDDFile.write(aModule.getDescriptor(), os); 114 out.closeEntry(); 115 } 116 } else { 117 AbstractArchive moduleArchive = out.getEmbeddedArchive(aModule.getArchiveUri()); 118 AbstractArchive moduleArchive2 = in.getEmbeddedArchive(aModule.getArchiveUri()); 119 write(aModule.getDescriptor(), moduleArchivist, moduleArchive2, moduleArchive); 120 } 121 } 122 123 ApplicationArchivist archivist = new ApplicationArchivist(); 125 archivist.setDescriptor(application); 126 archivist.writeRuntimeDeploymentDescriptors(out); 127 if (application.isLoadedFromApplicationXml()) { 128 archivist.copyStandardDeploymentDescriptors(in, out); 129 } else { 130 archivist.writeStandardDeploymentDescriptors(out); 131 } 132 } 133 } 134 135 140 public void write(BundleDescriptor bundle, AbstractArchive in, AbstractArchive out) 141 throws IOException 142 { 143 Archivist archivist = ArchivistFactory.getArchivistForArchive(out); 144 write(bundle, archivist, in, out); 145 } 146 147 153 protected void write(BundleDescriptor bundle, Archivist archivist, AbstractArchive in, AbstractArchive out) 154 throws IOException 155 { 156 archivist.setDescriptor(bundle); 157 archivist.writeRuntimeDeploymentDescriptors(out); 158 159 if (!bundle.isFullFlag()) { 163 archivist.writeStandardDeploymentDescriptors(out); 164 } else { 165 if (bundle.getModuleType().equals(ModuleType.WAR)) { 169 WebBundleDescriptor webBundle = (WebBundleDescriptor) bundle; 170 if (webBundle.hasWebServices()) { 171 archivist.writeStandardDeploymentDescriptors(out); 172 } else { 173 archivist.copyStandardDeploymentDescriptors(in, out); 174 } 175 } else { 176 archivist.copyStandardDeploymentDescriptors(in, out); 177 } 178 } 179 180 if (bundle.hasWebServices()) { 184 WebServicesDescriptor webServices = bundle.getWebServices(); 185 for (WebService webService : webServices.getWebServices()) { 186 if (webService.hasMappingFile() && 187 !webService.getMappingFileUri().endsWith(".xml")) { 188 Archivist.copyAnEntry(in, out, 189 webService.getMappingFileUri()); 190 } 191 } 192 } 193 } 194 } 195 | Popular Tags |