/** Start the DTD parsing (called by GenBeans class) */ public void process() throws java.io.IOException, Schema2BeansException { if (this.filename == null && this.schemaIn == null) throw new IllegalArgumentException(Common.getMessage("FilenameNotSpecified_msg", errHeader)); if (this.handler == null) throw new IllegalArgumentException(Common.getMessage("HandlerNotSpecified_msg", errHeader)); if (config.isTraceParse()) { config.messageOut.println( "Parsing file " + this.filename.toString() + // NOI18N " with handler " + this.handler.getClass()); // NOI18N } try { startupReader(); this.handler.startDocument(config.getDocRoot()); this.parse(); shutdownReader(); this.handler.endDocument(); } catch (FileNotFoundException e) { config.messageOut.println("Error: file " + this.filename.toString() + " not found"); // NOI18N throw e; /* } catch (IllegalStateException e) { throw e; } catch (RuntimeException e) { TraceLogger.error(e); throw e; */ } }
// Entry point - print help and call the parser public static void main(String args[]) { GenBeans.Config config = new GenBeans.Config(); if (config.parseArguments(args)) { config.showHelp(System.out); return; } /* if (config.getFilename() == null) { config.showHelp(System.out); return; } try { for (int i=0; i<args.length; i++) { if (args[i].equals("-f")) { config.setFilename(new File(args[++i])); help++; } else if (args[i].equals("-d")) { config.setDocRoot(args[++i]); if (config.getDocRoot() == null) { help = 0; break; } } else if (args[i].equals("-veto")) { config.setVetoable(true); } else if (args[i].equals("-t")) { ++i; if (args[i].equalsIgnoreCase("parse")) config.setTraceParse(true); else if (args[i].equalsIgnoreCase("gen")) config.setTraceGen(true); else if (args[i].equalsIgnoreCase("dot")) config.setTraceDot(true); else { if (!args[i].equalsIgnoreCase("all")) --i; // unknown value, trace all, and rethink that option config.setTraceParse(true); config.setTraceGen(true); config.setTraceMisc(true); config.setTraceDot(true); } } else if (args[i].equals("-ts")) { config.setDumpToString(true); } else if (args[i].equals("-version")) { System.out.println("schema2beans - " + Version.getVersion()); return; } else if (args[i].equals("-noe")) { config.setScalarException(false); } else if (args[i].equals("-p")) { config.setPackagePath(args[++i]); if (config.getPackagePath() == null) { help = 0; break; } } else if (args[i].equals("-r")) { String dir = args[++i]; if (dir == null) { help = 0; break; } config.setRootDir(new File(dir)); } else if (args[i].equals("-st")) { config.setStandalone(true); } else if (args[i].equals("-sp")) { tab = args[++i]; } else if (args[i].equals("-mdd")) { String f = args[++i]; if (f == null) { help = 0; break; } config.setMddFile(new File(f)); } else if (args[i].equalsIgnoreCase("-xmlschema")) { config.setSchemaTypeNum(Config.XML_SCHEMA); } else if (args[i].equalsIgnoreCase("-dtd")) { config.setSchemaTypeNum(Config.DTD); } else if (args[i].equalsIgnoreCase("-throw")) { config.setThrowErrors(true); } else if (args[i].equalsIgnoreCase("-basebean")) { config.setOutputType(Config.OUTPUT_TRADITIONAL_BASEBEAN); } else if (args[i].equalsIgnoreCase("-javabeans")) { config.setOutputType(Config.OUTPUT_JAVABEANS); } else if (args[i].equalsIgnoreCase("-validate")) { config.setGenerateValidate(true); } else if (args[i].equalsIgnoreCase("-novalidate")) { config.setGenerateValidate(false); } else if (args[i].equalsIgnoreCase("-propertyevents")) { config.setGeneratePropertyEvents(true); } else if (args[i].equalsIgnoreCase("-nopropertyevents")) { config.setGeneratePropertyEvents(false); } else if (args[i].equalsIgnoreCase("-transactions")) { config.setGenerateTransactions(true); } else if (args[i].equalsIgnoreCase("-attrprop")) { config.setAttributesAsProperties(true); } else if (args[i].equalsIgnoreCase("-noattrprop")) { config.setAttributesAsProperties(false); } else if (args[i].equalsIgnoreCase("-indexedpropertytype")) { config.setIndexedPropertyType(args[++i]); } else if (args[i].equalsIgnoreCase("-delegator")) { config.setGenerateDelegator(true); } else if (args[i].equalsIgnoreCase("-premium")) { config.buyPremium(); } else if (args[i].equalsIgnoreCase("-commoninterface")) { config.setGenerateCommonInterface(COMMON_BEAN); } else if (args[i].equalsIgnoreCase("-nocommoninterface")) { config.setGenerateCommonInterface(null); } else if (args[i].equalsIgnoreCase("-commoninterfacename")) { config.setGenerateCommonInterface(args[++i]); } else if (args[i].equalsIgnoreCase("-compile")) { config.setDoCompile(true); } else if (args[i].equalsIgnoreCase("-auto")) { config.setAuto(true); } else if (args[i].equalsIgnoreCase("-defaultsaccessable")) { config.setDefaultsAccessable(true); } else if (args[i].equalsIgnoreCase("-useinterfaces")) { config.setUseInterfaces(true); } else if (args[i].equalsIgnoreCase("-geninterfaces")) { config.setGenerateInterfaces(true); } else if (args[i].equalsIgnoreCase("-nogeninterfaces")) { config.setGenerateInterfaces(false); } else if (args[i].equalsIgnoreCase("-keepelementpositions")) { config.setKeepElementPositions(true); } else if (args[i].equalsIgnoreCase("-comments")) { config.setProcessComments(true); } else if (args[i].equalsIgnoreCase("-doctype")) { config.setProcessDocType(true); } else if (args[i].equalsIgnoreCase("-dumpbeantree")) { config.setDumpBeanTree(new File(args[++i])); } else if (args[i].equalsIgnoreCase("-removeunreferencednodes")) { config.setRemoveUnreferencedNodes(true); } else if (args[i].equalsIgnoreCase("-writebeangraph")) { config.setWriteBeanGraphFile(new File(args[++i])); } else if (args[i].equalsIgnoreCase("-readbeangraph")) { config.addReadBeanGraphFiles(new File(args[++i])); } else if (args[i].equalsIgnoreCase("-gendotgraph")) { config.setGenerateDotGraph(new File(args[++i])); } else if (args[i].equalsIgnoreCase("-delegatedir")) { config.setDelegateDir(new File(args[++i])); } else if (args[i].equalsIgnoreCase("-delegatepackage")) { config.setDelegatePackage(args[++i]); } else if (args[i].equalsIgnoreCase("-checkuptodate")) { config.setCheckUpToDate(true); } else if (args[i].equalsIgnoreCase("-haschanged")) { config.setGenerateHasChanged(true); } else if (args[i].equalsIgnoreCase("-generateSwitches")) { config.setGenerateSwitches(true); } else if (args[i].equalsIgnoreCase("-min")) { config.setMinFeatures(true); } else if (args[i].equalsIgnoreCase("-forme")) { config.setForME(true); } else if (args[i].equalsIgnoreCase("-tagsfile")) { config.setGenerateTagsFile(true); } else if (args[i].equalsIgnoreCase("-help") || args[i].equalsIgnoreCase("--help")) { help = 0; } else { System.out.println("Unknown argument: "+args[i]); System.out.println("Use -help."); System.exit(1); } } } catch (Exception e) { help = 0; } if (help < 1) { System.out.println("usage:"); System.out.println("java "+GenBeans.class.getName()+" -f filename [-d docRoot] [-t] [-p package] [-r rootDir] \n\t[-sp number] [-mdd filename] [-noe] [-ts] [-veto] [-version]\n\t[-st] [-throw] [-dtd|-xmlschema] [-javabeans] [-validate]\n\t[-propertyevents] [-attrprop] [-delegator] [-commonInterface] [-commonInterfaceName name]\n\t[-premium] [-compile] [-defaultsAccessable] [-auto]\n\t[-useinterfaces] [-geninterfaces] [-keepelementpositions]\n\t[-dumpbeantree filename] [-removeUnreferencedNodes]\n\t[-genDotGraph filename] [-comments] [-checkUpToDate]\n\t[-writeBeanGraph filename] [-readBeanGraph filename]*\n\t[-hasChanged] [-min] [-forME] [-tagsFile]\n"); System.out.println("where:"); System.out.println(" -f file name of the DTD"); System.out.println(" -d DTD root element name (for example webapp or ejb-jar)"); System.out.println(" -p package name"); System.out.println(" -r base root directory (root of the package path)"); System.out.println(" -sp set the indentation to use 'number' spaces instead of \n the default tab (\ ) value"); System.out.println(" -mdd provides extra information that the dtd cannot provide. \n If the file doesn't exist, a skeleton file is created and \n no bean generation happens."); System.out.println(" -noe do not throw the NoSuchElement exception when a scalar property\n has no value, return a default '0' value instead."); System.out.println(" -ts the toString() of the bean returns the full content\n of the bean sub-tree instead of its simple name."); System.out.println(" -veto generate vetoable properties (only for non-bean properties)."); System.out.println(" -st standalone mode - do not generate NetBeans dependencies"); System.out.println(" -throw generate code that prefers to pass exceptions\n through instead of converting them to RuntimeException (recommended)."); System.out.println(" -dtd DTD input mode (default)"); System.out.println(" -xmlschema XML Schema input mode"); System.out.println(" -javabeans Generate pure JavaBeans that do not need\n any runtime library support (no BaseBean)."); System.out.println(" -validate Generate a validate method for doing validation."); System.out.println(" -propertyevents Generate methods for dealing with property events (always on for BaseBean type)."); System.out.println(" -attrprop Attributes become like any other property"); System.out.println(" -delegator Generate a delegator class for every bean generated."); System.out.println(" -commonInterface Generate a common interface between all beans."); System.out.println(" -commonInterfaceName Name the common interface."); System.out.println(" -premium The \"Premium\" Package. Turn on what ought to be the default switches (but can't be the default due to backwards compatibility)."); System.out.println(" -min Generate the minimum Java Beans. Reduce features in favor of reduced class file size."); System.out.println(" -compile Compile all generated classes using javac."); System.out.println(" -defaultsAccessable Generate methods to be able to get at default values."); System.out.println(" -useInterfaces Getters and setters signatures would any defined interface on the bean."); System.out.println(" -genInterfaces For every bean generated, generate an interfaces for it's accessors."); System.out.println(" -keepElementPositions Keep track of the positions of elements (no BaseBean support)."); System.out.println(" -dumpBeanTree filename Write out the bean tree to filename."); System.out.println(" -removeUnreferencedNodes Do not generate unreferenced nodes from the bean graph."); System.out.println(" -writeBeanGraph Write out a beangraph XML file. Useful for connecting separate bean graphs."); System.out.println(" -readBeanGraph Read in and use the results of another bean graph."); System.out.println(" -genDotGraph filename Generate a .dot style file for use with GraphViz."); System.out.println(" -comments Process and keep comments (always on for BaseBean type)."); System.out.println(" -doctype Process and keep Document Types (always on for BaseBean type)."); System.out.println(" -hasChanged Generate code to keep track if the bean graph has changed."); System.out.println(" -checkUpToDate Only do generation if the source files are newer than the to be generated files."); System.out.println(" -forME Generate code for use on J2ME."); System.out.println(" -tagsFile Generate a class that has all schema element & attribute names"); System.out.println(" -t [parse|gen|all]\ttracing."); System.out.println("\n\nThe bean classes are generated in the directory rootDir/packagePath, where packagePath is built using the package name specified. If the package name is not specified, the doc root element value is used as the default package name. Use the empty string to get no (default) package."); System.out.println("\nexamples: java GenBeans -f ejb.dtd"); System.out.println(" java GenBeans -f webapp.dtd -d webapp -p myproject.webapp -r /myPath/src"); System.out.println(" java GenBeans -f webapp.xsd -xmlschema -r /myPath/src -premium"); System.out.println("\nMost of the parameters are optional. Only the file name is mandatory."); System.out.println("With only the file name specified, the generator uses the current directory, and uses the schema docroot value as the package name."); } else*/ DDLogFlags.debug = config.isTrace(); try { doIt(config); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
public DocDefParser(GenBeans.Config config, DocDefHandler handler) { this.config = config; this.filename = config.getFilename(); this.schemaIn = config.getFileIn(); this.handler = handler; }