Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,29 @@ import java.nio.file.Path
import org.apache.daffodil.sapi._
import org.apache.daffodil.sapi.io.InputSourceDataInputStream
import org.apache.daffodil.sapi.infoset.{JsonInfosetOutputter, XMLTextInfosetOutputter}
import cats.effect.IO
import cats.syntax.all._

object Support {
/* Daffodil DataProcessor wrapper methods */
def dataProcessorWithDebugger(
p: DataProcessor,
debugger: org.apache.daffodil.runtime1.debugger.Debugger,
variables: Map[String, String]
): DataProcessor =
p.withDebugger(debugger)
.withDebugging(true)
.withExternalVariables(variables)
.withValidationMode(ValidationMode.Limited)
): IO[DataProcessor] = {
val base = p.withDebugger(debugger).withDebugging(true)

variables.toList
.foldLeftM(base) { case (dp, (k, v)) =>
IO(dp.withExternalVariables(Map(k -> v))).handleErrorWith {
case e: ExternalVariableException =>
IO.println(s"[WARNING] Skipping unknown external variable '$k': ${e.getMessage}") *>
IO.pure(dp)
case e => IO.raiseError(e)
}
}
.map(_.withValidationMode(ValidationMode.Limited))
}

/* Daffodil infoset wrapper methods */
def getInputSourceDataInputStream(data: InputStream): InputSourceDataInputStream = new InputSourceDataInputStream(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,30 @@ import java.io._
import java.nio.file.Path
import org.apache.daffodil.api._
import scala.jdk.CollectionConverters._
import cats.effect.IO
import cats.syntax.all._
import org.apache.daffodil.api.exceptions.ExternalVariableException

object Support {
/* Daffodil DataProcessor wrapper methods */
def dataProcessorWithDebugger(p: DataProcessor, debugger: Debugger, variables: Map[String, String]): DataProcessor =
p.withDebugger(debugger)
.withExternalVariables(variables.asJava)
.withValidation("daffodil")
def dataProcessorWithDebugger(
p: DataProcessor,
debugger: Debugger,
variables: Map[String, String]
): IO[DataProcessor] = {
val base = p.withDebugger(debugger)

/* Daffodil infoset wrapper methods */
def getInputSourceDataInputStream(data: InputStream): InputSourceDataInputStream =
Daffodil.newInputSourceDataInputStream(data)
def getInfosetOutputter(infosetFormat: String, stream: OutputStream): InfosetOutputter =
infosetFormat match {
case "xml" => Daffodil.newXMLTextInfosetOutputter(stream, true)
case "json" => Daffodil.newJsonInfosetOutputter(stream, true)
case other => throw new IllegalArgumentException(s"unsupported infosetFormat: $other")
}
variables.toList
.foldLeftM(base) { case (dp, (k, v)) =>
IO(dp.withExternalVariables(Map(k -> v).asJava)).handleErrorWith {
case e: ExternalVariableException =>
IO.println(s"[WARNING] Skipping unknown external variable '$k': ${e.getMessage}") *>
IO.pure(dp)
case e => IO.raiseError(e)
}
}
.map(_.withValidation("daffodil"))
}

/* Daffodil ProcessorFactory wrapper methods */
def getProcessorFactory(
Expand All @@ -56,9 +63,21 @@ object Support {
.withTunables(tunables.asJava)
.compileFile(schema.toFile(), rootName.orNull, rootNamespace.orNull)

/* Method to convert java list of diagnostics to a sequence of diagnostics */
/* Method to convert java list of diagnostics to a sequence of diagnostics */
def parseDiagnosticList(
dl: java.util.List[org.apache.daffodil.api.Diagnostic]
): Seq[org.apache.daffodil.api.Diagnostic] =
dl.asScala.toSeq

/* Daffodil infoset wrapper methods */
def getInputSourceDataInputStream(data: InputStream): InputSourceDataInputStream =
Daffodil.newInputSourceDataInputStream(data)

def getInfosetOutputter(infosetFormat: String, stream: OutputStream): InfosetOutputter =
infosetFormat match {
case "xml" => Daffodil.newXMLTextInfosetOutputter(stream, true)
case "json" => Daffodil.newJsonInfosetOutputter(stream, true)
case other => throw new IllegalArgumentException(s"unsupported infosetFormat: $other")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ object Parse {
for {
dp <- DAPCompiler()
.compile(schema, rootName, rootNamespace, tunables)
.map(p => Support.dataProcessorWithDebugger(p, debugger, variables))
.flatMap(p => Support.dataProcessorWithDebugger(p, debugger, variables))
done <- Ref[IO].of(false)
pleaseStop <- Deferred[IO, Unit]
} yield new Parse {
Expand Down
Loading