Vector moduleNames = new Vector();
if (descriptor.isApplication()) {
Application app = (Application) descriptor;
for (ModuleDescriptor md : app.getModules()) {
Archivist moduleArchivist = archivistFactory.getArchivist(md.getModuleType());
ReadableArchive subSource = source.getSubArchive(md.getArchiveUri());
ReadableArchive subSource2 = source2.getSubArchive(md.getArchiveUri());
moduleNames.add(md.getArchiveUri());
// any file that needs to be kept in the sub module should be
// calculated here
Vector subEntries = new Vector();
// manifest file always stay in embedded jar
subEntries.add(JarFile.MANIFEST_NAME);
BundleDescriptor subBundleDesc =
(BundleDescriptor) md.getDescriptor();
// all mapping file stay within the embedded jar
WebServicesDescriptor wsd = subBundleDesc.getWebServices();
if (wsd!=null) {
for (Iterator itr = wsd.getWebServices().iterator();itr.hasNext();) {
WebService ws = (WebService) itr.next();
subEntries.add(ws.getMappingFileUri());
}
}
Set refs = subBundleDesc.getServiceReferenceDescriptors();
for (Iterator itr = refs.iterator();itr.hasNext();) {
ServiceReferenceDescriptor srd = (ServiceReferenceDescriptor) itr.next();
subEntries.add(srd.getMappingFileUri());
}
// first copy original module files in the root on the target
// except for .rar files contents.
// We need to do it first so we save the list of files to be saved in the
// embedded archive (for proper deployment descriptor loading)
List embeddedFiles = new ArrayList();
for (Enumeration e = subSource.entries();e.hasMoreElements();) {
String entryName = (String) e.nextElement();
// Deployment Descriptors (and associated) go in the embedded files
if (entryName.endsWith(".xml") ||
subEntries.contains(entryName) ||
entryName.startsWith(subBundleDesc.getWsdlDir())) {
embeddedFiles.add(entryName);
} else {
try {
copy(subSource, target, entryName);
} catch(IOException ioe) {
// dup, we ignore
}
}
}
// now we need to copy the files we saved inside the embedded
// archive file
WritableArchive subTarget = target.createSubArchive(md.getArchiveUri());
// and copy the list of identified files inside it
// copy deployment descriptor files from generated xml directory
for (Iterator itr = embeddedFiles.iterator();itr.hasNext();) {
String entryName = (String) itr.next();
copyWithOverride(subSource, subSource2, subTarget, entryName);
}
copy(subSource, subSource2, subTarget,
moduleArchivist.getStandardDDFile().getDeploymentDescriptorPath(),
embeddedFiles);
// every module may not have a sun descriptor, e.g. par file does not have one.
if(moduleArchivist.getConfigurationDDFile()!=null) {
copy(subSource, subSource2, subTarget,
moduleArchivist.getConfigurationDDFile().getDeploymentDescriptorPath(),
embeddedFiles);
}
// and the manifest file since it does not appear in the list of files...
copy(subSource, subTarget, JarFile.MANIFEST_NAME);
// we do not need to copy anything else from the source embedded module
// since all .class files and resources have moved at the top level of the target
// application client container jar, so we can close out both subarchives
target.closeEntry(subTarget);
subSource.close();
subSource2.close();
}
}
// standalone modules and .ear file level entries fall back here, we
// just need to copy the original archive file elements at the root level
// of the target application client container jar file.
Archivist archivist = archivistFactory.getArchivist(descriptor.getModuleType());
// because of the backend layout, the appclient jar file appears in the list of files
// in the source archive (which is the exploded directory where we started writing
// the appclient file... this is also true when doing deploydir deployment
String appClientFileName = target.getURI().getSchemeSpecificPart().substring(target.getURI().getSchemeSpecificPart().lastIndexOf(File.separatorChar)+1);
// and the manifest file since it does not appear in the
// list of files...
copy(source, target, JarFile.MANIFEST_NAME);
List xmlFiles = new ArrayList();
String libDir = computeLibraryDirectory(descriptor);
for (Enumeration e = ((FileArchive)source).entries(moduleNames.elements());e.hasMoreElements();) {
String entryName = (String) e.nextElement();
// if this is the appclient we are creating, we pass
if (entryName.equals(appClientFileName)) {
continue;
}
// now we need to write the elements in the target file and explode
// if it is a utility jar file
if (entryName.endsWith(".jar") && ! inLibDirSubdirectory(libDir, entryName)) {
// explode
ReadableArchive subSource = null;
try {
subSource = source.getSubArchive(entryName);
for (Enumeration subEntries = subSource.entries();subEntries.hasMoreElements();) {
String subEntryName = (String) subEntries.nextElement();
if(DescriptorConstants.PERSISTENCE_DD_ENTRY.equals(subEntryName)){
// If we copy DescriptorConstants.PAR_DD_ENTRY into
// *Client.jar then during subsequent app loading time
// server will treat that jar as another PU Root and try to load it.
// so don't copy such a file.
continue;
}
copy(subSource, target, subEntryName);
}
} finally {
if (subSource != null) {
subSource.close();
}
}
} else {
if (entryName.endsWith(".xml")) {
xmlFiles.add(entryName);
}
copyWithOverride(source, source2, target, entryName);
}
}
copy(source, source2, target,
archivist.getStandardDDFile().getDeploymentDescriptorPath(),
xmlFiles);
copy(source, source2, target,
archivist.getConfigurationDDFile().getDeploymentDescriptorPath(),
xmlFiles);
}