stevedlawrence commented on a change in pull request #262: Unordered sequences
URL: https://github.com/apache/incubator-daffodil/pull/262#discussion_r330502420
##########
File path:
daffodil-runtime1/src/main/scala/org/apache/daffodil/infoset/InfosetImpl.scala
##########
@@ -1450,37 +1449,40 @@ sealed class DIComplex(override val erd:
ElementRuntimeData, val tunable: Daffod
* When parsed, these arrays show up as separate DIArrays in the infoset. We
need
* to combine these separate arrays.
* */
- final def flattenAndValidateChildNodes(): Maybe[List[ElementRuntimeData]] = {
- var ret: List[ElementRuntimeData] = List()
- var groups = childNodes.groupBy(_.erd)
+ final def flattenAndValidateChildNodes(pstate: ParseOrUnparseState): Unit = {
+ val groups = childNodes.groupBy(_.erd)
+ childNodes.clear()
groups foreach {
case (erd, nodes) => {
// Check min/maxOccurs validity while iterating over childNodes
- val min0 = erd.minOccurs
- val max0 = erd.maxOccurs
- val isUnbounded = max0 == -1
+ val min = erd.minOccurs
+ val max = erd.maxOccurs
+ val isUnbounded = max == -1
// Flatten multiple DIArrays into the first one
if (erd.isArray) {
- nodes.reduceLeft((a, b) =>
a.asInstanceOf[DIArray].concat(b.asInstanceOf[DIArray]))
+ val a = nodes(0).asInstanceOf[DIArray]
+ nodes.drop(1).foreach( b => a.concat(b.asInstanceOf[DIArray]))
nodes.reduceToSize(1)
+
+ // Need to also remove duplicates from fastLookup
+ val fastSeq = nameToChildNodeLookup.get(a.namedQName)
+ if (fastSeq != null)
+ fastSeq.reduceToSize(1)
+ } else {
+ if (nodes.length > 1)
+ pstate.validationError("Multiple elements detected for scalar
element %s", erd.namedQName)
}
val occurrence = if (erd.isArray) nodes(0).contents.length else
nodes.length
- if (isUnbounded && occurrence < min0)
- ret = ret :+ erd
- else if (!isUnbounded && (occurrence < min0 || occurrence > max0))
- ret = ret :+ erd
+ if (isUnbounded && occurrence < min)
+ pstate.validationError("Element %s failed check of minOccurs='%s'
and maxOccurs='unbounded', actual number of occurrences: %s", erd.namedQName,
min, occurrence)
+ else if (!isUnbounded && (occurrence < min || occurrence > max))
+ pstate.validationError("Element %s failed check of minOccurs='%s'
and maxOccurs='%s', actual number of occurrences: %s", erd.namedQName, min,
max, occurrence)
Review comment:
Should these only be one if ``isArray == true``? Since the else above
requires that scalar elements have a length of 1 or else it's a processing
error? Otherwise, for scalar elements where more than one is parsed, we could
get both a PE and validation errors?
----------------------------------------------------------------
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