1 19 package org.enhydra.zeus.util; 20 21 import java.io.IOException ; 22 import java.util.List ; 23 24 import org.enhydra.zeus.Binder; 26 import org.enhydra.zeus.Source; 27 import org.enhydra.zeus.ZeusException; 28 import org.enhydra.zeus.binder.SchemaBinder; 29 import org.enhydra.zeus.source.StreamSource; 30 31 39 public class XSDSourceGenerator extends BaseSourceGenerator 40 implements SourceGenerator { 41 42 47 public XSDSourceGenerator() { 48 super(); 49 } 50 51 62 protected List getConstraintBindings() throws IOException { 63 Source source = new StreamSource(constraintsReader); 64 Binder xsdBinder = new SchemaBinder(source); 65 xsdBinder.setIsCollapsingSimpleElements(collapseSimpleElements); 66 xsdBinder.setIsIgnoringIDAttributes(ignoreIDAttributes); 67 68 List bindings = xsdBinder.getBindings(); 69 return bindings; 70 } 71 72 79 public static void main(String [] args) { 80 try { 81 Arguments arguments = new Arguments(args); 82 83 SourceGenerator sourceGenerator = 85 new XSDSourceGenerator(); 86 87 String constraintsFilename = 89 arguments.getValue("constraints"); 90 if (constraintsFilename == null) { 91 System.out.println("Usage: java " + 92 sourceGenerator.getClass().getName() + 93 " -constraints=<constraints filename>" + 94 " [-outputDir=<output directory>" + 95 " [-collapseSimpleElements=" + 96 "<true | false>]" + 97 " [-ignoreIDAttributes=<true | false>]" + 98 " [-javaPackage=<Java package name>]"); 99 return; 100 } 101 102 String outputDirName = arguments.getValue("outputDir"); 104 String collapseSimpleElements = 105 arguments.getValue("collapseSimpleElements"); 106 String ignoreIDAttributes = 107 arguments.getValue("ignoreIDAttributes"); 108 String javaPackage = arguments.getValue("javaPackage"); 109 sourceGenerator.setConstraintsInput(constraintsFilename); 110 if (outputDirName != null) { 111 sourceGenerator.setOutputDir(outputDirName); 112 } 113 if (javaPackage != null) { 114 sourceGenerator.setJavaPackage(javaPackage); 115 } 116 if ((collapseSimpleElements != null) && 117 (collapseSimpleElements.equalsIgnoreCase("true"))) { 118 119 if ((ignoreIDAttributes != null) && 120 (ignoreIDAttributes.equalsIgnoreCase("true"))) { 121 122 sourceGenerator.setCollapseSimpleElements(true, true); 123 } 124 sourceGenerator.setCollapseSimpleElements(true, false); 125 } 126 127 sourceGenerator.generate(); 128 } catch (IOException e) { 129 System.out.println("Error generating source code: " + 130 e.getMessage()); 131 e.printStackTrace(); 132 } catch (ZeusException e) { 133 System.out.println("Error generating source code: " + 134 e.getMessage()); 135 e.printStackTrace(); 136 } 137 } 138 } 139 | Popular Tags |