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 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
  • ConsoleLogWriter
  • FileLogWriter
  • LogLevel
  • LogWriter
  • NullLogWriter

object LogLevel extends Enumeration

Logging levels.

Error, Warning, and Info are intended for general use. The default is Info.

Levels Resolver Compile, Debug, and OOLAGDebug are intended for Daffodil developer use.

Linear Supertypes
Enumeration, Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. LogLevel
  2. Enumeration
  3. Serializable
  4. Serializable
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. type LogLevel = Value
  2. class Val extends Value with Serializable
    Attributes
    protected
    Definition Classes
    Enumeration
    Annotations
    @SerialVersionUID()
  3. abstract class Value extends Ordered[Value] with Serializable
    Definition Classes
    Enumeration
    Annotations
    @SerialVersionUID()
  4. class ValueSet extends AbstractSet[Value] with SortedSet[Value] with SortedSetLike[Value, ValueSet] with Serializable
    Definition Classes
    Enumeration

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. val Compile: Value
  5. val Debug: Value
  6. val DelimDebug: Value
  7. val Error: Value
  8. val Info: Value
  9. val OOLAGDebug: Value
  10. val Resolver: Value
  11. final def Value(i: Int, name: String): Value
    Attributes
    protected
    Definition Classes
    Enumeration
  12. final def Value(name: String): Value
    Attributes
    protected
    Definition Classes
    Enumeration
  13. final def Value(i: Int): Value
    Attributes
    protected
    Definition Classes
    Enumeration
  14. final def Value: Value
    Attributes
    protected
    Definition Classes
    Enumeration
  15. val Warning: Value
  16. final def apply(x: Int): Value
    Definition Classes
    Enumeration
  17. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  18. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  19. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  21. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  22. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  23. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  24. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  25. final def maxId: Int
    Definition Classes
    Enumeration
  26. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  27. var nextId: Int
    Attributes
    protected
    Definition Classes
    Enumeration
  28. var nextName: Iterator[String]
    Attributes
    protected
    Definition Classes
    Enumeration
  29. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  30. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  31. def readResolve(): AnyRef
    Attributes
    protected
    Definition Classes
    Enumeration
  32. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  33. def toString(): String
    Definition Classes
    Enumeration → AnyRef → Any
  34. def values: ValueSet
    Definition Classes
    Enumeration
  35. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  36. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  37. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  38. final def withName(s: String): Value
    Definition Classes
    Enumeration

Inherited from Enumeration

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped