1 import java.lang.reflect.*; 2 import java.util.*; 3 import java.io.*; 4 import org.apache.log4j.Category; 5 6 31 32 35 public class Afterburners 36 { 37 private static Category cat = Category.getInstance( Afterburners.class); 38 39 45 public static void main( String [] args) { 46 47 boolean doNextAfterburner = true; 48 49 for ( int i = 0; (i < args.length) && doNextAfterburner; i++) { 50 51 if ( args[i] == null) continue; 52 53 55 StreamTokenizer st = new StreamTokenizer( new StringReader( args[i])); 56 st.resetSyntax(); st.whitespaceChars(0, ' '); 58 st.wordChars('\u0021', '\u00FF'); 59 st.quoteChar('\''); 60 st.quoteChar('"'); 61 st.eolIsSignificant(false); 62 Vector argVec = new Vector(); String invokeClass = null; 65 try { 66 while( st.nextToken() != StreamTokenizer.TT_EOF) { 67 switch( st.ttype) { 68 case '"': 69 case '\'': 70 case StreamTokenizer.TT_WORD: 71 if (invokeClass == null) 72 invokeClass = st.sval; 73 else 74 argVec.addElement( st.sval); 75 break; 76 default: 77 cat.error( 78 "(internal) token type: " + st.ttype + 79 " while parsing afterburner args. Continuing." 80 ); 81 break; 82 } 83 } 84 85 if (( invokeClass == null) || ( invokeClass.trim().length() < 1)) { 86 cat.error("AFTERBURNER_ARG" + i + ": invalid class name. Ignored."); 87 continue; 88 } 89 cat.info("Afterburners AFTERBURNER_ARG" + i + ":"); 90 try { 91 Class c = Class.forName( invokeClass); 93 Method m = c.getMethod( "main", new Class [] { java.lang.String [].class} ); 94 95 String [] argsArray = new String [ argVec.size()]; 97 Enumeration ae = argVec.elements(); 98 int k = 0; 99 String comma = " "; 100 StringBuffer msg = new StringBuffer ("try calling " + invokeClass + ".main("); 101 while ( ae.hasMoreElements() ) { 102 argsArray[k] = (String ) ae.nextElement(); 103 if ( argsArray[k] == null) argsArray[k] = ""; 104 msg.append( comma + '"' + argsArray[k] + '"'); 105 comma = ", "; 106 k++; 107 } 108 cat.info( msg + ")"); 109 110 m.invoke( null, new Object [] { argsArray}); 112 } 113 catch( ClassNotFoundException e) { 114 cat.error("Class '" + invokeClass + "' not found while afterburning. Ignored."); 115 } 116 catch( NoSuchMethodException e) { 117 cat.error("Class '" + invokeClass + "' has no proper 'main'-method. Ignored."); 118 } 119 catch( IllegalAccessException e) { 120 cat.error("Class '" + invokeClass + "' has no accessible 'main'-method. Ignored."); 121 } 122 catch( InvocationTargetException e) { 123 cat.error("Class '" + invokeClass + "': invokation failed. Ignored."); 124 e.printStackTrace(); 125 } 126 } 127 catch ( IOException e) { 128 cat.error("IOException while parsing afterburner's arguments."); 129 cat.error("Afterburning stopped."); 130 doNextAfterburner = false; 131 } 132 133 } 134 } 135 136 } 137 | Popular Tags |