/** * Parses whole file of DAVE-ML markup. * * <p>This method will take the supplied DAVE xml file, and convert that file into lists of {@link * Signal} and {@link Block}, as well as {@link BreakpointSet} and {@link FuncTable} objects. * * <p>The procedure is to locate and create objects for each type of DAVE-ML element, in sequence: * * <ul> * <li><code><variableDef></code>s * <li><code><breakpointDef></code>s * <li><code><griddedTableDef></code>s * <li><code><function></code>s * </ul> * * <p>An interesting quirk about building a model: the <code><function></code> elements * specify a table, one or more breakpoint sets, and the independent variable to be normalized * with the particular breakpoint set(s). Thus, only when the function definition is read and * parsed can we construct breakpoint blocks ({@link BlockBP}s). So, the function table parsing * routine ( <code>new</code> {@link BlockFuncTable}) has to do a lot of <code>BlockBP</code> * creation and wiring of {@link Signal}s That's why creation of <code>BlockBPs</code> is deferred * until creation of <code>BlockFuncTable</code>s. * * @throws <code>IOException</code> - when errors occur. */ public boolean parseFile() throws IOException { // Get DAVE XML file's location (in a file: URL) File f = new File(this.inputFileName); String fullURI = f.toURI().toString(); this.base_uri = fullURI; // have to keep file name as part of base // Dig out model name from file name this.m.setName(this.stubName); // Hack the start time this.parseStartTime = System.currentTimeMillis(); // Build XML tree Document doc = load(); root = doc.getRootElement(); // See if there is a default namespace this.ns = root.getNamespace(); if (this.isVerbose()) { System.out.println("Root element has '" + this.ns.getURI() + "' default namespace."); } // Parse into signals and blocks -- // Find our Signals; create a Signal for each VariableDef // found parseVariableDefs(); // Record breakpoint sets by creating a BreakpointSet for // every BreakpointDef found parseBreakpointDefs(); // Record tables parseTableDefs(); // Create lookup functions and associated breakpoint blocks; // tie breakpoints & tables together into functions. parseFunctions(); // Hook all the blocks together // loop through model, telling each block to wire up its inputs and outputs to predefined // signals. m.wireBlocks(); // Create input & output blocks m.hookUpIO(); // Load checkcase data (if any) parseCheckCases(); // Hit the stopwatch again this.parseStopTime = System.currentTimeMillis(); // Sanity check boolean result = m.verifyIntegrity(); // Initialize model // This builds the exection order lists; was happening only for models with checkcases try { m.initialize(); } catch (DAVEException ex) { Logger.getLogger(DAVE.class.getName()).log(Level.SEVERE, null, ex); } // report results if (this.isVerbose()) { System.out.println(""); System.out.println("File parsing complete; model built."); System.out.println("==================================="); System.out.println(""); } return result; }