1 19 20 import java.io.File ; 21 import java.io.FileInputStream ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.enhydra.zeus.Binder; 27 import org.enhydra.zeus.Binding; 28 import org.enhydra.zeus.Generator; 29 import org.enhydra.zeus.Result; 30 import org.enhydra.zeus.Source; 31 import org.enhydra.zeus.binder.SchemaBinder; 32 import org.enhydra.zeus.binding.Container; 33 import org.enhydra.zeus.binding.Property; 34 import org.enhydra.zeus.generator.SimpleGenerator; 35 import org.enhydra.zeus.result.StreamResult; 36 import org.enhydra.zeus.source.StreamSource; 37 import org.enhydra.zeus.util.Arguments; 38 39 public class TestSchemaBinder { 40 41 public static void main(String [] args) { 42 Arguments theArguments = new Arguments(args); 43 44 if (!theArguments.hasValue("file")) { 46 System.out.println( 47 "Usage: java samples.TestSchemaBinder -file=<file name> " + 48 "[-package=<package>] [-quiet=true/false]"); 49 return; 50 } 51 52 try { 53 String thePackage = null; 54 if (theArguments.hasValue("package")) { 55 thePackage = theArguments.getValue("package"); 56 } else { 57 58 thePackage = ""; 60 } 61 62 boolean isQuiet = false; 64 if (theArguments.hasValue("quiet")) { 65 isQuiet = 66 theArguments.getValue("quiet") 67 .trim() 68 .equalsIgnoreCase("true"); 69 } 70 71 File schema = new File (theArguments.getValue("file")); 73 Source source = new StreamSource(new FileInputStream (schema)); 74 75 if (!isQuiet) { 76 System.out.println("Generating bindings..."); 77 } 78 79 Binder schemaBinder = new SchemaBinder(source); 81 List bindings = schemaBinder.getBindings(); 82 83 if (!isQuiet) { 84 System.out.println("Bindings generated...\n\n"); 85 } 86 87 if (!isQuiet) { 89 for (Iterator i = bindings.iterator(); i.hasNext();) { 90 Binding binding = (Binding) i.next(); 91 System.out.println("Binding"); 92 System.out.println(" Type: " + 93 binding.getClass().getName()); 94 System.out.println(" Name: " + binding.getJavaName()); 95 System.out.println(" Properties"); 96 97 try { 98 Container container = (Container) binding; 99 List properties = container.getProperties(); 100 if (properties.size() > 0) { 101 for (Iterator j = properties.iterator(); 102 j.hasNext(); ) { 103 Property property = (Property) j.next(); 104 System.out.println(" Name: " + 105 property.getJavaName()); 106 System.out.println(" Type: " + 107 property.getJavaType()); 108 } 109 } else { 110 System.out.println(" (None)"); 111 } 112 } catch (ClassCastException e) { 113 System.out.println(" (None)"); 114 } 115 System.out.println(); 116 } 117 System.out.println("--------------------------------------"); 118 System.out.println( 119 "Finished testing Binding Generation...\n\n"); 120 System.out.println("--------------------------------------"); 121 System.out.println("Going to test Class Generation...\n"); 122 } 123 124 Generator generator = new SimpleGenerator(); 125 generator.setOutputDirectory(new File ("output")); 126 for (Iterator i = bindings.iterator(); i.hasNext();) { 128 129 if (!isQuiet) { 130 System.out.println("--------------------------------"); 131 } 132 133 Binding binding = (Binding) i.next(); 134 generator.generate(binding); 135 136 if (!isQuiet) { 137 System.out.println("--------------------------------"); 138 } 139 } 140 141 } catch (Exception e) { 142 e.printStackTrace(); 143 } 144 } 145 } 146 | Popular Tags |