FileDocCategorySizeDatePackage
ClientLauncher.javaAPI DocJBoss 4.2.15995Fri Jul 13 20:53:52 BST 2007org.jboss.ejb3.client

ClientLauncher

public class ClientLauncher extends Object
This class launches a JavaEE 5 application client. The first argument is either a jar file containing the client deployment files or the application client class name. The manifest file Main-Class attribute must point to the application client class. It must also contain an application client deployment descriptor file (META-INF/application-client.xml).
author
Carlo de Wolf
version
$Revision: $

Fields Summary
Constructors Summary
Methods Summary
private static java.net.URLfindResource(java.lang.String resourceName)

      URL url;
      if(Thread.currentThread().getContextClassLoader() instanceof URLClassLoader)
         url = ((URLClassLoader) Thread.currentThread().getContextClassLoader()).findResource(resourceName);
      else
         url = Thread.currentThread().getContextClassLoader().getResource(resourceName);
      return url;
   
public static voidlaunch(org.jboss.ejb3.metamodel.ApplicationClientDD xml, java.lang.String mainClassName, java.lang.String applicationClientName, java.lang.String[] args)
Convenience method for launching a client container.

param
xml
param
mainClassName
param
applicationClientName
param
args
throws
Exception

      Class mainClass = Class.forName(mainClassName);
      
      ClientContainer container = new ClientContainer(xml, mainClass, applicationClientName);
      
      // TODO: postContruct
      
      container.invokeMain(args);
      
      // TODO: preDestroy
   
public voidlaunch(java.lang.String mainClassName, java.lang.String clientName, java.lang.String[] args)
The AppClientLauncher method for launching a client container.

param
mainClassName - the class whose main(String[]) will be invoked
param
clientName - the client name that maps to the server side JNDI ENC
param
args - the args to pass to main method
throws
Throwable

      ApplicationClientDD xml = loadXML();
      launch(xml, mainClassName, clientName, args);
   
public static org.jboss.ejb3.metamodel.ApplicationClientDDloadXML()
Convenience method to load the XML descriptor.

return
throws
IOException
throws
JBossXBException

      URL url = findResource("META-INF/application-client.xml");
      URL jbossClientURL = findResource("META-INF/jboss-client.xml");
      return loadXML(url, jbossClientURL);
   
public static org.jboss.ejb3.metamodel.ApplicationClientDDloadXML(java.lang.String urlSpec)

      URL url = new URL(urlSpec);
      return loadXML(url, null);
   
public static org.jboss.ejb3.metamodel.ApplicationClientDDloadXML(java.net.URL url, java.net.URL jbossClientURL)

      ApplicationClientDD dd = ApplicationClientDDObjectFactory.parse(url);
      dd = JBossClientDDObjectFactory.parse(jbossClientURL, dd);
      return dd;
   
public static voidmain(java.lang.String[] args)
Work in progress.

param
args the arguments for the launcher

      try
      {
         if(args.length < 1)
            throw new IllegalArgumentException("expected a jar filename as argument");
         
         Class<?> mainClass;
         
         String name = args[0];
         if(name.endsWith(".jar"))
         {
            throw new NotImplementedException();
//            JarFile jarFile = new JarFile(jarName);
         }
         else
         {
            String mainClassName = name;
            mainClass = Class.forName(mainClassName);
         }
         
         URL appXmlURL = mainClass.getClassLoader().getResource("META-INF/application-client.xml");
         if(appXmlURL == null)
            throw new RuntimeException("Can't find META-INF/application-client.xml");
         
         ApplicationClientDD xml = ApplicationClientDDObjectFactory.parse(appXmlURL);
         
         // FIXME: j2ee.clientName
         
         List<String> newArgs = new ArrayList<String>();
         for(int i = 1; i < args.length; i++)
         {
            newArgs.add(args[i]);
         }
         args = newArgs.toArray(args);
         
         // FIXME: when jar gets implemented this won't work anymore
         String mainClassName = name;
         launch(xml, mainClassName, "FIXME", args);
      }
      catch (Exception e)
      {
         e.printStackTrace();
         System.exit(1);
      }