This is an automated email from the ASF dual-hosted git repository.
slawrence pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git
The following commit(s) were added to refs/heads/main by this push:
new 2590f54ce Use targetNamespace when resolving global references without
a namespace prefix or default namespace
2590f54ce is described below
commit 2590f54ce93e262d02660bd9d57bc7979a7d06d9
Author: Steve Lawrence <[email protected]>
AuthorDate: Thu Sep 5 12:48:46 2024 -0400
Use targetNamespace when resolving global references without a namespace
prefix or default namespace
When resolving global references (e.g. global element declaration,
complex types, DFDL variables, DFDL formats), if the QName does not have
a prefix then we currently use the default namespace (i.e. xmlns="...")
when resolving the reference. And if the schema does not define a
default namespace then we just assume NoNamespace.
This works fine except when a schema with a targetNamespace includes a
schema with no targetNamespace and default namespace. In that case,
resolving global references in the included schema must use the
targetNamespace of the including schema because all the global
components have been chameleoned into a different namespace.
To fix this, we now pass around targetNamespace to a number of places
where resolving a global reference might be done (which is a lot of
places), and use that targetNamespace when resolving a QName without a
prefix and no default namespace.
Note that the logic to resolve defineFormat references already did
something similar using its custom "adjustNamespace" logic. This is
removed so all global references use the same logic when resolving
references--no post-resolution adjustment is needed.
A number of functions were refactored a bit to make the logic and style
more consistent, making it easier to see where logic differed. Some
unused functions were discovered and removed.
DAFFODIL-2916
---
.../daffodil/core/dpath/DFDLExpressionParser.scala | 4 +-
.../apache/daffodil/core/dpath/Expression.scala | 19 +++--
.../daffodil/core/dsom/CompiledExpression.scala | 10 +++
.../daffodil/core/dsom/DFDLDefineVariable.scala | 7 +-
.../daffodil/core/dsom/DFDLFormatAnnotation.scala | 31 ++-----
.../daffodil/core/dsom/ElementDeclMixin.scala | 7 +-
.../daffodil/core/dsom/RestrictionUnion.scala | 11 ++-
.../daffodil/core/dsom/SchemaComponent.scala | 20 ++++-
.../apache/daffodil/core/dsom/SchemaDocument.scala | 17 +---
.../org/apache/daffodil/core/dsom/SchemaSet.scala | 97 +++++++---------------
.../core/grammar/ElementBaseGrammarMixin.scala | 11 ++-
.../apache/daffodil/core/grammar/GrammarTerm.scala | 1 +
.../daffodil/core/grammar/RepTypeMixin.scala | 8 +-
.../grammar/primitives/PrimitivesExpressions.scala | 10 +++
.../core/runtime1/ElementBaseRuntime1Mixin.scala | 2 +-
.../runtime1/SchemaComponentRuntime1Mixin.scala | 1 +
.../core/runtime1/SimpleTypeRuntime1Mixin.scala | 1 +
.../core/runtime1/VariableRuntime1Mixin.scala | 2 +
.../core/dpath/TestDFDLExpressionEvaluation.scala | 2 +
.../core/dpath/TestDFDLExpressionTree.scala | 44 ++++++----
.../apache/daffodil/lib/externalvars/Binding.scala | 7 +-
.../org/apache/daffodil/lib/xml/QNameBase.scala | 81 ++++++++++++------
.../scala/org/apache/daffodil/lib/xml/QNames.scala | 3 +-
.../annotation/props/TestGeneratedProperties.scala | 2 +
.../runtime1/debugger/InteractiveDebugger.scala | 5 ++
.../apache/daffodil/runtime1/dpath/NodeInfo.scala | 9 ++
.../runtime1/dsom/CompiledExpression1.scala | 3 +
.../runtime1/dsom/ExpressionCompiler.scala | 2 +
.../daffodil/runtime1/processors/RuntimeData.scala | 10 ++-
.../daffodil/section06/namespaces/namespaces.tdml | 52 ++++++++++++
.../namespaces/no_target_namespace.dfdl.xsd | 71 ++++++++++++++++
.../no_target_namespace_include.dfdl.xsd | 54 ++++++++++++
.../section06/namespaces/TestNamespaces.scala | 3 +
33 files changed, 434 insertions(+), 173 deletions(-)
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/DFDLExpressionParser.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/DFDLExpressionParser.scala
index a08194360..f5041f1a6 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/DFDLExpressionParser.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/DFDLExpressionParser.scala
@@ -26,6 +26,7 @@ import scala.xml.NamespaceBinding
import org.apache.daffodil.lib.api.WarnID
import org.apache.daffodil.lib.exceptions.Assert
import org.apache.daffodil.lib.util.Logger
+import org.apache.daffodil.lib.xml.NS
import org.apache.daffodil.lib.xml.NamedQName
import org.apache.daffodil.lib.xml.QNameRegex
import org.apache.daffodil.runtime1.BasicComponent
@@ -52,6 +53,7 @@ class DFDLPathExpressionParser[T <: AnyRef](
qn: NamedQName,
nodeInfoKind: NodeInfo.Kind,
namespaces: NamespaceBinding,
+ targetNamespace: NS,
context: DPathCompileInfo,
isEvaluatedAbove: Boolean,
host: BasicComponent
@@ -229,7 +231,7 @@ class DFDLPathExpressionParser[T <: AnyRef](
def Comp = EqualityComp | NumberComp
def TopLevel: Parser[WholeExpression] = ("{" ~> Expr <~ "}") ^^ { xpr =>
- WholeExpression(nodeInfoKind, xpr, namespaces, context, host)
+ WholeExpression(nodeInfoKind, xpr, namespaces, targetNamespace, context,
host)
}
val SuccessAtEnd = Parser { in => Success(in, new CharSequenceReader("")) }
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala
index a0ae36b50..7d651f8a8 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dpath/Expression.scala
@@ -153,6 +153,8 @@ abstract class Expression extends OOLAGHostImpl() with
BasicComponent {
lazy val namespaces: NamespaceBinding = parent.namespaces
+ lazy val targetNamespace: NS = parent.targetNamespace
+
def children: Seq[Expression]
def setContextsForChildren(context: OOLAGHost = this): Unit = {
@@ -219,7 +221,7 @@ abstract class Expression extends OOLAGHostImpl() with
BasicComponent {
def resolveRef(qnameString: String): RefQName = {
QName
- .resolveRef(qnameString, namespaces, tunable.unqualifiedPathStepPolicy)
+ .resolveRef(qnameString, namespaces, targetNamespace,
tunable.unqualifiedPathStepPolicy)
.recover { case _: Throwable =>
SDE("The prefix of '%s' has no corresponding namespace definition.",
qnameString)
}
@@ -458,6 +460,7 @@ case class WholeExpression(
nodeInfoKind: NodeInfo.Kind,
ifor: Expression,
nsBindingForPrefixResolution: NamespaceBinding,
+ targetNamespaceArg: NS,
ci: DPathCompileInfo,
host: BasicComponent
) extends Expression {
@@ -477,6 +480,8 @@ case class WholeExpression(
override lazy val namespaces = nsBindingForPrefixResolution
+ override lazy val targetNamespace = targetNamespaceArg
+
override def text = ifor.text
override lazy val targetType = nodeInfoKind
@@ -827,7 +832,12 @@ sealed abstract class StepExpression(val step: String, val
pred: Option[Predicat
}
lazy val stepQName = {
- val e = QName.resolveStep(step, namespaces,
tunable.unqualifiedPathStepPolicy)
+ val e = QName.resolveStep(
+ step,
+ namespaces,
+ targetNamespace,
+ tunable.unqualifiedPathStepPolicy
+ )
e match {
case Failure(th) => SDE("Step %s prefix has no corresponding
namespace.", step)
case Success(v) => v
@@ -1367,10 +1377,7 @@ case class VariableRef(val qnameString: String) extends
PrimaryExpression(Nil) {
}
override def text = "$" + qnameString
- lazy val theQName: RefQName = {
- val refQ = resolveRef(qnameString)
- refQ
- }
+ lazy val theQName: RefQName = resolveRef(qnameString)
lazy val vrd = compileInfo.variableMap
.getVariableRuntimeData(theQName)
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/CompiledExpression.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/CompiledExpression.scala
index 1cd2aac48..18e6d6213 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/CompiledExpression.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/CompiledExpression.scala
@@ -25,6 +25,7 @@ import org.apache.daffodil.core.dpath._
import org.apache.daffodil.lib.exceptions.Assert
import org.apache.daffodil.lib.schema.annotation.props.Found
import org.apache.daffodil.lib.util.DPathUtil
+import org.apache.daffodil.lib.xml.NS
import org.apache.daffodil.lib.xml.NamedQName
import org.apache.daffodil.runtime1.BasicComponent
import org.apache.daffodil.runtime1.dpath.NodeInfo
@@ -60,6 +61,7 @@ class ExpressionCompiler[T <: AnyRef] extends
ExpressionCompilerBase[T] {
nodeInfoKind: NodeInfo.Kind,
exprOrLiteral: String,
namespaces: NamespaceBinding,
+ targetNamespace: NS,
compileInfoWhereExpressionWasLocated: DPathCompileInfo,
isEvaluatedAbove: Boolean,
host: BasicComponent,
@@ -76,6 +78,7 @@ class ExpressionCompiler[T <: AnyRef] extends
ExpressionCompilerBase[T] {
nodeInfoKind,
exprOrLiteral,
namespaces,
+ targetNamespace,
compileInfoWhereExpressionWasLocated,
isEvaluatedAbove,
host,
@@ -87,6 +90,7 @@ class ExpressionCompiler[T <: AnyRef] extends
ExpressionCompilerBase[T] {
nodeInfoKind,
exprOrLiteral,
namespaces,
+ targetNamespace,
compileInfoWhereExpressionWasLocated,
isEvaluatedAbove
)
@@ -122,6 +126,7 @@ class ExpressionCompiler[T <: AnyRef] extends
ExpressionCompilerBase[T] {
nodeInfoKind,
property.value,
property.location.namespaces,
+ property.location.targetNamespace,
compileInfo,
isEvaluatedAbove,
host,
@@ -166,6 +171,7 @@ class ExpressionCompiler[T <: AnyRef] extends
ExpressionCompilerBase[T] {
staticNodeInfoKind,
exprOrLiteral,
namespacesForNamespaceResolution,
+ property.location.targetNamespace,
compileInfoWhereExpressionWasLocated,
isEvaluatedAbove,
host,
@@ -180,6 +186,7 @@ class ExpressionCompiler[T <: AnyRef] extends
ExpressionCompilerBase[T] {
runtimeNodeInfoKind,
exprOrLiteral,
namespacesForNamespaceResolution,
+ property.location.targetNamespace,
compileInfoWhereExpressionWasLocated,
isEvaluatedAbove,
host,
@@ -212,6 +219,7 @@ class ExpressionCompiler[T <: AnyRef] extends
ExpressionCompilerBase[T] {
nodeInfoKind: NodeInfo.Kind,
exprOrLiteral: String,
namespaces: NamespaceBinding,
+ targetNamespace: NS,
compileInfoWhereExpressionWasLocated: DPathCompileInfo,
isEvaluatedAbove: Boolean,
host: BasicComponent,
@@ -231,6 +239,7 @@ class ExpressionCompiler[T <: AnyRef] extends
ExpressionCompilerBase[T] {
qn,
nodeInfoKind,
namespaces,
+ targetNamespace,
compileInfo,
isEvaluatedAbove,
host
@@ -244,6 +253,7 @@ class ExpressionCompiler[T <: AnyRef] extends
ExpressionCompilerBase[T] {
nodeInfoKind: NodeInfo.Kind,
exprOrLiteral: String,
namespaces: NamespaceBinding,
+ targetNamespace: NS,
compileInfoWhereExpressionWasLocated: DPathCompileInfo,
isEvaluatedAbove: Boolean
): CompiledExpression[T] = {
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/DFDLDefineVariable.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/DFDLDefineVariable.scala
index ff4073e6d..be82b000d 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/DFDLDefineVariable.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/DFDLDefineVariable.scala
@@ -83,7 +83,12 @@ class DFDLDefineVariable private (node: Node, doc:
SchemaDocument)
}
final lazy val typeQName = {
- val eQN = QName.resolveRef(typeQNameString, namespaces,
tunable.unqualifiedPathStepPolicy)
+ val eQN = QName.resolveRef(
+ typeQNameString,
+ namespaces,
+ targetNamespace,
+ tunable.unqualifiedPathStepPolicy
+ )
val res = eQN.recover { case _: Throwable =>
SDE("Variables must have primitive types. Type is '%s'.",
typeQNameString)
}.get
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/DFDLFormatAnnotation.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/DFDLFormatAnnotation.scala
index c91ee8fc6..10ceaf23b 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/DFDLFormatAnnotation.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/DFDLFormatAnnotation.scala
@@ -24,7 +24,6 @@ import org.apache.daffodil.lib.api.WarnID
import org.apache.daffodil.lib.exceptions.Assert
import org.apache.daffodil.lib.schema.annotation.props.LookupLocation
import org.apache.daffodil.lib.xml.NS
-import org.apache.daffodil.lib.xml.NoNamespace
import org.apache.daffodil.lib.xml.RefQName
import org.apache.daffodil.lib.xml.XMLUtils
@@ -124,14 +123,6 @@ abstract class DFDLFormatAnnotation(nodeArg: Node,
annotatedSCArg: AnnotatedSche
}
}
- private def adjustNamespace(ns: NS) = {
- ns match {
- case NoNamespace =>
- annotatedSC.targetNamespace // this could also be NoNamespace, but
that's ok.
- case _ => ns
- }
- }
-
// The ListMap collection preserves insertion order.
private type NamedFormatMap = ListMap[RefQName, DFDLFormat]
@@ -144,33 +135,21 @@ abstract class DFDLFormatAnnotation(nodeArg: Node,
annotatedSCArg: AnnotatedSche
val res =
qns
.map { case qn =>
- // first we have to adjust the namespace
- // because a file with no target namespace,
- // can reference something in another file, which also has no target
- // namespace. The files can collectively or by nesting, be
- // included in a third file that has a namespace, and in that
- // case all the format definitions being created as those
- // files are loaded will be in that third namespace.
- // so just because we had <dfdl:format ref="someFormat"/> and the
- // ref has no namespace prefix on it, doesn't mean that the
- // defineFormat we're seeking is in no namespace.
- val adjustedNS = adjustNamespace(qn.namespace)
- val adjustedQN = RefQName(None, qn.local, adjustedNS)
- val notSeenIt = seen.get(adjustedQN) == None
+ val notSeenIt = seen.get(qn) == None
schemaDefinitionUnless(
notSeenIt,
"Format ref attributes form a cycle: \n%s\n%s",
- (adjustedQN, locationDescription),
+ (qn, locationDescription),
seen.map { case (qn, fmtAnn) => (qn, fmtAnn.locationDescription)
}.mkString("\n")
)
- val defFmt = schemaSet.getDefineFormat(adjustedQN).getOrElse {
+ val defFmt = schemaSet.getDefineFormat(qn).getOrElse {
annotatedSC.schemaDefinitionError(
"defineFormat with name '%s', was not found.",
- adjustedQN.toString
+ qn.toString
)
}
val fmt = defFmt.formatAnnotation
- val newSeen = seen + (adjustedQN -> fmt)
+ val newSeen = seen + (qn -> fmt)
val moreRefs = fmt.getFormatRefs(newSeen)
moreRefs
}
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/ElementDeclMixin.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/ElementDeclMixin.scala
index d2e64bafb..ad5b9e1be 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/ElementDeclMixin.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/ElementDeclMixin.scala
@@ -74,8 +74,7 @@ trait ElementDeclMixin extends ElementLikeMixin with
ElementDeclView {
final lazy val optNamedComplexType: Option[GlobalComplexTypeDef] = {
namedTypeQName.flatMap { qn =>
- val res = schemaSet.getGlobalComplexTypeDef(qn)
- res
+ schemaSet.getGlobalComplexTypeDef(qn)
}
}
@@ -144,7 +143,9 @@ trait ElementDeclMixin extends ElementLikeMixin with
ElementDeclView {
final lazy val optNamedSimpleType: Option[SimpleTypeBase] = {
namedTypeQName.flatMap { qn =>
-
schemaSet.getPrimitiveType(qn).orElse(schemaSet.getGlobalSimpleTypeDef(qn))
+ PrimType.fromQName(qn).map { PrimitiveType(_) }.orElse {
+ schemaSet.getGlobalSimpleTypeDef(qn)
+ }
}
}
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/RestrictionUnion.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/RestrictionUnion.scala
index bf8ec28b0..2266174ed 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/RestrictionUnion.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/RestrictionUnion.scala
@@ -90,7 +90,12 @@ final class Restriction private (xmlArg: Node, val
simpleTypeDef: SimpleTypeDefB
lazy val baseQName: RefQName = {
val tryBaseQName =
- QName.resolveRef(baseQNameString, xml.scope,
tunable.unqualifiedPathStepPolicy)
+ QName.resolveRef(
+ baseQNameString,
+ xml.scope,
+ targetNamespace,
+ tunable.unqualifiedPathStepPolicy
+ )
schemaDefinitionUnless(
tryBaseQName.isSuccess,
"Failed to resolve base property reference for xs:restriction: " +
tryBaseQName.failed.get.getMessage
@@ -102,10 +107,10 @@ final class Restriction private (xmlArg: Node, val
simpleTypeDef: SimpleTypeDefB
* Exclusive - restriction either has a baseType or a direct primType.
*/
lazy val (optDirectPrimType, optBaseTypeDef: Option[GlobalSimpleTypeDef]) = {
- val optPT = schemaSet.getPrimitiveType(baseQName)
+ val optPT = PrimType.fromQName(baseQName)
val res =
if (optPT.isDefined)
- (Some(optPT.get.typeNode), None)
+ (optPT, None)
else {
val optFactory = schemaSet.getGlobalSimpleTypeDef(baseQName)
val bType =
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaComponent.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaComponent.scala
index 9d78ab250..191603e35 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaComponent.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaComponent.scala
@@ -28,9 +28,11 @@ import org.apache.daffodil.lib.util.Delay
import org.apache.daffodil.lib.util.Misc
import org.apache.daffodil.lib.xml.GetAttributesMixin
import org.apache.daffodil.lib.xml.NS
+import org.apache.daffodil.lib.xml.RefQName
import org.apache.daffodil.lib.xml.ResolvesQNames
import org.apache.daffodil.lib.xml.XMLUtils
import org.apache.daffodil.runtime1.BasicComponent
+import org.apache.daffodil.runtime1.dpath.NodeInfo
import org.apache.daffodil.runtime1.dsom._
import org.apache.daffodil.runtime1.processors.VariableMap
@@ -92,6 +94,7 @@ trait SchemaComponent
Delay('nonElementParents, this, parents),
variableMap,
namespaces,
+ targetNamespace,
path,
schemaFileLocation,
tunable.unqualifiedPathStepPolicy
@@ -262,6 +265,21 @@ trait SchemaComponent
new scala.xml.NamespaceBinding("dfdl", XMLUtils.DFDL_NAMESPACE.toString,
xml.scope)
scala.xml.Elem("dfdl", label, emptyXMLMetadata, dfdlBinding, true)
}
+
+ def errMissingGlobalReferenceNoPrim(
+ qname: RefQName,
+ propertyName: String,
+ referenceDescription: String
+ ): Nothing = {
+ val isPrimitive = NodeInfo.PrimType.fromQName(qname).isDefined
+ val msg =
+ if (isPrimitive)
+ s"The $propertyName property cannnot resolve to a primitive type:
$qname"
+ else
+ s"Failed to resolve $propertyName to a $referenceDescription: $qname"
+ schemaDefinitionError(msg)
+ }
+
}
object Schema {
@@ -334,12 +352,10 @@ final class Schema private (
noneOrOne(schemaDocuments.flatMap { _.getGlobalGroupDef(name) }, name)
def getDefineFormat(name: String) =
noneOrOne(schemaDocuments.flatMap { _.getDefineFormat(name) }, name)
- def getDefineFormats() = schemaDocuments.flatMap { _.defineFormats }
def getDefineVariable(name: String) =
noneOrOne(schemaDocuments.flatMap { _.getDefineVariable(name) }, name)
def getDefineEscapeScheme(name: String) =
noneOrOne(schemaDocuments.flatMap { _.getDefineEscapeScheme(name) }, name)
- def getDefaultFormat = schemaDocuments.flatMap { x =>
Some(x.getDefaultFormat) }
// used for bulk checking of uniqueness
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaDocument.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaDocument.scala
index 6100564d6..85f8c4f75 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaDocument.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaDocument.scala
@@ -263,24 +263,13 @@ final class SchemaDocument private (xmlSDoc:
XMLSchemaDocument)
/**
* by name getters for the global things that can be referenced.
*/
- def getGlobalElementDecl(name: String) = {
- val geds = globalElementDecls
- val res = geds.find { _.name == name }
- res
- }
+ def getGlobalElementDecl(name: String) = globalElementDecls.find { _.name ==
name }
def getGlobalSimpleTypeDef(name: String) = globalSimpleTypeDefs.find {
_.name == name }
def getGlobalComplexTypeDef(name: String) = globalComplexTypeDefs.find {
_.name == name }
def getGlobalGroupDef(name: String) = globalGroupDefs.find { _.name == name }
- def getDefineFormat(name: String) = defineFormats.find { df =>
- val dfName = df.namedQName.local
- val res = dfName == name
- res
- }
- def getDefineVariable(name: String) = {
- val res = defineVariables.find { _.name == name }
- res
- }
+ def getDefineFormat(name: String) = defineFormats.find { _.namedQName.local
== name }
+ def getDefineVariable(name: String) = defineVariables.find { _.name == name }
def getDefaultFormat = this.defaultFormat
def getDefineEscapeScheme(name: String) = defineEscapeSchemes.find { _.name
== name }
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaSet.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaSet.scala
index 2f6db8c61..792b730ea 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaSet.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SchemaSet.scala
@@ -28,7 +28,6 @@ import org.apache.daffodil.lib.api.DaffodilTunables
import org.apache.daffodil.lib.api.Diagnostic
import org.apache.daffodil.lib.api.UnitTestSchemaSource
import org.apache.daffodil.lib.exceptions.Assert
-import org.apache.daffodil.lib.exceptions.ThrowsSDE
import org.apache.daffodil.lib.oolag.OOLAG
import org.apache.daffodil.lib.schema.annotation.props.LookupLocation
import org.apache.daffodil.lib.util.TransitiveClosure
@@ -36,7 +35,6 @@ import org.apache.daffodil.lib.xml.DFDLCatalogResolver
import org.apache.daffodil.lib.xml.NS
import org.apache.daffodil.lib.xml.XMLUtils
import org.apache.daffodil.lib.xml._
-import org.apache.daffodil.runtime1.dpath.NodeInfo
object SchemaSet {
def apply(
@@ -349,8 +347,8 @@ final class SchemaSet private (
*/
private def getGlobalElement(rootSpec: RootSpec) = {
rootSpec match {
- case RootSpec(Some(rootNamespaceName), rootElementName) => {
- val qn = RefQName(None, rootElementName, rootNamespaceName)
+ case RootSpec(Some(rootNamespace), rootElementName) => {
+ val qn = RefQName(None, rootElementName, rootNamespace)
val optGE = getGlobalElementDecl(qn)
val ge = optGE.getOrElse {
schemaDefinitionError("No global element found for %s", rootSpec)
@@ -397,11 +395,11 @@ final class SchemaSet private (
}
/**
- * Retrieve schema by namespace name.
+ * Retrieve schema by namespace
*
- * If the schema has no namespace, then use ""
+ * If the schema has no namespace, then use NoNamespace
*/
- def getSchema(namespace: NS) = {
+ def getSchema(namespace: NS): Option[Schema] = {
val schemaForNamespace = schemas.find { s => s.targetNamespace ==
namespace }
schemaForNamespace
}
@@ -412,88 +410,53 @@ final class SchemaSet private (
*
* These all return factories for the objects, not the objects themselves.
*/
- def getGlobalElementDecl(refQName: RefQName) = {
- val s = getSchema(refQName.namespace)
- val res = s.flatMap { s =>
- {
- val ged = s.getGlobalElementDecl(refQName.local)
- ged
- }
+ def getGlobalElementDecl(refQName: RefQName): Option[GlobalElementDecl] = {
+ getSchema(refQName.namespace).flatMap {
+ _.getGlobalElementDecl(refQName.local)
}
- res
}
- def getGlobalSimpleTypeDef(refQName: RefQName) =
getSchema(refQName.namespace).flatMap {
- _.getGlobalSimpleTypeDef(refQName.local)
- }
-
- def getGlobalSimpleTypeDefNoPrim(
- refQName: RefQName,
- prop: String,
- context: ThrowsSDE
- ): GlobalSimpleTypeDef = {
- val gstd = getGlobalSimpleTypeDef(refQName)
- gstd.getOrElse {
- val isPrimitive = getPrimitiveType(refQName).isDefined
- val msg =
- if (isPrimitive) s"The $prop property cannnot resolve to a primitive
type: $refQName"
- else s"Failed to resolve $prop to a global simpleType definition:
$refQName"
- context.schemaDefinitionError(msg)
+ def getGlobalSimpleTypeDef(refQName: RefQName): Option[GlobalSimpleTypeDef]
= {
+ getSchema(refQName.namespace).flatMap {
+ _.getGlobalSimpleTypeDef(refQName.local)
}
}
- def getGlobalComplexTypeDef(refQName: RefQName) =
getSchema(refQName.namespace).flatMap {
- _.getGlobalComplexTypeDef(refQName.local)
+ def getGlobalComplexTypeDef(refQName: RefQName):
Option[GlobalComplexTypeDef] = {
+ getSchema(refQName.namespace).flatMap {
+ _.getGlobalComplexTypeDef(refQName.local)
+ }
}
- def getGlobalGroupDef(refQName: RefQName) =
getSchema(refQName.namespace).flatMap {
- _.getGlobalGroupDef(refQName.local)
+ def getGlobalGroupDef(refQName: RefQName): Option[GlobalGroupDef] = {
+ getSchema(refQName.namespace).flatMap {
+ _.getGlobalGroupDef(refQName.local)
+ }
}
/**
* DFDL Schema top-level global objects
*/
- def getDefineFormat(refQName: RefQName) = {
- val s = getSchema(refQName.namespace)
- s.flatMap {
+ def getDefineFormat(refQName: RefQName): Option[DFDLDefineFormat] = {
+ getSchema(refQName.namespace).flatMap {
_.getDefineFormat(refQName.local)
}
}
- def getDefineFormats(namespace: NS, context: ThrowsSDE) =
getSchema(namespace) match {
- case None =>
- context.schemaDefinitionError("Failed to find a schema for namespace: "
+ namespace)
- case Some(sch) => sch.getDefineFormats()
- }
-
- def getDefineVariable(refQName: RefQName) = {
- val res = getSchema(refQName.namespace).flatMap {
+ def getDefineVariable(refQName: RefQName): Option[DFDLDefineVariable] = {
+ val optVar = getSchema(refQName.namespace).flatMap {
_.getDefineVariable(refQName.local)
}
- val finalResult = res match {
- case None => {
- val optRes = this.predefinedVars.find(dfv => {
- dfv.namespace == refQName.namespace && dfv.name == refQName.local
- })
- optRes
- }
- case Some(value) => res
+ optVar.orElse {
+ predefinedVars.find(dfv => {
+ dfv.namespace == refQName.namespace && dfv.name == refQName.local
+ })
}
- finalResult
}
- def getDefineEscapeScheme(refQName: RefQName) =
getSchema(refQName.namespace).flatMap {
- _.getDefineEscapeScheme(refQName.local)
- }
-
- def getPrimitiveType(refQName: RefQName) = {
- if (refQName.namespace != XMLUtils.XSD_NAMESPACE) // must check namespace
- None
- else {
- val optPrimNode = NodeInfo.PrimType.fromNameString(refQName.local)
- optPrimNode.map {
- PrimitiveType(_)
- }
+ def getDefineEscapeScheme(refQName: RefQName):
Option[DFDLDefineEscapeSchemeFactory] = {
+ getSchema(refQName.namespace).flatMap {
+ _.getDefineEscapeScheme(refQName.local)
}
}
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala
index fffbe2139..d48a95932 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala
@@ -97,7 +97,14 @@ trait ElementBaseGrammarMixin
// We need to resolve the global simple type of the prefix length type
// because we need to create a detached element with the same schema
// document/parent of the GSTD.
- schemaSet.getGlobalSimpleTypeDefNoPrim(prefixLengthType,
"dfdl:prefixLengthType", this)
+ val gstd = schemaSet.getGlobalSimpleTypeDef(prefixLengthType).getOrElse {
+ errMissingGlobalReferenceNoPrim(
+ prefixLengthType,
+ "dfdl:prefixLengthType",
+ "global simpleType definition"
+ )
+ }
+ gstd
}.value
lazy val prefixedLengthElementDecl: PrefixLengthQuasiElementDecl =
@@ -1478,12 +1485,14 @@ trait ElementBaseGrammarMixin
val exprProp = outputValueCalcOption.asInstanceOf[Found]
val exprText = exprProp.value
val exprNamespaces = exprProp.location.namespaces
+ val exprTargetNamespace = exprProp.location.targetNamespace
val qn = GlobalQName(Some("daf"), "outputValueCalc", XMLUtils.dafintURI)
val expr = ExpressionCompilers.AnyRef.compileExpression(
qn,
primType,
exprText,
exprNamespaces,
+ exprTargetNamespace,
dpathCompileInfo,
isEvaluatedAbove = false,
self,
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/GrammarTerm.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/GrammarTerm.scala
index c1237a889..d7d5392d6 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/GrammarTerm.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/GrammarTerm.scala
@@ -56,6 +56,7 @@ abstract class Gram(contextArg: SchemaComponent)
final override lazy val tunable = context.tunable
final override def namespaces = context.namespaces
+ final override def targetNamespace = context.targetNamespace
final override def unqualifiedPathStepPolicy =
context.unqualifiedPathStepPolicy
final override def schemaFileLocation = context.schemaFileLocation
final override def localSuppressSchemaDefinitionWarnings =
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/RepTypeMixin.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/RepTypeMixin.scala
index 280dee85e..0143930db 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/RepTypeMixin.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/RepTypeMixin.scala
@@ -45,7 +45,13 @@ trait RepTypeMixin { self: ElementBase =>
private lazy val repTypeGSTD: GlobalSimpleTypeDef = LV('repTypeGSTD) {
// throws an SDE if the simple type def is not found or if it is not a
simple type (e.g. a
// primitive type)
- val gstd = schemaSet.getGlobalSimpleTypeDefNoPrim(repType,
"dfdlx:repType", this)
+ val gstd = schemaSet.getGlobalSimpleTypeDef(repType).getOrElse {
+ errMissingGlobalReferenceNoPrim(
+ repType,
+ "dfdlx:repType",
+ "global simpleType definition"
+ )
+ }
schemaDefinitionUnless(
gstd.primType.isInstanceOf[NodeInfo.Integer.Kind],
"dfdlx:repType (%s) must resolve to a global simple type definition
derived from xs:integer, but was %s",
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/primitives/PrimitivesExpressions.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/primitives/PrimitivesExpressions.scala
index 64120f299..5f1c88d70 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/primitives/PrimitivesExpressions.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/primitives/PrimitivesExpressions.scala
@@ -30,6 +30,7 @@ import
org.apache.daffodil.lib.schema.annotation.props.PropertyLookupResult
import org.apache.daffodil.lib.schema.annotation.props.gen.FailureType
import org.apache.daffodil.lib.schema.annotation.props.gen.VariableDirection
import org.apache.daffodil.lib.xml.GlobalQName
+import org.apache.daffodil.lib.xml.NS
import org.apache.daffodil.lib.xml.XMLUtils
import org.apache.daffodil.runtime1.dpath.NodeInfo
import org.apache.daffodil.runtime1.dsom._
@@ -55,6 +56,7 @@ abstract class AssertBase(
decl: AnnotatedSchemaComponent,
exprWithBraces: String,
namespacesForNamespaceResolution: scala.xml.NamespaceBinding,
+ targetNamespaceArg: NS,
scWherePropertyWasLocated: AnnotatedSchemaComponent,
msgOpt: Option[String],
discrim: Boolean, // are we a discriminator or not.
@@ -74,6 +76,7 @@ abstract class AssertBase(
decl,
foundProp.value,
foundProp.location.namespaces,
+ foundProp.location.targetNamespace,
decl,
msgOpt,
discrim,
@@ -84,6 +87,7 @@ abstract class AssertBase(
override val baseName = assertKindName
override lazy val exprText = exprWithBraces
override lazy val exprNamespaces = namespacesForNamespaceResolution
+ override lazy val exprTargetNamespace = targetNamespaceArg
override lazy val exprComponent = scWherePropertyWasLocated
override def nodeKind = NodeInfo.Boolean
@@ -96,6 +100,7 @@ abstract class AssertBase(
NodeInfo.String,
msgOpt.get,
exprNamespaces,
+ exprTargetNamespace,
exprComponent.dpathCompileInfo,
false,
this,
@@ -197,6 +202,7 @@ case class SetVariable(stmt: DFDLSetVariable, override val
term: Term)
override lazy val exprText = stmt.value
override lazy val exprNamespaces = stmt.xml.scope
+ override lazy val exprTargetNamespace = stmt.annotatedSC.targetNamespace
override lazy val exprComponent = stmt
override lazy val nodeKind = stmt.defv.primType
@@ -281,6 +287,7 @@ abstract class ExpressionEvaluatorBase(e:
AnnotatedSchemaComponent) extends Term
def baseName: String
def exprNamespaces: scala.xml.NamespaceBinding
+ def exprTargetNamespace: NS
def exprComponent: SchemaComponent
def exprText: String
@@ -294,6 +301,7 @@ abstract class ExpressionEvaluatorBase(e:
AnnotatedSchemaComponent) extends Term
nodeKind,
exprText,
exprNamespaces,
+ exprTargetNamespace,
exprComponent.dpathCompileInfo,
false,
this,
@@ -307,6 +315,7 @@ abstract class ValueCalcBase(e: ElementBase, property:
PropertyLookupResult)
override lazy val exprText = exprProp.value
override lazy val exprNamespaces = exprProp.location.namespaces
+ override lazy val exprTargetNamespace = exprProp.location.targetNamespace
override lazy val exprComponent =
exprProp.location.asInstanceOf[SchemaComponent]
lazy val pt = e.primType // .typeRuntimeData
@@ -335,6 +344,7 @@ abstract class AssertPatternPrimBase(decl: Term, stmt:
DFDLAssertionBase, discri
override val baseName = if (discrim) "Discriminator" else "Assert"
override lazy val exprText = stmt.messageAttrib.get
override lazy val exprNamespaces = decl.namespaces
+ override lazy val exprTargetNamespace = decl.targetNamespace
override lazy val exprComponent = decl
override def nodeKind = NodeInfo.String
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/ElementBaseRuntime1Mixin.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/ElementBaseRuntime1Mixin.scala
index 0493c691a..f8032f65e 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/ElementBaseRuntime1Mixin.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/ElementBaseRuntime1Mixin.scala
@@ -148,6 +148,7 @@ trait ElementBaseRuntime1Mixin { self: ElementBase =>
variableMap,
Delay('elementChildrenCompileInfo, this, elementChildrenCompileInfo),
namespaces,
+ targetNamespace,
slashPath,
name,
isArray,
@@ -190,7 +191,6 @@ trait ElementBaseRuntime1Mixin { self: ElementBase =>
minimizedScope,
defaultBitOrder,
optPrimType,
- targetNamespace,
optSimpleTypeRuntimeData,
optComplexTypeModelGroupRuntimeData,
minOccurs,
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/SchemaComponentRuntime1Mixin.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/SchemaComponentRuntime1Mixin.scala
index ef8a105e2..93461eeb0 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/SchemaComponentRuntime1Mixin.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/SchemaComponentRuntime1Mixin.scala
@@ -43,6 +43,7 @@ trait SchemaComponentRuntime1Mixin { self: SchemaComponent =>
diagnosticDebugName,
path,
namespaces,
+ targetNamespace,
tunable.unqualifiedPathStepPolicy
)
}.value
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/SimpleTypeRuntime1Mixin.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/SimpleTypeRuntime1Mixin.scala
index 2929c43d9..f4d572079 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/SimpleTypeRuntime1Mixin.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/SimpleTypeRuntime1Mixin.scala
@@ -30,6 +30,7 @@ trait SimpleTypeRuntime1Mixin { self: SimpleTypeDefBase =>
diagnosticDebugName,
path,
namespaces,
+ targetNamespace,
primType,
noFacetChecks,
optRestriction.toSeq.flatMap { r => if (r.hasPattern) r.patternValues
else Nil },
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/VariableRuntime1Mixin.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/VariableRuntime1Mixin.scala
index d9e8f5f16..45698b740 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/VariableRuntime1Mixin.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/VariableRuntime1Mixin.scala
@@ -40,6 +40,7 @@ trait DFDLDefineVariableRuntime1Mixin { self:
DFDLDefineVariable =>
this.diagnosticDebugName,
this.path,
this.namespaces,
+ this.targetNamespace,
this.external,
this.direction,
Delay('maybeDefaultValueExpr, this, maybeDefaultValueExpr),
@@ -93,6 +94,7 @@ trait DFDLNewVariableInstanceRuntime1Mixin { self:
DFDLNewVariableInstance =>
this.diagnosticDebugName,
this.path,
this.namespaces,
+ this.targetNamespace,
defv.external,
defv.direction,
Delay('maybeDefaultValueExpr2, this, maybeDefaultValueExpr),
diff --git
a/daffodil-core/src/test/scala/org/apache/daffodil/core/dpath/TestDFDLExpressionEvaluation.scala
b/daffodil-core/src/test/scala/org/apache/daffodil/core/dpath/TestDFDLExpressionEvaluation.scala
index 737328dee..2682e8eda 100644
---
a/daffodil-core/src/test/scala/org/apache/daffodil/core/dpath/TestDFDLExpressionEvaluation.scala
+++
b/daffodil-core/src/test/scala/org/apache/daffodil/core/dpath/TestDFDLExpressionEvaluation.scala
@@ -47,6 +47,7 @@ class TestDFDLExpressionEvaluation extends Parsers {
.withTunable("releaseUnneededInfoset", "false")
val pf =
schemaCompiler.compileNode(testSchema).asInstanceOf[ProcessorFactory]
val sset = pf.sset
+ val targetNamespace =
sset.schemas.head.schemaDocuments.head.targetNamespace
if (pf.isError) fail("pf compile errors")
val dp = pf.onPath("/").asInstanceOf[DataProcessor]
val infosetRootElem = TestInfoset.elem2Infoset(infosetAsXML, dp)
@@ -56,6 +57,7 @@ class TestDFDLExpressionEvaluation extends Parsers {
qn,
NodeInfo.AnyType,
testSchema.scope,
+ targetNamespace,
erd.dpathCompileInfo,
false,
sset
diff --git
a/daffodil-core/src/test/scala/org/apache/daffodil/core/dpath/TestDFDLExpressionTree.scala
b/daffodil-core/src/test/scala/org/apache/daffodil/core/dpath/TestDFDLExpressionTree.scala
index bd8a80716..ce0f1e342 100644
---
a/daffodil-core/src/test/scala/org/apache/daffodil/core/dpath/TestDFDLExpressionTree.scala
+++
b/daffodil-core/src/test/scala/org/apache/daffodil/core/dpath/TestDFDLExpressionTree.scala
@@ -54,6 +54,7 @@ class TestDFDLExpressionTree extends Parsers {
qn,
NodeInfo.String,
testSchema.scope,
+ schemaDoc.targetNamespace,
erd.dpathCompileInfo,
false,
sset
@@ -76,6 +77,7 @@ class TestDFDLExpressionTree extends Parsers {
qn,
NodeInfo.AnyType,
testSchema.scope,
+ schemaDoc.targetNamespace,
decl.dpathCompileInfo,
false,
sset
@@ -115,6 +117,7 @@ class TestDFDLExpressionTree extends Parsers {
RootPathExpression(Some(RelativePathExpression(steps, _))),
_,
_,
+ _,
_
) = ce
val List(n1: DownStepExpression) = steps
@@ -149,6 +152,7 @@ class TestDFDLExpressionTree extends Parsers {
RootPathExpression(Some(RelativePathExpression(steps, _))),
_,
_,
+ _,
_
) = ce
val List(b, a) = steps
@@ -166,7 +170,7 @@ class TestDFDLExpressionTree extends Parsers {
@Test def test_a_predPred(): Unit = {
testExpr(dummySchema, "{ a[i[j]] }") { actual =>
- val WholeExpression(_, RelativePathExpression(steps, _), _, _, _) =
actual
+ val WholeExpression(_, RelativePathExpression(steps, _), _, _, _, _) =
actual
val List(n1) = steps
val NamedStep("a", Some(PredicateExpression(rel))) = n1
val RelativePathExpression(List(n2), _) = rel
@@ -178,7 +182,7 @@ class TestDFDLExpressionTree extends Parsers {
@Test def test_relativePath() = {
testExpr(dummySchema, "{ ../..[2]/bookstore }") { actual =>
- val WholeExpression(_, RelativePathExpression(steps, _), _, _, _) =
actual
+ val WholeExpression(_, RelativePathExpression(steps, _), _, _, _, _) =
actual
val List(n1, n2, n3) = steps
val u @ Up(None) = n1; assertNotNull(u)
val u2 @ Up(Some(PredicateExpression(LiteralExpression(two: JBigInt))))
= n2;
@@ -214,6 +218,7 @@ class TestDFDLExpressionTree extends Parsers {
RootPathExpression(Some(RelativePathExpression(steps, _))),
_,
_,
+ _,
_
) = actual
val List(n1, n2, n3) = steps.asInstanceOf[List[NamedStep]]
@@ -263,6 +268,7 @@ class TestDFDLExpressionTree extends Parsers {
RootPathExpression(Some(RelativePathExpression(List(step: NamedStep),
_))),
_,
_,
+ _,
_
) = actual
val exc = intercept[Exception] {
@@ -283,6 +289,7 @@ class TestDFDLExpressionTree extends Parsers {
RootPathExpression(Some(RelativePathExpression(steps, _))),
_,
_,
+ _,
_
) = actual
val List(n1, n2, n3) = steps
@@ -305,6 +312,7 @@ class TestDFDLExpressionTree extends Parsers {
),
_,
_,
+ _,
_
) = actual; assertNotNull(a)
assertEquals(JBigInt.valueOf(1), one)
@@ -314,7 +322,7 @@ class TestDFDLExpressionTree extends Parsers {
@Test def testFnTrue(): Unit = {
testExpr(dummySchema, "{ fn:true() }") { actual =>
- val a @ WholeExpression(_, FunctionCallExpression("fn:true", Nil), _, _,
_) = actual;
+ val a @ WholeExpression(_, FunctionCallExpression("fn:true", Nil), _, _,
_, _) = actual;
assertNotNull(a)
}
}
@@ -322,7 +330,8 @@ class TestDFDLExpressionTree extends Parsers {
@Test def test_numbers1() = {
testExpr(dummySchema, "{ 0. }") { actual: Expression =>
val res = JBigDecimal.ZERO
- val a @ WholeExpression(_, LiteralExpression(actualRes: JBigDecimal), _,
_, _) = actual;
+ val a @ WholeExpression(_, LiteralExpression(actualRes: JBigDecimal), _,
_, _, _) =
+ actual;
assertNotNull(a)
assertEquals(res, actualRes)
}
@@ -331,28 +340,29 @@ class TestDFDLExpressionTree extends Parsers {
@Test def test_numbers() = {
testExpr(dummySchema, "{ 5.0E2 }") {
- case WholeExpression(_, LiteralExpression(500.0), _, _, _) => /* ok */ ;
+ case WholeExpression(_, LiteralExpression(500.0), _, _, _, _) => /* ok
*/ ;
}
testExpr(dummySchema, "{ 5E2 }") {
- case WholeExpression(_, LiteralExpression(500.0), _, _, _) => /* ok */ ;
+ case WholeExpression(_, LiteralExpression(500.0), _, _, _, _) => /* ok
*/ ;
}
testExpr(dummySchema, "{ .2E2 }") {
- case WholeExpression(_, LiteralExpression(20.0), _, _, _) => /* ok */ ;
+ case WholeExpression(_, LiteralExpression(20.0), _, _, _, _) => /* ok */
;
}
testExpr(dummySchema, "{ .2E-3 }") {
- case WholeExpression(_, LiteralExpression(0.0002), _, _, _) => /* ok */ ;
+ case WholeExpression(_, LiteralExpression(0.0002), _, _, _, _) => /* ok
*/ ;
}
testExpr(dummySchema, "{ .2E+3 }") {
- case WholeExpression(_, LiteralExpression(200.0), _, _, _) => /* ok */ ;
+ case WholeExpression(_, LiteralExpression(200.0), _, _, _, _) => /* ok
*/ ;
}
// testExpr(dummySchema, "0.") { actual =>
// val res = new JBigDecimal("0.0")
- // val a @ WholeExpression(_, LiteralExpression(`res`), _, _, _) =
actual; assertNotNull(a)
+ // val a @ WholeExpression(_, LiteralExpression(`res`), _, _, _, _) =
actual; assertNotNull(a)
// }
testExpr(dummySchema, "{ .1 }") { actual =>
val res = new JBigDecimal("0.1")
- val a @ WholeExpression(_, LiteralExpression(`res`), _, _, _) = actual;
assertNotNull(a)
+ val a @ WholeExpression(_, LiteralExpression(`res`), _, _, _, _) =
actual;
+ assertNotNull(a)
}
testExpr(
dummySchema,
@@ -360,20 +370,20 @@ class TestDFDLExpressionTree extends Parsers {
) { actual =>
val res =
new
JBigDecimal("982304892038409234982304892038409234.0909808908982304892038409234")
- val WholeExpression(_, LiteralExpression(r: JBigDecimal), _, _, _) =
actual
+ val WholeExpression(_, LiteralExpression(r: JBigDecimal), _, _, _, _) =
actual
assertEquals(res, r)
}
testExpr(dummySchema, "{ 0 }") { actual =>
val res = JBigInt.ZERO
- val a @ WholeExpression(_, LiteralExpression(actualRes: JBigInt), _, _,
_) = actual;
+ val a @ WholeExpression(_, LiteralExpression(actualRes: JBigInt), _, _,
_, _) = actual;
assertNotNull(a)
assertEquals(res, actualRes)
}
testExpr(dummySchema, "{
9817239872193792873982173948739879128370982398723897921370 }") {
actual =>
val res = new
JBigInt("9817239872193792873982173948739879128370982398723897921370")
- val a @ WholeExpression(_, LiteralExpression(actualRes: JBigInt), _,
_, _) = actual;
+ val a @ WholeExpression(_, LiteralExpression(actualRes: JBigInt), _,
_, _, _) = actual;
assertNotNull(a)
assertEquals(res, actualRes)
}
@@ -384,7 +394,7 @@ class TestDFDLExpressionTree extends Parsers {
def testStringLit(expr: String): Unit = {
testExpr(dummySchema, expr) {
- case WholeExpression(_, LiteralExpression(expr), _, _, _) => /* ok */
+ case WholeExpression(_, LiteralExpression(expr), _, _, _, _) => /* ok
*/
}
}
testStringLit("{ 'abc' }")
@@ -405,7 +415,7 @@ class TestDFDLExpressionTree extends Parsers {
def testFn(expr: String)(body: FunctionCallExpression => Unit): Unit = {
testExpr(dummySchema, expr) { actual =>
- val WholeExpression(_, fnExpr: FunctionCallExpression, _, _, _) =
actual
+ val WholeExpression(_, fnExpr: FunctionCallExpression, _, _, _, _) =
actual
body(fnExpr)
}
}
@@ -428,7 +438,7 @@ class TestDFDLExpressionTree extends Parsers {
else +i
}"""
) { actual =>
- val WholeExpression(_, IfExpression(Seq(pred, thenPart, elsePart)), _,
_, _) = actual
+ val WholeExpression(_, IfExpression(Seq(pred, thenPart, elsePart)), _,
_, _, _) = actual
val p @ OrExpression(
List(
RelativePathExpression(List(NamedStep("a", None)), _),
diff --git
a/daffodil-lib/src/main/scala/org/apache/daffodil/lib/externalvars/Binding.scala
b/daffodil-lib/src/main/scala/org/apache/daffodil/lib/externalvars/Binding.scala
index 12de91734..7e268b1c1 100644
---
a/daffodil-lib/src/main/scala/org/apache/daffodil/lib/externalvars/Binding.scala
+++
b/daffodil-lib/src/main/scala/org/apache/daffodil/lib/externalvars/Binding.scala
@@ -96,7 +96,12 @@ object Binding {
// if one is defined.
//
val rqn =
- RefQNameFactory.resolveRef(name, scope,
UnqualifiedPathStepPolicy.DefaultNamespace)
+ RefQNameFactory.resolveRef(
+ name,
+ scope,
+ NoNamespace,
+ UnqualifiedPathStepPolicy.DefaultNamespace
+ )
new Binding(rqn.get, value)
}
diff --git
a/daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/QNameBase.scala
b/daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/QNameBase.scala
index 7b964982c..879d58a2b 100644
--- a/daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/QNameBase.scala
+++ b/daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/QNameBase.scala
@@ -111,9 +111,10 @@ object QName {
def resolveRef(
qnameString: String,
scope: scala.xml.NamespaceBinding,
+ targetNamespace: NS,
unqualifiedPathStepPolicy: UnqualifiedPathStepPolicy
): Try[RefQName] =
- RefQNameFactory.resolveRef(qnameString, scope, unqualifiedPathStepPolicy)
+ RefQNameFactory.resolveRef(qnameString, scope, targetNamespace,
unqualifiedPathStepPolicy)
def parseExtSyntax(extSyntax: String): (Option[String], NS, String) = {
val res =
@@ -167,9 +168,21 @@ object QName {
def resolveStep(
qnameString: String,
scope: scala.xml.NamespaceBinding,
+ targetNamespace: NS,
unqualifiedPathStepPolicy: UnqualifiedPathStepPolicy
- ): Try[StepQName] =
- StepQNameFactory.resolveRef(qnameString, scope, unqualifiedPathStepPolicy)
+ ): Try[StepQName] = {
+ // TODO: We pass in NoNamespace instead of targetNamespace here, which may
not be correct in
+ // all cases. If the step being referenced is a global element or if
elementFormDefault is
+ // qualified then we probably do want to use targetNamespace to look it up
since those
+ // elements likely have a namespace. But for non-qualified local steps, we
probably do just
+ // want to use NoNamespace since the step won't have a namespace. However,
this is sort of a
+ // chicken-and-egg problem--we need to know the namespace to how to find
the step, but we
+ // don't know which namespace to use (NoNamespace or targetNamespace)
unless we've already
+ // found the same. Instead, we use NoNamespace and let the flexibility that
+ // unqualfiedPathStepPolicy gives use help to find the step element.
Possibly related to
+ // DAFFODIL-2917
+ StepQNameFactory.resolveRef(qnameString, scope, NoNamespace,
unqualifiedPathStepPolicy)
+ }
def createLocal(
name: String,
@@ -505,23 +518,29 @@ protected trait RefQNameFactoryBase[T] {
def resolveRef(
qnameString: String,
scope: scala.xml.NamespaceBinding,
+ targetNamespace: NS,
unqualifiedPathStepPolicy: UnqualifiedPathStepPolicy
): Try[T] = Try {
qnameString match {
- case QNameRegex.QName(pre, local) => {
- val prefix = Option(pre)
+ case QNameRegex.QName(prefix, local) => {
+
// note that the prefix, if defined, can never be ""
- val optURI = prefix match {
- case None => resolveDefaultNamespace(scope,
unqualifiedPathStepPolicy)
- case Some(pre) => Option(scope.getURI(pre))
+ val pre = Option(prefix)
+ val preNS = pre.map { p =>
+ Option(scope.getURI(p)).map(NS(_)).getOrElse {
+ throw new QNameUndefinedPrefixException(p)
+ }
}
- val ns = (prefix, optURI) match {
- case (None, None) => NoNamespace
- case (Some(pre), None) =>
- throw new QNameUndefinedPrefixException(pre)
- case (_, Some(ns)) => NS(ns)
+ val ns = preNS match {
+ case None => {
+ // there was no prefix, use the default namespace (i.e.
xmln="...") if defined. If
+ // not defined, use the targetNamespace
+ val defaultNS = resolveDefaultNamespace(scope,
unqualifiedPathStepPolicy)
+ defaultNS.map(NS(_)).getOrElse(targetNamespace)
+ }
+ case Some(n) => n
}
- val res = constructor(prefix, local, ns)
+ val res = constructor(pre, local, ns)
res
}
case _ => throw new QNameSyntaxException(Some(qnameString), None)
@@ -548,26 +567,36 @@ object RefQNameFactory extends
RefQNameFactoryBase[RefQName] {
def resolveExtendedSyntaxRef(
extSyntax: String,
scope: scala.xml.NamespaceBinding,
+ targetNamespace: NS,
unqualifiedPathStepPolicy: UnqualifiedPathStepPolicy
): Try[RefQName] = Try {
val (pre, ns, local) = QName.parseExtSyntax(extSyntax)
+
// note that the prefix, if defined, can never be ""
- val optURI = pre match {
- case None => resolveDefaultNamespace(scope, unqualifiedPathStepPolicy)
- case Some(prefix) => Option(scope.getURI(prefix))
+ val preNS = pre.map { p =>
+ Option(scope.getURI(p)).map(NS(_)).getOrElse {
+ throw new QNameUndefinedPrefixException(p)
+ }
}
- val optNS = (pre, optURI, ns) match {
- case (None, None, UnspecifiedNamespace) =>
- resolveDefaultNamespace(scope, unqualifiedPathStepPolicy).map { NS(_) }
- case (_, Some(uriString), UnspecifiedNamespace) => Some(NS(uriString))
- case (Some(pre), None, _) => throw new QNameUndefinedPrefixException(pre)
- case (Some(pre), Some(uriString), n) if (n.toString != uriString) =>
- Assert.invariantFailed(
+ val resolvedNS = (preNS, ns) match {
+ case (None, UnspecifiedNamespace) => {
+ // if neither prefix nor namespace was specified, use the default
namespace (i.e.
+ // xmln="...") if defined. If not defined, use the targetNamespace.
+ val defaultNS = resolveDefaultNamespace(scope,
unqualifiedPathStepPolicy)
+ defaultNS.map(NS(_)).getOrElse(targetNamespace)
+ }
+ case (None, n) => n
+ case (Some(pn), UnspecifiedNamespace) => pn
+ case (Some(pn), n) => {
+ // TODO: Is this actually an invariant, or should this be an exception
simlar to
+ // QNameUndefinedPrefixException?
+ Assert.invariant(
+ pn eq n,
"namespace from prefix and scope, and ns argument are inconsitent."
)
- case (_, _, n) => Some(n)
+ n
+ }
}
- val resolvedNS = optNS.getOrElse(UnspecifiedNamespace)
val res = constructor(pre, local, resolvedNS)
res
}
diff --git
a/daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/QNames.scala
b/daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/QNames.scala
index 628766946..d8d30d33a 100644
--- a/daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/QNames.scala
+++ b/daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/QNames.scala
@@ -61,12 +61,13 @@ trait ResolvesQNames extends ThrowsSDE {
def namespaces: scala.xml.NamespaceBinding
def unqualifiedPathStepPolicy: UnqualifiedPathStepPolicy
+ def targetNamespace: NS
/**
* If prefix of name is unmapped, SDE
*/
def resolveQName(qnString: String): RefQName = {
- val eQN = QName.resolveRef(qnString, namespaces, unqualifiedPathStepPolicy)
+ val eQN = QName.resolveRef(qnString, namespaces, targetNamespace,
unqualifiedPathStepPolicy)
// we don't want to just throw the exception, we want to
// convert to an SDE, so we use recover
val res = eQN.recover { ThrowSDE }.get
diff --git
a/daffodil-lib/src/test/scala/org/apache/daffodil/lib/schema/annotation/props/TestGeneratedProperties.scala
b/daffodil-lib/src/test/scala/org/apache/daffodil/lib/schema/annotation/props/TestGeneratedProperties.scala
index 7c41e3d46..e5e6630ae 100644
---
a/daffodil-lib/src/test/scala/org/apache/daffodil/lib/schema/annotation/props/TestGeneratedProperties.scala
+++
b/daffodil-lib/src/test/scala/org/apache/daffodil/lib/schema/annotation/props/TestGeneratedProperties.scala
@@ -22,6 +22,7 @@ import org.apache.daffodil.lib.api.WarnID
import org.apache.daffodil.lib.exceptions.SchemaFileLocation
import org.apache.daffodil.lib.oolag.OOLAG.OOLAGHostImpl
import org.apache.daffodil.lib.schema.annotation.props.gen._
+import org.apache.daffodil.lib.xml.NS
import org.junit.Assert._
import org.junit.Test
@@ -54,6 +55,7 @@ class TestGeneratedProperties {
def lineDescription: String = ???
def locationDescription: String = ???
def namespaces: scala.xml.NamespaceBinding = ???
+ def targetNamespace: NS = ???
def schemaFileLocation: SchemaFileLocation = ???
val xml = bagOfProps
diff --git
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/debugger/InteractiveDebugger.scala
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/debugger/InteractiveDebugger.scala
index 47c95ddf4..28a0e897d 100644
---
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/debugger/InteractiveDebugger.scala
+++
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/debugger/InteractiveDebugger.scala
@@ -30,6 +30,7 @@ import org.apache.daffodil.lib.util.DPathUtil
import org.apache.daffodil.lib.util.Enum
import org.apache.daffodil.lib.util.Misc
import org.apache.daffodil.lib.xml.GlobalQName
+import org.apache.daffodil.lib.xml.NS
import org.apache.daffodil.lib.xml.QName
import org.apache.daffodil.lib.xml.XMLUtils
import org.apache.daffodil.runtime1.BasicComponent
@@ -308,6 +309,7 @@ class InteractiveDebugger(
NodeInfo.Boolean,
expression,
context.dpathCompileInfo.namespaces,
+ context.dpathCompileInfo.targetNamespace,
context.dpathCompileInfo,
false,
hostForDiags,
@@ -1107,6 +1109,7 @@ class InteractiveDebugger(
else expression
val context = state.getContext()
val namespaces = context.dpathCompileInfo.namespaces
+ val targetNamespace = context.dpathCompileInfo.targetNamespace
val expressionWithBraces =
if (!DPathUtil.isExpression(adjustedExpression)) "{ " +
adjustedExpression + " }"
else adjustedExpression
@@ -1118,6 +1121,7 @@ class InteractiveDebugger(
NodeInfo.AnyType,
expressionWithBraces,
namespaces,
+ targetNamespace,
context.dpathCompileInfo,
isEvaluatedAbove,
hostForDiags,
@@ -2367,6 +2371,7 @@ class DebuggerHost(override val tunable: DaffodilTunables)
*/
// Members declared in org.apache.daffodil.lib.xml.ResolvesQNames
def namespaces: scala.xml.NamespaceBinding = ???
+ def targetNamespace: NS = ???
def unqualifiedPathStepPolicy:
org.apache.daffodil.lib.api.UnqualifiedPathStepPolicy = ???
// Members declared in org.apache.daffodil.lib.exceptions.ThrowsSDE
def schemaFileLocation:
org.apache.daffodil.lib.exceptions.SchemaFileLocation = ???
diff --git
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/NodeInfo.scala
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/NodeInfo.scala
index 6a1152797..cb94dec31 100644
---
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/NodeInfo.scala
+++
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/NodeInfo.scala
@@ -44,6 +44,7 @@ import org.apache.daffodil.lib.util.Numbers.asBigInt
import org.apache.daffodil.lib.xml.GlobalQName
import org.apache.daffodil.lib.xml.NoNamespace
import org.apache.daffodil.lib.xml.QName
+import org.apache.daffodil.lib.xml.RefQName
import org.apache.daffodil.lib.xml.XMLUtils
import org.apache.daffodil.runtime1.api.DFDLPrimType
import org.apache.daffodil.runtime1.dsom.walker._
@@ -506,6 +507,14 @@ object NodeInfo extends Enum {
nameToPrimType.get(name)
}
+ def fromQName(qname: RefQName): Option[PrimType] = {
+ if (qname.namespace != XMLUtils.XSD_NAMESPACE) None
+ else {
+ val optPrimNode = fromNameString(qname.local)
+ optPrimNode
+ }
+ }
+
trait PrimNonNumeric { self: AnyAtomic.Kind =>
protected def fromString(s: String): DataValuePrimitive
def fromXMLString(s: String): DataValuePrimitive = {
diff --git
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/CompiledExpression1.scala
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/CompiledExpression1.scala
index a14b24967..07f85b5d2 100644
---
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/CompiledExpression1.scala
+++
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/CompiledExpression1.scala
@@ -207,6 +207,7 @@ class DPathCompileInfo(
@TransientParam parentsDelay: Delay[Seq[DPathCompileInfo]],
val variableMap: VariableMap,
val namespaces: scala.xml.NamespaceBinding,
+ val targetNamespace: NS,
val path: String,
override val schemaFileLocation: SchemaFileLocation,
val unqualifiedPathStepPolicy: UnqualifiedPathStepPolicy
@@ -341,6 +342,7 @@ class DPathElementCompileInfo(
// to realize the by-name arg expression.
elementChildrenCompileInfoDelay: Delay[Seq[DPathElementCompileInfo]],
namespaces: scala.xml.NamespaceBinding,
+ targetNamespace: NS,
path: String,
val name: String,
val isArray: Boolean,
@@ -356,6 +358,7 @@ class DPathElementCompileInfo(
parentsDelay.asInstanceOf[Delay[Seq[DPathCompileInfo]]],
variableMap,
namespaces,
+ targetNamespace,
path,
sfl,
unqualifiedPathStepPolicy
diff --git
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/ExpressionCompiler.scala
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/ExpressionCompiler.scala
index 49909d7b1..b3025fc10 100644
---
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/ExpressionCompiler.scala
+++
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/ExpressionCompiler.scala
@@ -20,6 +20,7 @@ package org.apache.daffodil.runtime1.dsom
import java.lang.{ Boolean => JBoolean, Long => JLong }
import scala.xml.NamespaceBinding
+import org.apache.daffodil.lib.xml.NS
import org.apache.daffodil.lib.xml.NamedQName
import org.apache.daffodil.runtime1.BasicComponent
import org.apache.daffodil.runtime1.dpath.NodeInfo
@@ -31,6 +32,7 @@ trait ExpressionCompilerBase[T <: AnyRef] {
nodeInfoKind: NodeInfo.Kind,
exprWithBracesMaybe: String,
namespaces: NamespaceBinding,
+ targetNamespace: NS,
compileInfoWherePropertyWasLocated: DPathCompileInfo,
isEvaluatedAbove: Boolean,
host: BasicComponent,
diff --git
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/RuntimeData.scala
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/RuntimeData.scala
index f1f2d7884..b46573290 100644
---
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/RuntimeData.scala
+++
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/RuntimeData.scala
@@ -96,6 +96,7 @@ sealed trait RuntimeData
def variableMap: VariableMap
def unqualifiedPathStepPolicy: UnqualifiedPathStepPolicy
def namespaces: NamespaceBinding
+ def targetNamespace: NS
def diagnosticDebugName: String
override def toString =
diagnosticDebugName // diagnostic messages depend on toString doing this
@@ -174,6 +175,7 @@ sealed abstract class TermRuntimeData(
}
final def namespaces = dpathCompileInfo.namespaces
+ final def targetNamespace = dpathCompileInfo.targetNamespace
private val termID = TermRuntimeData.generateTermID
@@ -213,6 +215,7 @@ sealed class NonTermRuntimeData(
val diagnosticDebugName: String,
val path: String,
override val namespaces: NamespaceBinding,
+ override val targetNamespace: NS,
val unqualifiedPathStepPolicy: UnqualifiedPathStepPolicy
) extends RuntimeData {}
@@ -228,6 +231,7 @@ final class SimpleTypeRuntimeData(
diagnosticDebugNameArg: String,
pathArg: String,
namespacesArg: NamespaceBinding,
+ targetNamespaceArg: NS,
val primType: NodeInfo.PrimType,
val noFacetChecks: Boolean,
val patternValues: Seq[FacetTypes.FacetValueR],
@@ -249,6 +253,7 @@ final class SimpleTypeRuntimeData(
diagnosticDebugNameArg,
pathArg,
namespacesArg,
+ targetNamespaceArg,
unqualifiedPathStepPolicyArg
) {
@@ -654,7 +659,6 @@ sealed class ElementRuntimeData(
override val minimizedScope: NamespaceBinding,
defaultBitOrderArg: BitOrder,
val optPrimType: Option[PrimType],
- val targetNamespace: NS,
val optSimpleTypeRuntimeData: Option[SimpleTypeRuntimeData],
val optComplexTypeModelGroupRuntimeData: Option[ModelGroupRuntimeData],
val minOccurs: Long,
@@ -782,6 +786,7 @@ sealed abstract class ErrorERD(local: String, namespaceURI:
String)
Seq[DPathElementCompileInfo]()
).force, // elementChildrenCompileInfoDelay:
Delay[Seq[DPathElementCompileInfo]],
null, // namespaces: scala.xml.NamespaceBinding,
+ null, // targetNamespace: NS,
local, // path: String,
local, // val name: String,
false, // val isArray: Boolean,
@@ -800,7 +805,6 @@ sealed abstract class ErrorERD(local: String, namespaceURI:
String)
null, // minimizedScopeArg: => NamespaceBinding,
null, // defaultBitOrderArg: => BitOrder,
None, // optPrimTypeArg: => Option[PrimType],
- null, // targetNamespaceArg: => NS,
null, // optSimpleTypeRuntimeDataArg: => Option[SimpleTypeRuntimeData],
null, // optComplexTypeModelGroupRuntimeDataArg: =>
Option[ModelGroupRuntimeData],
0L, // minOccursArg: => Long,
@@ -1040,6 +1044,7 @@ final class VariableRuntimeData(
diagnosticDebugNameArg: String,
pathArg: String,
namespacesArg: NamespaceBinding,
+ targetNamespaceArg: NS,
val external: Boolean,
val direction: VariableDirection,
maybeDefaultValueExprDelay: Delay[Maybe[CompiledExpression[AnyRef]]],
@@ -1054,6 +1059,7 @@ final class VariableRuntimeData(
diagnosticDebugNameArg,
pathArg,
namespacesArg,
+ targetNamespaceArg,
unqualifiedPathStepPolicyArg
) {
diff --git
a/daffodil-test/src/test/resources/org/apache/daffodil/section06/namespaces/namespaces.tdml
b/daffodil-test/src/test/resources/org/apache/daffodil/section06/namespaces/namespaces.tdml
index 7493a97f4..cc68a5941 100644
---
a/daffodil-test/src/test/resources/org/apache/daffodil/section06/namespaces/namespaces.tdml
+++
b/daffodil-test/src/test/resources/org/apache/daffodil/section06/namespaces/namespaces.tdml
@@ -2439,4 +2439,56 @@
</tdml:infoset>
</tdml:parserTestCase>
+ <!--
+ Test name: noTargetNamespace_01
+ Schema: no_target_namespace.dfdl.xsd
+ Root: root
+ Purpose: A schema with no target namespace can successfully reference all
+ types of global references
+ -->
+ <tdml:parserTestCase name="noTargetNamespace_01"
+ root="root" model="no_target_namespace.dfdl.xsd">
+ <tdml:document>1,2,3,4,</tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <root>
+ <one>1</one>
+ <two>
+ <two>2</two>
+ </two>
+ <three>3</three>
+ <four>4</four>
+ <five>5</five>
+ </root>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ </tdml:parserTestCase>
+
+ <!--
+ Test name: noTargetNamespace_02
+ Schema: no_target_namespace_include.dfdl.xsd
+ Root: combined
+ Purpose: Includes a no-namespce schema with internal references to global
elements,
+ the includd schema references are chameleoned
+ -->
+ <tdml:parserTestCase name="noTargetNamespace_02"
+ root="combined" model="no_target_namespace_include.dfdl.xsd">
+ <tdml:document>1,2,3,4,</tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:combined xmlns:ex="http://example.com/">
+ <ex:root>
+ <one xmlns="http://example.com/">1</one>
+ <two>
+ <two>2</two>
+ </two>
+ <three>3</three>
+ <four>4</four>
+ <five>6</five>
+ </ex:root>
+ </ex:combined>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ </tdml:parserTestCase>
+
</tdml:testSuite>
diff --git
a/daffodil-test/src/test/resources/org/apache/daffodil/section06/namespaces/no_target_namespace.dfdl.xsd
b/daffodil-test/src/test/resources/org/apache/daffodil/section06/namespaces/no_target_namespace.dfdl.xsd
new file mode 100644
index 000000000..4500d396c
--- /dev/null
+++
b/daffodil-test/src/test/resources/org/apache/daffodil/section06/namespaces/no_target_namespace.dfdl.xsd
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/">
+
+ <xs:include
schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+
+ <xs:annotation>
+ <xs:appinfo source="http://www.ogf.org/dfdl/">
+ <dfdl:format ref="GeneralFormat" />
+ <dfdl:defineFormat name="delimited">
+ <dfdl:format lengthKind="delimited" />
+ </dfdl:defineFormat>
+ <dfdl:defineVariable name="ntnVar" type="xs:string" defaultValue="5" />
+ <dfdl:defineEscapeScheme name="ntnES">
+ <dfdl:escapeScheme escapeKind="escapeCharacter"
+ escapeCharacter="\"
+ escapeEscapeCharacter=""
+ extraEscapedCharacters="" />
+ </dfdl:defineEscapeScheme>
+ </xs:appinfo>
+ </xs:annotation>
+
+ <xs:element name="root">
+ <xs:complexType>
+ <xs:sequence dfdl:separator="," dfdl:separatorPosition="postfix">
+ <xs:element ref="one" />
+ <xs:element name="two" type="ct" />
+ <xs:element name="three" type="st" />
+ <xs:group ref="gr" />
+ <xs:element name="five" type="xs:string" dfdl:inputValueCalc="{
$ntnVar }" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="one" type="xs:string" dfdl:ref="delimited"
dfdl:escapeSchemeRef="ntnES" />
+
+ <xs:complexType name="ct">
+ <xs:sequence>
+ <xs:element name="two" type="xs:string" dfdl:ref="delimited" />
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:simpleType name="st" dfdl:ref="delimited">
+ <xs:restriction base="xs:string" />
+ </xs:simpleType>
+
+ <xs:group name="gr">
+ <xs:sequence>
+ <xs:element name="four" type="xs:string" dfdl:ref="delimited" />
+ </xs:sequence>
+ </xs:group>
+
+</xs:schema>
diff --git
a/daffodil-test/src/test/resources/org/apache/daffodil/section06/namespaces/no_target_namespace_include.dfdl.xsd
b/daffodil-test/src/test/resources/org/apache/daffodil/section06/namespaces/no_target_namespace_include.dfdl.xsd
new file mode 100644
index 000000000..01329f3e9
--- /dev/null
+++
b/daffodil-test/src/test/resources/org/apache/daffodil/section06/namespaces/no_target_namespace_include.dfdl.xsd
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+ xmlns:ex="http://example.com/"
+ targetNamespace="http://example.com/">
+
+ <!--
+ includes a no target namespace schema into one that has a target
+ namespace, which chameleons the references
+ -->
+ <xs:include schemaLocation="no_target_namespace.dfdl.xsd" />
+
+ <xs:include
schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+
+ <xs:annotation>
+ <xs:appinfo source="http://www.ogf.org/dfdl/">
+ <dfdl:format ref="ex:GeneralFormat" />
+ </xs:appinfo>
+ </xs:annotation>
+
+ <xs:element name="combined">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:sequence>
+ <xs:annotation>
+ <xs:appinfo source="http://www.ogf.org/dfdl/">
+ <dfdl:setVariable ref="ex:ntnVar" value="6" />
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:sequence>
+ <xs:element ref="ex:root" dfdl:ref="ex:delimited" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+</xs:schema>
diff --git
a/daffodil-test/src/test/scala/org/apache/daffodil/section06/namespaces/TestNamespaces.scala
b/daffodil-test/src/test/scala/org/apache/daffodil/section06/namespaces/TestNamespaces.scala
index 16537be0d..045ee2992 100644
---
a/daffodil-test/src/test/scala/org/apache/daffodil/section06/namespaces/TestNamespaces.scala
+++
b/daffodil-test/src/test/scala/org/apache/daffodil/section06/namespaces/TestNamespaces.scala
@@ -248,4 +248,7 @@ class TestNamespaces {
@Test def test_deprecatedSchemaLocation01(): Unit = {
runner3.runOneTest("deprecatedSchemaLocation01")
}
+
+ @Test def test_noTargetNamespace_01(): Unit = {
runner.runOneTest("noTargetNamespace_01") }
+ @Test def test_noTargetNamespace_02(): Unit = {
runner.runOneTest("noTargetNamespace_02") }
}