stevedlawrence commented on a change in pull request #343: Daffodil 2302 fixes
external variables API difficulties
URL: https://github.com/apache/incubator-daffodil/pull/343#discussion_r400881006
##########
File path:
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/DataProcessor.scala
##########
@@ -114,70 +147,126 @@ class DataProcessor(
// not configure the size of the regex match buffers.
@transient lazy val regexMatchState = new ThreadLocal[(CharBuffer,
LongBuffer)] {
override def initialValue = {
- val cb =
CharBuffer.allocate(tunablesObj.maximumRegexMatchLengthInCharacters)
- val lb =
LongBuffer.allocate(tunablesObj.maximumRegexMatchLengthInCharacters)
+ val cb =
CharBuffer.allocate(tunables.maximumRegexMatchLengthInCharacters)
+ val lb =
LongBuffer.allocate(tunables.maximumRegexMatchLengthInCharacters)
(cb, lb)
}
}
- def setValidationMode(mode: ValidationMode.Type): Unit = {
ssrd.validationMode = mode }
- def getValidationMode() = ssrd.validationMode
- def getVariables = ssrd.variables
- def getTunables = tunablesObj
-
- @transient private var areDebugging_ = false
+ /**
+ * Returns a data processor with the same state.
+ */
+ override def clone(): DataProcessor = copy()
- def areDebugging = areDebugging_
+ /**
+ * Returns a data processor with all the same state, but the validation mode
changed to that of the argument.
+ *
+ * Note that the default validation mode is "off", that is, no validation is
performed.
+ */
+ @deprecated("Use withValidationMode.", "Since 2.6.0")
+ def setValidationMode(mode: ValidationMode.Type): Unit = { validationMode =
mode }
- @transient private var optDebugger_ : Option[Debugger] = None
+ def withValidationMode(mode:ValidationMode.Type): DataProcessor =
copy(validationMode = mode)
- private def optDebugger = {
- if (optDebugger_ == null) {
- // transient value restored as null
- optDebugger_ = None
- }
- optDebugger_
- }
+ // TODO Deprecate and replace usages with just tunables.
+ def getTunables: DaffodilTunables = tunables
def debugger = {
Assert.invariant(areDebugging)
optDebugger.get
}
+ @deprecated("Use withDebugger.", "Since 2.6.0")
def setDebugger(dbg: AnyRef) {
- optDebugger_ = Some(dbg.asInstanceOf[Debugger])
+ val optDbg = if (dbg eq null) None else Some(dbg.asInstanceOf[Debugger])
+ optDebugger = optDbg
}
+ def withDebugger(dbg:AnyRef) = {
+ val optDbg = if (dbg eq null) None else Some(dbg.asInstanceOf[Debugger])
+ copy(optDebugger = optDbg)
+ }
+
+ @deprecated("Use withDebugging.", "Since 2.6.0")
def setDebugging(flag: Boolean) {
- areDebugging_ = flag
- setTunable("allowExternalPathExpressions", flag.toString)
+ areDebugging = flag
+ tunables = tunables.setTunable("allowExternalPathExpressions",
flag.toString)
}
- def setExternalVariables(extVars: Map[String, String]): Unit = {
+ def withDebugging(flag: Boolean): DataProcessor = {
+ val newTunables = tunables.setTunable("allowExternalPathExpressions",
flag.toString)
+ copy(areDebugging = flag, tunables = newTunables)
+ }
+
+ private def newVariableMap(extVars: Map[String, String]): VariableMap = {
val bindings = ExternalVariablesLoader.getVariables(extVars)
- ExternalVariablesLoader.loadVariables(bindings, ssrd, ssrd.variables)
- ssrd.variables = ExternalVariablesLoader.loadVariables(extVars, ssrd,
ssrd.variables)
+ val newVariableMap = ExternalVariablesLoader.loadVariables(bindings,
ssrd, variableMap)
+ newVariableMap
}
+
+ private def newVariableMap(extVars: File): VariableMap = {
+ ExternalVariablesLoader.loadVariables(extVars, ssrd, variableMap,
getTunables)
+ }
+
+ private def newVariableMap(extVars: File, tunable: DaffodilTunables):
VariableMap = {
+ ExternalVariablesLoader.loadVariables(extVars, ssrd, variableMap,
getTunables)
+ }
+
+ private def newVariableMap(extVars: Seq[Binding]): VariableMap = {
+ ExternalVariablesLoader.loadVariables(extVars, ssrd, variableMap)
+ }
+
+ @deprecated("Use withExternalVariables.", "Since 2.6.0")
+ def setExternalVariables(extVars: Map[String, String]): Unit = {
+ variableMap = newVariableMap(extVars)
+ }
+
+ def withExternalVariables(extVars: Map[String, String]): DataProcessor = {
+ copy(variableMap = newVariableMap(extVars))
+ }
+
+ @deprecated("Use withExternalVariables.", "Since 2.6.0")
def setExternalVariables(extVars: File): Unit = {
- ssrd.variables = ExternalVariablesLoader.loadVariables(extVars, ssrd,
ssrd.variables, getTunables)
+ variableMap = newVariableMap(extVars)
}
+
+ def withExternalVariables(extVars: File): DataProcessor =
+ copy(variableMap = newVariableMap(extVars))
+
+ @deprecated("Use withExternalVariables.", "Since 2.6.0")
def setExternalVariables(extVars: File, tunable: DaffodilTunables): Unit = {
- ssrd.variables = ExternalVariablesLoader.loadVariables(extVars, ssrd,
ssrd.variables, getTunables)
+ variableMap = newVariableMap(extVars, tunable)
+ }
+
+ def withExternalVariables(extVars: File, tunable: DaffodilTunables):
DataProcessor = {
+ copy(variableMap = newVariableMap(extVars, tunable))
}
+ @deprecated("Use withExternalVariables.", "Since 2.6.0")
def setExternalVariables(extVars: Seq[Binding]): Unit = {
- ssrd.variables = ExternalVariablesLoader.loadVariables(extVars, ssrd,
ssrd.variables)
+ variableMap = newVariableMap(extVars)
}
- def setTunable(tunable: String, value: String): Unit = tunablesObj =
tunablesObj.setTunable(tunable, value)
- def setTunables(tunables: Map[String, String]): Unit = tunablesObj =
tunablesObj.setTunables(tunables)
+ def withExternalVariables(extVars: Seq[Binding]): DataProcessor = {
+ copy(variableMap = newVariableMap(extVars))
+ }
+
+ @deprecated("Use withTunables.", "Since 2.6.0")
+ def setTunable(tunable: String, value: String): Unit = tunables =
tunables.setTunable(tunable, value)
+
+ def withTunable(tunable: String, value: String): DataProcessor =
copy(tunables = tunables.setTunable(tunable, value))
+
+ @deprecated("Use withTunables.", "Since 2.6.0")
Review comment:
It looks like scaladoc uses the "since" field to create a deprecation string
of ``Since version %s``. So this will become ``Since version Since 2.6.0``. I
think we just want this to be ``2.6.0``.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services