1 28 29 package org.jibx.match; 30 31 import java.io.File ; 32 import java.lang.reflect.InvocationTargetException ; 33 import java.lang.reflect.Method ; 34 35 import org.jibx.binding.Loader; 36 37 47 48 public class TestLoader 49 { 50 private static final Class [] RUNNER_PARAM_TYPES = 51 { 52 String .class, String .class, String .class 53 }; 54 55 private TestLoader() {} 56 57 public static void main(String [] args) 58 throws ClassNotFoundException , NoSuchMethodException { 59 if (args.length >= 3 && args.length % 3 == 0) { 60 61 File temp = new File ("temp.xml"); 63 if (temp.exists()) { 64 temp.delete(); 65 } 66 67 boolean err = false; 69 int offset = 0; 70 String [] pargs = new String [3]; 71 ClassLoader base = Thread.currentThread().getContextClassLoader(); 72 for (; offset < args.length; offset += 3) { 73 try { 74 75 Thread.currentThread().setContextClassLoader(base); 77 Loader loader = new Loader(); 78 loader.loadResourceBinding(args[offset]); 79 80 Thread.currentThread().setContextClassLoader(loader); 82 Class clas = loader.loadClass("org.jibx.match.TestRunner"); 83 Method test = clas.getDeclaredMethod("runTest", 84 RUNNER_PARAM_TYPES); 85 pargs[0] = args[offset+1]; 86 pargs[1] = args[offset+2]; 87 pargs[2] = args[offset+2]; 88 Boolean result = (Boolean )test.invoke(null, pargs); 89 if (!result.booleanValue()) { 90 err = true; 91 break; 92 } 93 } catch (InvocationTargetException ex) { 94 ex.getTargetException().printStackTrace(); 95 err = true; 96 break; 97 } catch (Exception ex) { 98 ex.printStackTrace(); 99 err = true; 100 break; 101 } 102 } 103 104 if (err) { 106 System.err.println("Error on argument set: " + args[offset] + 107 ", " + args[offset+1] + ", " + args[offset+2]); 108 System.err.println("File path " + temp.getAbsolutePath()); 109 System.exit(1); 110 } 111 112 } else { 113 System.err.println("Requires arguments in sets of three:\n" + 114 " binding-resource mapped-class in-file\n" + 115 "Leaves output as temp.xml in case of error"); 116 System.exit(1); 117 } 118 } 119 } 120 | Popular Tags |