1 22 package org.jboss.client; 23 24 import java.lang.reflect.InvocationTargetException ; 25 import java.lang.reflect.Method ; 26 import java.lang.reflect.Modifier ; 27 28 import org.jboss.logging.Logger; 29 import org.jboss.naming.client.java.javaURLContextFactory; 30 31 38 public class ReflectionLauncher 39 implements AppClientLauncher 40 { 41 private static Logger log = Logger.getLogger(ReflectionLauncher.class); 42 43 53 public void launch(String clientClass, String clientName, String [] args) 54 throws Throwable 55 { 56 try 57 { 58 System.setProperty(javaURLContextFactory.J2EE_CLIENT_NAME_PROP, clientName); 59 Class cl = Class.forName(clientClass); 61 Method main = cl.getDeclaredMethod("main", new Class []{String [].class}); 62 Object [] mainArgs = {args}; 63 if( Modifier.isStatic(main.getModifiers()) ) 64 { 65 main.invoke(null, mainArgs); 66 } 67 else 68 { 69 Object client = cl.newInstance(); 70 main.invoke(client, mainArgs); 71 } 72 log.debug("Client invoker success."); 73 } 74 catch (InvocationTargetException e) 75 { 76 throw e.getTargetException(); 77 } 78 } 79 } 80 | Popular Tags |