1 19 20 import java.io.File ; 21 import java.io.FileInputStream ; 22 import java.lang.reflect.Method ; 23 24 import org.enhydra.zeus.Source; 26 import org.enhydra.zeus.Unmarshaller; 27 import org.enhydra.zeus.source.StreamSource; 28 29 public class TestUnmarshaller { 30 31 public static void main(String [] args) { 32 if (args.length < 1) { 33 System.out.println("Usage: java samples.TestUnmarshaller " + 34 "[XML filename] [package]"); 35 return; 36 } 37 38 try { 39 String thePackage = null; 40 if (args.length > 1) { 41 thePackage = args[1]; 42 } else { 43 44 thePackage = ""; 46 } 47 48 Source source = new StreamSource( 49 new FileInputStream (new File (args[0]))); 50 Unmarshaller unmarshaller = new Unmarshaller(); 51 unmarshaller.setJavaPackage(thePackage); 52 Object o = unmarshaller.unmarshal(source).getObject(); 53 54 System.out.println("Generated class of type " + 56 o.getClass().getName()); 57 System.out.println("Methods available:"); 58 Method [] methods = o.getClass().getDeclaredMethods(); 59 for (int i=0; i<methods.length; i++) { 60 Method method = methods[i]; 61 System.out.print(" " + method.getReturnType().getName() + 62 " " + method.getName() + "("); 63 Class [] params = method.getParameterTypes(); 64 for (int j=0; j<params.length; j++) { 65 System.out.print(params[j].getName()); 66 if (j+1 < params.length) { 67 System.out.print(", "); 68 } 69 } 70 System.out.println(");"); 71 } 72 } catch (Exception e) { 73 e.printStackTrace(); 74 } 75 } 76 } 77 | Popular Tags |