Skip to content

Commit

Permalink
Remove last remnants of deprecated API
Browse files Browse the repository at this point in the history
Scrub constructor parameters and scaladocs of all remnants of the
deprecated API removed by previous DAFFODIL-2743 commits.  Remove 2nd
DataProcessor constructor; always call 1st constructor instead.  Also
replace all calls/definitions of DataProcessor's getTunables() with
tunables.  Make saving and reloading a DataProcessor reset both
variableMap and validationMode.  Fix some IDEA nits and formatting.

SchemaSet.scala: Scrub deprecated API from SchemaSet.root's scaladocs.
Fix some IDEA nits in root's code block.

SchemaSetRuntime1Mixin.scala: Make onPath call 1st DataProcessor
constructor instead of 2nd constructor.

TestTunables.scala, TestInfosetCursor.scala, TestInfosetCursor1.scala,
TestInfosetCursorFromReader.scala, TestInfosetCursorFromReader2.scala,
TestUtils.scala, DFDLParserUnparser.scala,
DaffodilUnparseContentHandler.scala, DataProcessor.scala,
PState.scala, UState.scala, Runtime2DataProcessor.scala:
- Replace getTunables() with tunables.

DataProcessor.scala: Remove externalVars from constructor parameters
and scaladocs since we no longer pass in compiler-set external
variable bindings.  Make SerializableDataProcessor's 4 fields same as
DataProcessor's first 4 fields, including variableMap to keep
preserving variables' mappings.  Make SerializableDataProcessor extend
1st DataProcessor constructor instead of 2nd constructor.  Format
constructors and a few methods according to Scala code style for
declarations (https://docs.scala-lang.org/style/declarations.html)
including trailing commas and closing parentheses to provide visual
separation between function arguments and extensions or body block.
Make 1st DataProcessor constructor public, reorder its parameters, and
make its last 2 parameters optional.  Make writeReplace save
variableMap instead of externalVars.  Delete 2nd DataProcessor
constructor since we no longer pass in compiler-set externalVars.
Reorder copy's parameters and make it call 1st constructor instead of
2nd constructor.  Remove loadExternalVariables and modify
withExternalVariables to get rid of externalVars.  Make save reset
variableMap as well as validationMode to original values.

Runtime2DataProcessor.scala: Put coverage off/on around unimplemented
methods.

DAFFODIL-2743
  • Loading branch information
tuxji committed Dec 9, 2022
1 parent debf1d4 commit a06714e
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,9 @@ final class SchemaSet private (
}

/**
* The root element can be specified by a deprecated API call on the compiler
* object or the ProcessorFactory class, but the call on the ProcessorFactory class
* just overrides anything coming from the compiler object.
* You can define the root by passing the root specification to the Compiler.compileX method.
*
* The right way is to pass the root specification to the Compiler.compileX method.
*
* Or, you can leave it unspecified, and this method will determine from the
* Or, you can leave the root unspecified, and this method will determine it from the
* first element declaration of the first schema file.
*/
lazy val root: Root = {
Expand All @@ -360,12 +356,12 @@ final class SchemaSet private (
// if the root element and rootNamespace aren't provided at all, then
// the first element of the first schema document is the root
val sDocs = this.allSchemaDocuments
assuming(sDocs.length > 0)
val firstSchemaDocument = sDocs(0)
assuming(sDocs.nonEmpty)
val firstSchemaDocument = sDocs.head
val gdecl = firstSchemaDocument.globalElementDecls
val firstElement = {
schemaDefinitionUnless(gdecl.length >= 1, "No global elements in: " + firstSchemaDocument.uriString)
gdecl(0)
schemaDefinitionUnless(gdecl.nonEmpty, "No global elements in: " + firstSchemaDocument.uriString)
gdecl.head
}
firstElement
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.daffodil.runtime1

import org.apache.daffodil.api.DFDL
import org.apache.daffodil.api.ValidationMode
import org.apache.daffodil.dsom.SchemaSet
import org.apache.daffodil.exceptions.Assert
import org.apache.daffodil.grammar.VariableMapFactory
Expand Down Expand Up @@ -75,7 +74,6 @@ trait SchemaSetRuntime1Mixin {
root.schemaDefinitionUnless(
!rootERD.dpathElementCompileInfo.isOutputValueCalc,
"The root element cannot have the dfdl:outputValueCalc property.")
val validationMode = ValidationMode.Off
val p = if (!root.isError) parser else null
val u = if (!root.isError) unparser else null
val ssrd = new SchemaSetRuntimeData(
Expand All @@ -87,7 +85,7 @@ trait SchemaSetRuntime1Mixin {
typeCalcMap)
if (root.numComponents > root.numUniqueComponents)
Logger.log.debug(s"Compiler: component counts: unique ${root.numUniqueComponents}, actual ${root.numComponents}.")
val dataProc = new DataProcessor(ssrd, tunable)
val dataProc = new DataProcessor(ssrd, tunable, variableMap.copy())
if (dataProc.isError) {
} else {
Logger.log.debug(s"Parser = ${ssrd.parser.toString}.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ class TestTunables {
val dp1 = pf1.onPath("/")
var dp2 = pf2.onPath("/")

val t1 = dp1.getTunables()
val t2 = dp2.getTunables()
val t1 = dp1.tunables
val t2 = dp2.tunables

/* Set tunable at run-time via data processor */
dp2 = dp2.withTunable("maxSkipLengthInBytes", "50")

val t3 = dp2.getTunables() // modified tunables at 'run-time'
val t4 = dp1.getTunables() // obtain first data processor to see if anything changed
val t3 = dp2.tunables // modified tunables at 'run-time'
val t4 = dp1.tunables // obtain first data processor to see if anything changed

assertEquals(1026, t1.maxSkipLengthInBytes) // initial compiler-set value
assertEquals(2048, t2.maxSkipLengthInBytes) // overwrite of compiler-set value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.apache.daffodil.processors.DataProcessor
import org.apache.daffodil.compiler.Compiler
import org.apache.daffodil.processors.SequenceRuntimeData
import org.apache.daffodil.processors.ChoiceRuntimeData

import InfosetEventKind._
import org.apache.daffodil.processors.ElementRuntimeData

Expand Down Expand Up @@ -91,7 +90,7 @@ class TestInfosetInputter {
}
val rootERD = u.ssrd.elementRuntimeData
val infosetInputter = new ScalaXMLInfosetInputter(infosetXML)
infosetInputter.initialize(rootERD, u.getTunables())
infosetInputter.initialize(rootERD, u.tunables)
(infosetInputter, rootERD)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TestInfosetInputter1 {
}
val rootERD = u.ssrd.elementRuntimeData
val ic = new XMLTextInfosetInputter(is)
ic.initialize(rootERD, u.getTunables())
ic.initialize(rootERD, u.tunables)
ic
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class TestInfosetInputterFromReader {
}
val rootERD = u.ssrd.elementRuntimeData
val inputter = new ScalaXMLInfosetInputter(infosetXML)
inputter.initialize(rootERD, u.getTunables())
inputter.initialize(rootERD, u.tunables)
val is = Adapter(inputter)
(is, rootERD, inputter, u.tunables)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TestInfosetInputterFromReader2 {

val is = new StreamInputStream(strings)
val inputter = new XMLTextInfosetInputter(is)
inputter.initialize(rootERD, u.getTunables())
inputter.initialize(rootERD, u.tunables)
val ic = Adapter(inputter)
(ic, rootERD, inputter)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,16 @@ class Fakes private () {
lazy val fakeGroupRefFactory = GroupRefFactory(fs1.xml, fs1, 1, false)

class FakeDataProcessor extends DFDL.DataProcessor {
def getValidationMode(): ValidationMode.Type = { ValidationMode.Full }
override def save(output: DFDL.Output): Unit = {}
def getVariables(): VariableMap = VariableMapFactory.create(Nil)
override def parse(input: InputSourceDataInputStream, output: InfosetOutputter): DFDL.ParseResult = null
override def unparse(inputter: InfosetInputter, output: DFDL.Output): DFDL.UnparseResult = null
override def getDiagnostics: Seq[Diagnostic] = Seq.empty
override def isError: Boolean = false
override def getTunables(): DaffodilTunables = { tunables }

override def validationMode: ValidationMode.Type = ValidationMode.Full
override def tunables: DaffodilTunables = DaffodilTunables()
override def variableMap: VariableMap = VariableMapFactory.create(Nil)
override def validationMode: ValidationMode.Type = ValidationMode.Full

override def withExternalVariables(extVars: Seq[Binding]): DFDL.DataProcessor = this
override def withExternalVariables(extVars: java.io.File): DFDL.DataProcessor = this
override def withExternalVariables(extVars: Map[String,String]): DFDL.DataProcessor = this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ object DFDL {
def withDebugger(dbg:AnyRef): DataProcessor
def withDebugging(flag: Boolean): DataProcessor

def validationMode: ValidationMode.Type

def getTunables(): DaffodilTunables
def save(output: DFDL.Output): Unit

def tunables: DaffodilTunables
def variableMap: VariableMap
def validationMode: ValidationMode.Type
}

trait DataProcessor extends DataProcessorBase with WithDiagnostics {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class DaffodilUnparseContentHandler(
private var prefixMapping: NamespaceBinding = _
private lazy val prefixMappingTrackingStack = new MStackOf[NamespaceBinding]

private lazy val tunablesBatchSize = dp.getTunables().saxUnparseEventBatchSize
private lazy val tunablesBatchSize = dp.tunables.saxUnparseEventBatchSize

/**
* we always have an extra buffer in the array that we use for the inputter.hasNext call. For each
Expand Down
Loading

0 comments on commit a06714e

Please sign in to comment.