Compile DFDL schemas into ProcessorFactory's or reload saved parsers into DataProcessor's.
Information related to a location in data
Compiled version of a DFDL Schema, used to parse data and get the DFDL infoset
Class containing diagnostic information
This exception will be thrown as a result of attempting to reload a saved parser that is invalid (not a parser file, corrupt, etc.) or is not in the GZIP format.
This exception will be thrown as a result of an invalid usage of the Daffodil API
Information related to locations in DFDL schema files
Result of calling DataProcessor#parse(input:java\.nio\.channels\.ReadableByteChannel,output:edu\.illinois\.ncsa\.daffodil\.sapi\.infoset\.InfosetOutputter)*, containing any diagnostic information, and the final data location
Factory to create DataProcessor's, used for parsing data
Result of calling DataProcessor#unparse(input*, containing diagnostic information
Abstract class that adds diagnostic information to classes that extend it.
Abstract class that adds diagnostic information to classes that extend it.
When a function returns a class that extend this, one should call WithDiagnostics#isError on that class before performing any further actions. If an error exists, any use of that class, aside from those functions in WithDiagnostics, is invalid and will result in an Exception.
Factory object to create a Compiler and set global configurations
Validation modes for validating the resulting infoset against the DFDL schema
Provides the classes necessary to perform parse tracing or create a custom debugger
Provides the classes necessary to perform parse tracing or create a custom debugger
Daffodil comes with one prebuilt debugger, the TraceDebuggerRunner, which outputs verbose information during the parsing processes, which can be used to aid in debugging a DFDL schema. For example, the TraceDebuggerRunner can be use like so:
val tdr = new TraceDebuggerRunner() Daffodil.setDebugger(tdr)
Additionally, one may create their own debugger runner by implementing the methods in the DebuggerRunner.
Once the debugger is set, it must then be turned on, like so:
Daffodil.setDebugging(true);
Defines various classes used control the representation of the infoset for parse and unparse.
Defines various classes used control the representation of the infoset for parse and unparse. Classes that extend InfosetOutputter are provided to the DataProcessor#parse(input:java\.nio\.channels\.ReadableByteChannel,output:edu\.illinois\.ncsa\.daffodil\.sapi\.infoset\.InfosetOutputter)* method to deteremine how to output an infoset. These classes are not guaranteed to be thread-safe. Classes that extend InfosetInputter are provided to the DataProcessor#unparse(input* method to determine how to read in an infoset. A new InfosetOutputter is required for each call to unparse().
Provides the classes necessary to recieve logging messages from Daffodil.
Provides the classes necessary to recieve logging messages from Daffodil.
Daffodil comes with three prebuilt log writers:
To use one of these log writers, create and instance of it and pass it to
Daffodil.setLogWriter. For example, to write all logs to /var/log/daffodil.log
:
val lw = new FileLogWriter(new File("/var/log/daffodil.log")) Daffodil.setLogWriter(lw)
One may also change the log level using Daffodil.setLoggingLevel, which defaults to LogLevel#Info if not set. For example, to change the log level to LogLevel#Warning:
Daffodil.setLoggingLevel(LogLevel.Warning);
Provides the classes necessary to compile DFDL schemas, parse and unparse files using the compiled objects, and retrieve results and parsing diagnostics
Overview
The Daffodil object is a factory object to create a Compiler. The Compiler provides a method to compils a provided DFDL schema into a ProcessorFactory, which creates a DataProcessor:
The DataProcessor provides the necessary functions to parse and unparse data, returning a ParseResult or UnparseResult, respectively. These contain information about the parse/unparse, such as whether or not the processing succeeded any diagnostic information.
Parse
The DataProcessor#parse(input:java\.nio\.channels\.ReadableByteChannel,output:edu\.illinois\.ncsa\.daffodil\.sapi\.infoset\.InfosetOutputter)* method accepts input data to parse in the form of a java.nio.channels.ReadableByteChannel and an infoset.InfosetOutputter to determine the output representation of the infoset (e.g. Scala XML Nodes, JDOM2 Documents, etc.):
The DataProcessor#parse(input:java\.nio\.channels\.ReadableByteChannel,output:edu\.illinois\.ncsa\.daffodil\.sapi\.infoset\.InfosetOutputter)* method is thread-safe and may be called multiple times without the need to create other data processors. However, infoset.InfosetOutputter's are not thread safe, requiring a unique instance per thread. An infoset.InfosetOutputter should call infoset.InfosetOutputter#reset before reuse (or a new one should be allocated). For example:
Unparse
The same DataProcessor used for parse can be used to unparse an infoset via the DataProcessor#unparse(input* method. An infoset.InfosetInputter provides the infoset to unparse, with the unparsed data written to the provided java.nio.channels.WritableByteChannel. For example:
Failures and Diagnostics
It is possible that failures could occur during the creation of the ProcessorFactory, DataProcessor, or ParseResult. However, rather than throwing an exception on error (e.g. invalid DFDL schema, parse error, etc), these classes extend WithDiagnostics, which is used to determine if an error occurred, and any diagnostic information (see Diagnostic) related to the step. Thus, before continuing, one must check WithDiagnostics#isError. For example:
Saving and Reloading Parsers
In some cases, it may be beneficial to save a parser and reload it. For example, when starting up, it may be quicker to reload an already compiled parser than to compile it from scratch. To save a DataProcessor:
And to restore a saved DataProcessor: