1 22 package org.jboss.ejb3.client; 23 24 import java.io.IOException ; 25 import java.net.URL ; 26 import java.net.URLClassLoader ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 import org.jboss.client.AppClientLauncher; 31 import org.jboss.ejb3.metamodel.ApplicationClientDD; 32 import org.jboss.ejb3.metamodel.ApplicationClientDDObjectFactory; 33 import org.jboss.ejb3.metamodel.JBossClientDDObjectFactory; 34 import org.jboss.util.NotImplementedException; 35 import org.jboss.xb.binding.JBossXBException; 36 37 47 public class ClientLauncher 48 implements AppClientLauncher 49 { 50 private static URL findResource(String resourceName) 51 { 52 URL url; 53 if(Thread.currentThread().getContextClassLoader() instanceof URLClassLoader ) 54 url = ((URLClassLoader ) Thread.currentThread().getContextClassLoader()).findResource("META-INF/application-client.xml"); 55 else 56 url = Thread.currentThread().getContextClassLoader().getResource("META-INF/application-client.xml"); 57 return url; 58 } 59 60 69 public static void launch(ApplicationClientDD xml, String mainClassName, String applicationClientName, String args[]) throws Exception 70 { 71 Class mainClass = Class.forName(mainClassName); 72 73 ClientContainer container = new ClientContainer(xml, mainClass, applicationClientName); 74 75 77 container.invokeMain(args); 78 79 } 81 82 89 public static ApplicationClientDD loadXML() throws JBossXBException, IOException 90 { 91 URL url = findResource("META-INF/application-client.xml"); 92 URL jbossClientURL = findResource("META-INF/jboss-client.xml"); 93 return loadXML(url, jbossClientURL); 94 } 95 96 @Deprecated 97 public static ApplicationClientDD loadXML(String urlSpec) throws JBossXBException, IOException 98 { 99 URL url = new URL (urlSpec); 100 return loadXML(url, null); 101 } 102 103 public static ApplicationClientDD loadXML(URL url, URL jbossClientURL) throws JBossXBException, IOException 104 { 105 ApplicationClientDD dd = ApplicationClientDDObjectFactory.parse(url); 106 dd = JBossClientDDObjectFactory.parse(jbossClientURL, dd); 107 return dd; 108 } 109 110 115 public static void main(String [] args) 116 { 117 try 118 { 119 if(args.length < 1) 120 throw new IllegalArgumentException ("expected a jar filename as argument"); 121 122 Class <?> mainClass; 123 124 String name = args[0]; 125 if(name.endsWith(".jar")) 126 { 127 throw new NotImplementedException(); 128 } 130 else 131 { 132 String mainClassName = name; 133 mainClass = Class.forName(mainClassName); 134 } 135 136 URL appXmlURL = mainClass.getClassLoader().getResource("META-INF/application-client.xml"); 137 if(appXmlURL == null) 138 throw new RuntimeException ("Can't find META-INF/application-client.xml"); 139 140 ApplicationClientDD xml = ApplicationClientDDObjectFactory.parse(appXmlURL); 141 142 144 List <String > newArgs = new ArrayList <String >(); 145 for(int i = 1; i < args.length; i++) 146 { 147 newArgs.add(args[i]); 148 } 149 args = newArgs.toArray(args); 150 151 String mainClassName = name; 153 launch(xml, mainClassName, "FIXME", args); 154 } 155 catch (Exception e) 156 { 157 e.printStackTrace(); 158 System.exit(1); 159 } 160 } 161 162 170 public void launch(String mainClassName, String clientName, String args[]) 171 throws Throwable 172 { 173 ApplicationClientDD xml = loadXML(); 174 launch(xml, mainClassName, clientName, args); 175 } 176 177 } 178 | Popular Tags |