Switch.getSwitch().setProviderManager(ProviderManager.getProviderManager());
// added for ClientContainer.xml initialization
setTargetServerProperties(xmlPath);
int exitCode = 0; // 0 for success
AppContainer container = null;
// Ensure cleanup is performed, even if
// application client calls System.exit().
Cleanup cleanup = new Cleanup();
Runtime runtime = Runtime.getRuntime();
runtime.addShutdownHook(cleanup);
// Set the HTTPS URL stream handler.
java.security.AccessController.doPrivileged(new
java.security.PrivilegedAction() {
public Object run() {
URL.setURLStreamHandlerFactory(new
HttpsURLStreamHandlerFactory());
return null;
}
});
File appClientFile;
/*
*For Java Web Start launches, locate the jar file implicitly.
*Otherwise, if the user omitted the clientjar argument (and the
*code has gotten this far) then the user must have used the
*first argument as the name of the class in ${user.dir} to run. If
*the user actually specified the clientjar argument, then use that
*value as the file spec for the client jar.
*/
if (isJWS) {
/*
*Java Web Start case.
*/
appClientFile = findAppClientFileForJWSLaunch();
} else if (clientJar==null) {
/*
*First-argument-as-class-name case
*/
File userDir = new File(System.getProperty("user.dir"));
File appClientClass = new File(userDir, className);
appClientFile = appClientClass.getParentFile();
} else {
/*
*Normal case - clientjar argument specified.
*/
appClientFile = new File(clientJar);
}
// class loader
URL[] urls = new URL[1];
urls[0] = appClientFile.toURI().toURL();
/*
*Set the parent of the new class loader to the current loader.
*The Java Web Start-managed class path is implemented in the
*current loader, so it must remain on the loader stack.
*/
ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
ClassLoader jcl = new URLClassLoader(urls, currentCL);
Thread.currentThread().setContextClassLoader(jcl);
ApplicationClientDescriptor appDesc = null;
// create the application container and call preInvoke.
/*
*Note that if the client jar argument is missing it can mean one of
*two things: Either the user used the first argument to specify
*the class to execute or
*this is a Java Web Start launch.
*/
if((clientJar!=null || isJWS ) && FileUtil.isEARFile(appClientFile)) {
// loads application with only the clients
Application app = null;
try {
ApplicationArchivist arch = new ApplicationArchivist();
arch.setAnnotationProcessingRequested(true);
// Set class loader here before opening archive
// to enable validation.
arch.setClassLoader(jcl);
app = (Application) arch.open(appClientFile);
} catch (Throwable t) {
_logger.log(Level.WARNING, "acc.failed_load_client_desc",
clientJar);
throw t;
}
app.setClassLoader(jcl);
appDesc = null;
int appclientCount = 0;
for (Iterator itr =
app.getApplicationClientDescriptors().iterator();
itr.hasNext();) {
ApplicationClientDescriptor next =
(ApplicationClientDescriptor) itr.next();
appclientCount++;
}
for (Iterator itr =
app.getApplicationClientDescriptors().iterator();
itr.hasNext();) {
ApplicationClientDescriptor next =
(ApplicationClientDescriptor) itr.next();
if (appclientCount == 1) {
//for -mainclass <class name> option
if (mainClass != null) {
if (!next.getMainClassName().equals(mainClass)) {
next.setMainClassName(mainClass);
}
}
appDesc = next;
break;
} else {//app contains multiple app client jars
if (mainClass != null) {
if (next.getMainClassName().equals(mainClass)) {
appDesc = next;
break;
}
} else {
if (displayName == null) {
_logger.log(Level.SEVERE,"acc.no_mainclass_or_displayname");
System.exit(1);
} else if (displayName != null && next.getName().equals(displayName)) {
if(appDesc == null) {
appDesc = next;
} else {
//multiple app duplicated display name
_logger.log(Level.WARNING, "acc.duplicate_display_name");
System.exit(1);
}
}
}
}
}
//construct AppContainer using appDesc
if (appDesc != null) {
container = new AppContainer(appDesc, guiAuth);
// the archive uri must have absolute path
//f = new File (f, appDesc.getModuleDescriptor().getArchiveUri());
}
} else {
// we are dealing with a class file or a client jar
// reads std & iAS application xml
try {
// Set classloader before opening archive to enable
// validation.
AppClientArchivist arch = new AppClientArchivist();
arch.setAnnotationProcessingRequested(true);
arch.setClassLoader(jcl);
// for class case, get default bundle
if (className!=null) {
appDesc = (ApplicationClientDescriptor) arch.getDefaultBundleDescriptor();
} else {
// for client jar case, do not process annotations.
// use AppClientArchivist.open(String) instead of
// AppClientArchivist.open(AbstractArchive) since the
// open(String) method calls validate.
appDesc = (ApplicationClientDescriptor) arch.open(appClientFile.getAbsolutePath());
}
if (className!=null) {
// post masssaging
AbstractArchive archive;
if (appClientFile.isDirectory()) {
archive = new FileArchive();
((FileArchive) archive).open(appClientFile.getAbsolutePath());
} else {
archive = new InputJarArchive();
((InputJarArchive) archive).open(appClientFile.getAbsolutePath());
}
if (appDesc.getMainClassName()==null || appDesc.getMainClassName().length()==0) {
appDesc.setMainClassName(className);
arch.processAnnotations(appDesc, archive);
// let's remove our appArgs first element since it was the app client class name
//...but only if this is not a Java Web Start launch.
if (mainClass==null && ! isJWS) {
appArgs.removeElementAt(0);
}
}
}
} catch (Throwable t) {
_logger.log(Level.WARNING,
"main.appclient_descriptors_failed", (displayName == null) ? mainClass : displayName);
throw t;
}
container = new AppContainer(appDesc, guiAuth);
}
if(container == null) {
_logger.log(Level.WARNING, "acc.no_client_desc",
(displayName == null) ? mainClass : displayName);
System.exit(1);
}
// Set the authenticator which is called back when a
// protected web resource is requested and authentication data is
// needed.
Authenticator.setDefault(new HttpAuthenticator(container));
// log a machine name, port number per Jagadesh's request
_logger.log(Level.INFO, "acc.orb_host_name", host);
_logger.log(Level.INFO, "acc.orb_port_number", port);
Properties props = new Properties();
props.put("org.omg.CORBA.ORBInitialHost", host);
props.put("org.omg.CORBA.ORBInitialPort", port);
String appMainClass = container.preInvoke(props);
cleanup.setAppContainer(container);
// load and invoke the real main of the application.
Class cl = null;
try {