1 23 24 package com.sun.enterprise.appclient; 25 26 import com.sun.enterprise.deployment.Application; 27 import com.sun.enterprise.deployment.ApplicationClientDescriptor; 28 import com.sun.enterprise.deployment.archivist.Archivist; 29 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 30 import com.sun.enterprise.deployment.backend.J2EEModuleExploder; 31 import com.sun.enterprise.deployment.BundleDescriptor; 32 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 33 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 34 import com.sun.enterprise.deployment.RootDeploymentDescriptor; 35 import com.sun.enterprise.deployment.util.ModuleDescriptor; 36 import com.sun.enterprise.loader.EJBClassLoader; 37 import com.sun.enterprise.util.io.FileUtils; 38 import java.io.File ; 39 import java.io.IOException ; 40 import java.net.MalformedURLException ; 41 import java.net.URI ; 42 import java.net.URISyntaxException ; 43 import java.net.URL ; 44 import java.util.Enumeration ; 45 import java.util.HashSet ; 46 import java.util.Iterator ; 47 import java.util.Set ; 48 import java.util.ArrayList ; 49 import java.util.List ; 50 import java.util.logging.Level ; 51 import java.util.logging.Logger ; 52 import javax.enterprise.deploy.shared.ModuleType ; 53 import org.xml.sax.SAXParseException ; 54 55 65 public class NestedAppClientInfo extends AppClientInfo { 66 67 private Application appDesc = null; 68 69 70 private ApplicationClientDescriptor selectedAppClientDescriptor = null; 71 72 73 private String displayNameFromCommandLine; 74 75 public NestedAppClientInfo( 76 boolean isJWS, Logger logger, File archive, 77 Archivist archivist, String mainClassFromCommandLine, 78 String displayNameFromCommandLine) { 79 super(isJWS, logger, archive, archivist, mainClassFromCommandLine); 80 this.displayNameFromCommandLine = displayNameFromCommandLine; 81 } 82 83 89 protected ApplicationClientDescriptor getAppClient(Archivist archivist) { 90 91 if (selectedAppClientDescriptor != null) { 92 return selectedAppClientDescriptor; 93 } 94 95 Application app = Application.class.cast(archivist.getDescriptor()); 96 97 102 Set <ApplicationClientDescriptor> embeddedAppClients = 103 (Set <ApplicationClientDescriptor>) 104 app.getApplicationClientDescriptors(); 105 106 109 if (embeddedAppClients.size() == 0) { 110 throw new IllegalArgumentException ( 111 localStrings.getString("appclient.noEmbeddedAppClients")); 112 } 113 114 118 if (embeddedAppClients.size() == 1) { 119 selectedAppClientDescriptor = useFirstEmbeddedAppClient( 120 embeddedAppClients, mainClassFromCommandLine); 121 } else { 122 selectedAppClientDescriptor = chooseFromEmbeddedAppClients( 123 embeddedAppClients, mainClassFromCommandLine, 124 displayNameFromCommandLine); 125 126 129 if (selectedAppClientDescriptor == null) { 130 if (mainClassFromCommandLine != null) { 131 throw new IllegalArgumentException (localStrings.getString("appclient.noMatchingClientUsingMainClass", mainClassFromCommandLine)); 132 } else { 133 throw new IllegalArgumentException (localStrings.getString("appclient.noMatchingClientUsingDisplayName", displayNameFromCommandLine)); 134 } 135 } 136 } 137 return selectedAppClientDescriptor; 138 } 139 140 private ApplicationClientDescriptor chooseFromEmbeddedAppClients( 141 Set <ApplicationClientDescriptor> embeddedAppClients, 142 String mainClassFromCommandLine, 143 String displayNameFromCommandLine) { 144 ApplicationClientDescriptor result = null; 145 146 159 for (ApplicationClientDescriptor candidate : embeddedAppClients) { 160 164 if (mainClassFromCommandLine != null) { 165 if (candidate.getMainClassName().equals(mainClassFromCommandLine)) { 166 result = candidate; 167 171 break; 172 } 173 } else { 174 177 if (candidate.getName().equals(displayNameFromCommandLine)) { 178 182 if (result == null) { 183 result = candidate; 184 189 } else { 190 throw new IllegalArgumentException (localStrings.getString("appclient.duplicate_display_name", displayNameFromCommandLine)); 191 } 192 } 193 } 194 } 195 return result; 196 } 197 198 private ApplicationClientDescriptor useFirstEmbeddedAppClient(Set <ApplicationClientDescriptor> embeddedAppClients, String mainClassNameFromCommandLine) { 199 ApplicationClientDescriptor result = null; 200 201 205 Iterator <ApplicationClientDescriptor> it = embeddedAppClients.iterator(); 206 if ( ! it.hasNext()) { 207 throw new IllegalStateException (localStrings.getString("appclient.unexpectedEndOfEmbeddedClients")); 208 } 209 210 result = embeddedAppClients.iterator().next(); 211 212 219 if (mainClassNameFromCommandLine != null) { 220 result.setMainClassName(mainClassNameFromCommandLine); 221 } 222 return result; 223 } 224 225 232 protected AbstractArchive expand(File file) 233 throws IOException , Exception { 234 235 File tmpDir = createTmpArchiveDir(file); 236 _logger.fine("Expanding original archive " + file.getAbsolutePath() + 237 " into " + tmpDir.getAbsolutePath()); 238 239 J2EEModuleExploder.explodeJar(file, tmpDir); 241 242 FileArchive appArchive = new FileArchive(); 244 appArchive.open(tmpDir.getAbsolutePath()); 245 246 ApplicationArchivist archivist = new ApplicationArchivist(); 247 if (archivist.hasStandardDeploymentDescriptor(appArchive)) { 248 appDesc = (Application) 249 archivist.readStandardDeploymentDescriptor(appArchive); 250 } else { 251 appDesc = Application.createApplication(appArchive,true); 252 } 253 254 Iterator <ModuleDescriptor> bundles = appDesc.getModules(); 257 while (bundles.hasNext()) { 258 259 ModuleDescriptor bundle = bundles.next(); 260 261 String moduleName = bundle.getArchiveUri(); 262 File srcArchive = new File (tmpDir, moduleName); 263 264 if (srcArchive.exists()) { 265 String massagedModuleName = 266 FileUtils.makeFriendlyFilename(moduleName); 267 File moduleDir = 268 new File (tmpDir, massagedModuleName); 269 J2EEModuleExploder.explodeJar(srcArchive, moduleDir); 270 271 srcArchive.delete(); 273 } 274 } 275 276 279 return appArchive; 280 } 281 282 289 protected List <String > getClassPaths(AbstractArchive archive) { 290 291 List <String > paths = new ArrayList (); 292 String appRoot = archive.getArchiveUri(); 293 paths.add(appRoot); 294 295 if (appDesc != null) { 296 Iterator <ModuleDescriptor> bundles = appDesc.getModules(); 298 while (bundles.hasNext()) { 299 ModuleDescriptor bundle = bundles.next(); 300 String moduleRoot = appRoot + File.separator + 301 FileUtils.makeFriendlyFilename(bundle.getArchiveUri()); 302 paths.add(moduleRoot); 303 } 304 } else { 305 } 309 310 for (Enumeration en = archive.entries(); en.hasMoreElements(); ) { 312 String entryName = (String ) en.nextElement(); 313 if (entryName.endsWith(".jar")) { 314 String entry = appRoot + File.separator + entryName; 315 paths.add(entry); 316 } 317 } 318 319 return paths; 320 } 321 322 protected String getAppClientRoot( 323 AbstractArchive archive, ApplicationClientDescriptor descriptor) { 324 String appRoot = archive.getArchiveUri(); 325 String moduleUri = descriptor.getModuleDescriptor().getArchiveUri(); 326 String moduleRoot = appRoot + File.separator + 327 FileUtils.makeFriendlyFilename(moduleUri); 328 return moduleRoot; 329 } 330 } 331 | Popular Tags |