mbeckerle commented on a change in pull request #88: Daffodil 1919 separators
URL: https://github.com/apache/incubator-daffodil/pull/88#discussion_r209086193
 
 

 ##########
 File path: 
daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/SequenceChildUnparsers.scala
 ##########
 @@ -0,0 +1,276 @@
+/*
+ * 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.
+ */
+package org.apache.daffodil.processors.unparsers
+
+import org.apache.daffodil.processors.Success
+import org.apache.daffodil.processors.SequenceRuntimeData
+import org.apache.daffodil.processors.ElementRuntimeData
+import org.apache.daffodil.processors.TermRuntimeData
+import org.apache.daffodil.api.ValidationMode
+import org.apache.daffodil.exceptions.Assert
+import org.apache.daffodil.infoset.DIArray
+import org.apache.daffodil.equality._
+import org.apache.daffodil.processors.parsers.MinMaxRepeatsMixin
+import org.apache.daffodil.schema.annotation.props.gen.OccursCountKind
+
+/**
+ * base for unparsers for the children of sequences.
+ *
+ * There is one sequence child unparser for each child (declared) of the 
sequence.
+ *
+ * These do not iterate over multiple recurring instances. That iteration 
happens
+ * in the caller. These unparse only a single occurrence when the child 
unparser
+ * is for an array/optional element.
+ */
+abstract class SequenceChildUnparser(
+  val childUnparser: Unparser,
+  val srd: SequenceRuntimeData,
+  val trd: TermRuntimeData)
+  extends CombinatorUnparser(srd) {
+
+  override def runtimeDependencies = Nil
+}
+
+/**
+ * Base for unparsers of array/optional elements.
+ *
+ * The unparse() method unparses exactly one occurrance, does NOT iterate over
+ * all the occurrences.
+ */
+abstract class RepeatingChildUnparser(
+  override val childUnparser: Unparser,
+  override val srd: SequenceRuntimeData,
+  val erd: ElementRuntimeData)
+  extends SequenceChildUnparser(childUnparser, srd, erd)
+  with MinMaxRepeatsMixin {
+
+  /**
+   * Unparse exactly one occurrence of an array/optional element.
+   *
+   * Iterating for arrays/optionals is done in the caller.
+   */
+  override protected def unparse(state: UState): Unit = {
+    childUnparser.unparse1(state)
+  }
+
+  override lazy val runtimeDependencies = Nil
+
+  override def toString = "RepUnparser(" + childUnparser.toString + ")"
+
+  override def toBriefXML(depthLimit: Int = -1): String = {
+    if (depthLimit == 0) "..." else
+      "<RepUnparser name='" + erd.name + "'>" + 
childUnparser.toBriefXML(depthLimit - 1) +
+        "</RepUnparser>"
+  }
+
+  /**
+   * Sets up for the start of an array. Pulls an event, which must be a 
start-array
+   * event.
+   */
+  def startArray(state: UState): Unit = {
+    //
+    // The Infoset events don't create an array start/end event for a
+    // truly optional (0..1) element.
+    //
+    // But an expression might still refer to dfdl:occursIndex() and we want 
that
+    // to be 1, not wherever an enclosing parent array is.
+    //
+    state.arrayIndexStack.push(1L) // one-based indexing
+
+    val ev = state.inspectAccessor
+    if (ev.erd.isArray) {
+      // only pull start array event for a true array, not an optional.
+      val event = state.advanceOrError
+      Assert.invariant(event.isStart && event.node.isInstanceOf[DIArray])
+      // pull the next event, so that nothing else sees or deals with array 
start events
+      state.inspect
+    }
+  }
+
+  /**
+   * Ends an array. Pulls an event which must be an end-array event.
 
 Review comment:
   Done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to