1 19 package org.enhydra.zeus.util; 20 21 import java.io.IOException ; 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.ZeusException; 30 import org.enhydra.zeus.binder.DTDBinder; 31 import org.enhydra.zeus.generator.SimpleGenerator; 32 import org.enhydra.zeus.source.DTDSource; 33 import org.enhydra.zeus.source.StreamDTDSource; 34 35 43 public class DTDSourceGenerator extends BaseSourceGenerator 44 implements SourceGenerator { 45 46 47 private static String interfacePackageName; 48 49 50 private String rootElementName; 51 52 57 public DTDSourceGenerator() { 58 super(); 59 } 60 61 72 protected List getConstraintBindings() throws IOException { 73 74 DTDSource dtdSource = new StreamDTDSource(constraintsReader); 76 77 DTDBinder dtdBinder = new DTDBinder(dtdSource, rootElementName); 79 dtdBinder.setIsCollapsingSimpleElements(collapseSimpleElements); 80 dtdBinder.setIsIgnoringIDAttributes(ignoreIDAttributes); 81 82 return dtdBinder.getBindings(); 84 } 85 86 97 protected Generator getGenerator() { 98 Generator generator = new SimpleGenerator(); 99 return generator; 100 } 101 102 110 public void setRootElementName(String rootElementName) { 111 this.rootElementName = rootElementName; 112 } 113 114 121 public static void main(String [] args) { 122 try { 123 Arguments arguments = new Arguments(args); 124 125 DTDSourceGenerator sourceGenerator = 127 new DTDSourceGenerator(); 128 129 String constraintsFilename = 131 arguments.getValue("constraints"); 132 if (constraintsFilename == null) { 133 System.out.println("Usage: java " + 134 sourceGenerator.getClass().getName() + 135 "\n -constraints=<constraints filename>" + 136 "\n [-outputDir=<output directory>]" + 137 "\n [-collapseSimpleElements=<true | false>]" + 138 "\n [-ignoreIDAttributes=<true | false>]" + 139 "\n [-javaPackage=<Java package name>]" + 140 "\n [-root=<Root Element Name>]"); 141 return; 142 } 143 144 String outputDirName = arguments.getValue("outputDir"); 146 String collapseSimpleElements = 147 arguments.getValue("collapseSimpleElements"); 148 String ignoreIDAttributes = 149 arguments.getValue("ignoreIDAttributes"); 150 String javaPackage = arguments.getValue("javaPackage"); 151 String rootElementName = arguments.getValue("root"); 152 153 sourceGenerator.setConstraintsInput(constraintsFilename); 154 155 if (outputDirName != null) { 156 sourceGenerator.setOutputDir(outputDirName); 157 } 158 if (javaPackage != null) { 159 sourceGenerator.setJavaPackage(javaPackage); 160 } 161 if ((collapseSimpleElements != null) && 162 (collapseSimpleElements.equalsIgnoreCase("true"))) { 163 if ((ignoreIDAttributes != null) && 164 (ignoreIDAttributes.equalsIgnoreCase("true"))) { 165 sourceGenerator.setCollapseSimpleElements(true, true); 166 } else { 167 sourceGenerator.setCollapseSimpleElements(true, false); 168 } 169 } 170 if (rootElementName != null) { 171 sourceGenerator.setRootElementName(rootElementName); 172 } 173 174 sourceGenerator.generate(); 176 177 } catch (IOException e) { 178 System.out.println("Error generating source code: " + 179 e.getMessage()); 180 e.printStackTrace(); 181 } catch (ZeusException e) { 182 System.out.println("Error generating source code: " + 183 e.getMessage()); 184 e.printStackTrace(); 185 } 186 } 187 } 188 | Popular Tags |