stevedlawrence commented on a change in pull request #343: WIP: Daf 2302 ext var
URL: https://github.com/apache/incubator-daffodil/pull/343#discussion_r400132696
##########
File path:
daffodil-core/src/main/scala/org/apache/daffodil/dsom/SchemaSet.scala
##########
@@ -480,66 +480,14 @@ final class SchemaSet(
Seq(encDFV, boDFV, binDFV, outDFV)
}
- /**
- * Determines if any of the externally defined variables
- * were specified expecting Daffodil to figure out the
- * namespace. If so, Daffodil attempts to guess the
- * namespace and will SDE if there is any ambiguity.
- *
- * @param allDefinedVariables The list of all DFDLDefineVariables in the
SchemaSet.
- *
- * @return A list of external variables updated with any found namespaces.
- */
- private def resolveExternalVariableNamespaces(allDefinedVariables:
Seq[DFDLDefineVariable]) = {
- val finalExternalVariables: scala.collection.mutable.Queue[Binding] =
scala.collection.mutable.Queue.empty
-
- val extVarsWithoutNS = externalVariables.filterNot(b =>
b.hasNamespaceSpecified)
-
- val extVarsWithNS = externalVariables.filter(b => b.hasNamespaceSpecified)
+ lazy val allDefinedVariables = schemas.flatMap{ _.defineVariables }
+ lazy val allExternalVariables = allDefinedVariables.filter{ _.external }
- extVarsWithNS.foreach(b => finalExternalVariables.enqueue(b))
-
- extVarsWithoutNS.foreach(v => {
- Assert.invariant(v.varQName.namespace.isUnspecified)
- val matchingDVs = allDefinedVariables.filter { dv =>
- // just compare local names. We're searching for an unambiguous match
- v.varQName.local == dv.namedQName.local
- }
-
- matchingDVs.length match {
- case 0 => this.SDE("Could not find the externally defined variable
%s.", v.varQName)
- case x: Int if x > 1 =>
- this.SDE(
- "The externally defined variable %s is ambiguous. " +
- "A namespace is required to resolve the ambiguity.\nFound:\t%s",
- v.varQName, matchingDVs.mkString(", "))
- case _ => // This is OK, we have exactly 1 match
- }
-
- val newNS = matchingDVs.head.namespace
- val newBinding = try {
- Binding(v.varQName.local, Some(newNS), v.varValue)
- } catch {
- case e: BindingException => this.SDE("Exception when processing
external variable %s: %s", v.varQName, e.getMessage)
- }
- finalExternalVariables.enqueue(newBinding)
- })
- finalExternalVariables
- }
-
- override def variableMap = LV('variableMap) {
+ override def variableMap: VariableMap = LV('variableMap) {
val dvs = allSchemaDocuments.flatMap { _.defineVariables }
Review comment:
Can this be replaced with the new allDefinedVariables above?
----------------------------------------------------------------
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