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

 ##########
 File path: 
daffodil-core/src/main/scala/org/apache/daffodil/compiler/Compiler.scala
 ##########
 @@ -73,190 +73,169 @@ object ForParser extends ParserOrUnparser
 object ForUnparser extends ParserOrUnparser
 object BothParserAndUnparser extends ParserOrUnparser
 
-final class ProcessorFactory(val sset: SchemaSet)
-  extends SchemaComponentImpl(<pf/>, sset)
-  with DFDL.ProcessorFactory
-  with HavingRootSpec {
-
-  lazy val (generateParser, generateUnparser) = {
-    val (context, policy) = tunable.parseUnparsePolicy match {
-      case ParseUnparsePolicyTunable.FromRoot => (Some(rootElem), 
rootElem.rootParseUnparsePolicy)
-      case ParseUnparsePolicyTunable.ParseOnly => (None, 
ParseUnparsePolicy.ParseOnly)
-      case ParseUnparsePolicyTunable.UnparseOnly => (None, 
ParseUnparsePolicy.UnparseOnly)
-      case ParseUnparsePolicyTunable.Both => (None, ParseUnparsePolicy.Both)
-    }
-    rootElem.checkParseUnparsePolicyCompatibility(context, policy)
-    policy match {
-      case ParseUnparsePolicy.Both => (true, true)
-      case ParseUnparsePolicy.ParseOnly => (true, false)
-      case ParseUnparsePolicy.UnparseOnly => (false, true)
-    }
+final class ProcessorFactory private(
+  private var optRootSpec: Option[RootSpec],
+  /*
+   * compilerExternalVarSettings supports the deprecated API
+   * where external variable settings can be supplied to the compiler
+   * instance.
+   *
+   * The non-deprecated API is to deal with external variable settings
+   * on the data processor instance. This is passed here so that
+   * the PF can propagate it to the DP.
+   */
+  var compilerExternalVarSettings: Queue[Binding],
+  schemaSource: DaffodilSchemaSource,
+  val validateDFDLSchemas: Boolean,
+  checkAllTopLevel: Boolean,
+  tunables: DaffodilTunables,
+  optSchemaSet: Option[SchemaSet])
+  extends DFDL.ProcessorFactory {
+
+  def this(optRootName: Option[String],
+    optRootNamespace: Option[String],
+    compilerExternalVarSettings: Queue[Binding],
+    schemaSource: DaffodilSchemaSource,
+    validateDFDLSchemas: Boolean,
+    checkAllTopLevel: Boolean,
+    tunables: DaffodilTunables) =
+    this(
+      RootSpec.makeRootSpec(optRootName, optRootNamespace), // compute 
root-spec object
+      compilerExternalVarSettings, schemaSource, validateDFDLSchemas, 
checkAllTopLevel, tunables, None)
+
+  private def copy(
+    optRootSpec: Option[RootSpec] = optRootSpec,
+    compilerExternalVarSettings: Queue[Binding] = 
compilerExternalVarSettings): ProcessorFactory =
+    new ProcessorFactory(optRootSpec, compilerExternalVarSettings, 
schemaSource, validateDFDLSchemas, checkAllTopLevel, tunables, Some(sset))
+
+  lazy val sset: SchemaSet =
+    optSchemaSet.getOrElse(
+      new SchemaSet(optRootSpec, schemaSource, validateDFDLSchemas, 
checkAllTopLevel, tunables,
+        compilerExternalVarSettings))
+
+  def elementBaseInstanceCount = sset.elementBaseInstanceCount
+
+  def diagnostics = sset.diagnostics
+  def getDiagnostics = diagnostics
+
+  override def onPath(xpath: String) = sset.onPath(xpath)
+
+  override def isError = sset.isError
+
+  @deprecated("Use arguments to Compiler.compileSource or compileFile.", 
"Since 2.6.0")
+  override def setDistinguishedRootNode(name: String, namespace: String): Unit 
= {
+    Assert.usage(name ne null)
+    optRootSpec = RootSpec.makeRootSpec(Option(name), Option(namespace))
   }
 
-  lazy val parser = LV('parser) {
-    val par = if (generateParser) rootElem.document.parser else new 
NotParsableParser(rootElem.erd)
-    Processor.initialize(par)
-    par
-  }.value
-
-  lazy val unparser = LV('unparser) {
-    val unp = if (generateUnparser) rootElem.document.unparser else new 
NotUnparsableUnparser(rootElem.erd)
-    Processor.initialize(unp)
-    unp
-  }.value
-
-  lazy val rootElem = sset.root
+  def withDistinguishedRootNode(name: String, namespace: String) : 
ProcessorFactory = {
+    Assert.usage(name ne null)
+    copy(optRootSpec = RootSpec.makeRootSpec(Option(name), Option(namespace)))
+  }
 
 Review comment:
   E.g. SAPI.Compiler doesn't have a withDistinghishedRootNode, just a 
deprecated setter and args on compileSource and compileFile. 

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