Packages

  • package root

    org.apache.daffodil.sapi - Provides the classes necessary to compile DFDL schemas, parse and unparse files using the compiled objects, and retrieve results and parsing diagnostics

    Apache Daffodil (incubating) Scala API

    Packages

    org.apache.daffodil.sapi - Provides the classes necessary to compile DFDL schemas, parse and unparse files using the compiled objects, and retrieve results and parsing diagnostics

    org.apache.daffodil.sapi.logger - Provides the classes necessary to receive logging messages from Daffodil.

    org.apache.daffodil.sapi.debugger - Provides the classes necessary to perform parse tracing or create a custom debugger

    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package apache
    Definition Classes
    org
  • package daffodil
    Definition Classes
    apache
  • package sapi

    Provides the classes necessary to compile DFDL schemas, parse and unparse files using the compiled objects, and retrieve results and parsing diagnostics

    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:

    val c = Daffodil.compiler()
    val pf = c.compileFile(file)
    val dp = pf.onPath("/")

    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 method accepts input data to parse in the form of a InputSourceDataInputStream and an InfosetOutputter to determine the output representation of the infoset (e.g. Scala XML Nodes, JDOM2 Documents, etc.):

    val scalaOutputter = new ScalaXMLInfosetOutputter()
    val is = new InputSourceDataInputStream(data)
    val pr = dp.parse(is, scalaOutputter)
    val node = scalaOutputter.getResult

    The DataProcessor.parse method is thread-safe and may be called multiple times without the need to create other data processors. However, InfosetOutputter's are not thread safe, requiring a unique instance per thread. An InfosetOutputter should call InfosetOutputter.reset before reuse (or a new one should be allocated). For example:

    val scalaOutputter = new ScalaXMLInfosetOutputter()
    files.foreach { f => {
      outputter.reset
      val is = new InputSourceDataInputStream(new FileInputStream(f))
      val pr = dp.parse(is, scalaOutputter)
      val node = scalaOutputter.getResult
    }

    One can repeat calls to parse() using the same InputSourceDataInputStream to continue parsing where the previous parse ended. For example:

    val is = new InputSourceDataInputStream(dataStream)
    val scalaOutputter = new ScalaXMLInfosetOutputter()
    val keepParsing = true
    while (keepParsing) {
      scalaOutputter.reset()
      val pr = dp.parse(is, jdomOutputter)
      ...
      keepParsing = !pr.location().isAtEnd() && !pr.isError()
    }
    Unparse

    The same DataProcessor used for parse can be used to unparse an infoset via the DataProcessor.unparse method. An InfosetInputter provides the infoset to unparse, with the unparsed data written to the provided java.nio.channels.WritableByteChannel. For example:

    val inputter = new ScalaXMLInfosetInputter(node)
    val ur = dp.unparse(inputter, wbc)
    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:

    val pf = c.compile(file)
    if (pf.isError()) {
      val diags = pf.getDiagnostics()
      diags.foreach { d =>
        System.out.println(d.toString())
      }
      return -1;
    }
    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:

    val dp = pf.onPath("/")
    dp.save(saveFile);

    And to restore a saved DataProcessor:

    val dp = Daffodil.reload(saveFile);
    val pr = dp.parse(data, inputter);
    Definition Classes
    daffodil
  • package debugger

    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

    Overview

    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);
    Definition Classes
    sapi
  • package infoset

    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 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 method to determine how to read in an infoset. A new InfosetOutputter is required for each call to unparse().

    Definition Classes
    sapi
  • InfosetInputter
  • InfosetInputterProxy
  • InfosetOutputter
  • InfosetOutputterProxy
  • JDOMInfosetInputter
  • JDOMInfosetOutputter
  • JsonInfosetInputter
  • JsonInfosetOutputter
  • NullInfosetOutputter
  • ScalaXMLInfosetInputter
  • ScalaXMLInfosetOutputter
  • W3CDOMInfosetInputter
  • W3CDOMInfosetOutputter
  • XMLTextInfosetInputter
  • XMLTextInfosetOutputter
  • package io
    Definition Classes
    sapi
  • package logger

    Provides the classes necessary to receive logging messages from Daffodil.

    Provides the classes necessary to receive logging messages from Daffodil.

    Overview

    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);
    Definition Classes
    sapi

package infoset

Defines various classes used control the representation of the infoset for parse and unparse. Classes that extend InfosetOutputter are provided to the DataProcessor.parse 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 method to determine how to read in an infoset. A new InfosetOutputter is required for each call to unparse().

Linear Supertypes
AnyRef, Any

Type Members

  1. abstract class InfosetInputter extends infoset.InfosetInputter

    Abstract class used to determine how the infoset representation should be input from a call to DataProcessor.unparse.

    Abstract class used to determine how the infoset representation should be input from a call to DataProcessor.unparse. This uses a Cursor API, such that each call to advance/inspect must update a cursor value, minimizing allocations. Callers of advance/inspect are expected to copy out any information from advanceAccessor and inspectAccessor if they need to retain the information after a call to advance/inspect.

  2. abstract class InfosetInputterProxy extends InfosetInputter
  3. abstract class InfosetOutputter extends infoset.InfosetOutputter

    Abstract class used to determine how the infoset representation should be output from a call to DataProcessor.parse.

    Abstract class used to determine how the infoset representation should be output from a call to DataProcessor.parse. The Daffodil core will call the various methods of this class in an order appropriate to create an infoset representation.

    Classes that extend InfosetOutputter are not guaranteed to be thread-safe.

  4. abstract class InfosetOutputterProxy extends InfosetOutputter
  5. class JDOMInfosetInputter extends InfosetInputterProxy

    Read in an infoset in the form of a jdom2 Document

  6. class JDOMInfosetOutputter extends InfosetOutputterProxy

    Output the infoset as a jdom Document

  7. class JsonInfosetInputter extends InfosetInputterProxy

    Read in an infoset in the form of json text from a java.io.Reader

  8. class JsonInfosetOutputter extends InfosetOutputterProxy

    Output the infoset as json text, written to a java.io.Writer

  9. class NullInfosetOutputter extends InfosetOutputterProxy

    Ignore all infoset output

  10. class ScalaXMLInfosetInputter extends InfosetInputterProxy

    Read in an infoset in the form of a scala.xml.Node

  11. class ScalaXMLInfosetOutputter extends InfosetOutputterProxy

    Output the infoset as a scala.xml.Node

  12. class W3CDOMInfosetInputter extends InfosetInputterProxy

    Read in an infoset in the form of a w3c Document

  13. class W3CDOMInfosetOutputter extends InfosetOutputterProxy

    Output the infoset as a w3c Document

  14. class XMLTextInfosetInputter extends InfosetInputterProxy

    Read in an infoset in the form of XML text from a java.io.Reader

  15. class XMLTextInfosetOutputter extends InfosetOutputterProxy

    Output the infoset as XML Text, written to a java.io.Writer

Inherited from AnyRef

Inherited from Any

Ungrouped