mbeckerle commented on a change in pull request #343: WIP: Daf 2302 ext var
URL: https://github.com/apache/incubator-daffodil/pull/343#discussion_r400203883
 
 

 ##########
 File path: 
daffodil-core/src/main/scala/org/apache/daffodil/compiler/Compiler.scala
 ##########
 @@ -192,34 +216,63 @@ final class ProcessorFactory(val sset: SchemaSet)
 /**
  * Both Compiler and ProcessorFactory share this same API call.
  */
-trait HavingRootSpec extends Logging {
-  var rootSpec: Option[RootSpec] = None
+trait HavingRootSpec[T] extends Logging {
+  var rootSpec: Option[RootSpec]
 
+  @deprecated("2020-03-26", "Use withDistinguishedRootNode.")
   def setDistinguishedRootNode(name: String, namespace: String): Unit = {
+    rootSpec = getRootSpec(name, namespace)
+  }
+
+  def withDistinguishedRootNode(name: String, namespace: String): T
+
+  protected final def getRootSpec(name: String, namespace: String): 
Option[RootSpec] = {
     val ns =
       if (namespace != null) Some(NS(namespace))
       else None
-    rootSpec = Some(RootSpec(ns, name))
-    // log(Info("%s setDistinguishedRootNode to %s", 
Misc.getNameFromClass(this), rootSpec))
-    //
-    // null means we search for the namespace
-    // Must be only one answer.
-    //
-
+    Some(RootSpec(ns, name))
   }
 }
+
 class InvalidParserException(msg: String, cause: Throwable = null) extends 
Exception(msg, cause)
 
-class Compiler(var validateDFDLSchemas: Boolean = true)
+class Compiler private (var validateDFDLSchemas: Boolean,
+  var tunables : DaffodilTunables,
+  /*
+   * Supports deprecated feature of establishing external vars on the compiler 
object.
+   * These are just saved and passed to the processor factory which 
incorporates them into
+   * the variable map of the data processor.
+   *
+   * This argument can be removed once this deprecated feature is removed.
+   */
+  private var externalDFDLVariables: Queue[Binding],
+  private var checkAllTopLevel : Boolean,
+  var rootSpec: Option[RootSpec]) // TODO: rename optRootSpec
   extends DFDL.Compiler
   with Logging
-  with HavingRootSpec {
+  with HavingRootSpec[Compiler] {
 
-  def setValidateDFDLSchemas(value: Boolean) = validateDFDLSchemas = value
+  private def this(validateDFDLSchemas: Boolean = true) = 
this(validateDFDLSchemas, DaffodilTunables(), Queue.empty, true, None)
 
-  private var tunablesObj = DaffodilTunables()
+  private def copy(validateDFDLSchemas: Boolean = validateDFDLSchemas,
+    tunables : DaffodilTunables = tunables,
+    externalDFDLVariables: Queue[Binding] = externalDFDLVariables,
+    checkAllTopLevel : Boolean = checkAllTopLevel,
+    rootSpec: Option[RootSpec] = rootSpec) =
+    new Compiler(validateDFDLSchemas, tunables, externalDFDLVariables, 
checkAllTopLevel, rootSpec)
+
+  /**
+   * Identical method to what we have in ProcessorFactory, but I couldn't
+   * come up with a way to share it in the HavingRootSpec mixin because it 
calls copy. So it is duplicated.
+   * Only 2 lines though. .
+   */
+  override def withDistinguishedRootNode(name: String, namespace: String): 
Compiler =
+    copy(rootSpec = getRootSpec(name, namespace))
+
+  @deprecated("2020-03-26", "Use withValidateDFDLSchemas.")
 
 Review comment:
   Seriously, they reversed the arg order from java's syntax.
   Why why why....
   I will see if @deprecated(since = "2016-03-26", message="...") works also, 
since that's clearer. 
   
   Also it seems that the since argument can be "Daffodil 2.6.0" instead of a 
date, which is better. 
   

----------------------------------------------------------------
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

Reply via email to