mbeckerle commented on code in PR #1112:
URL: https://github.com/apache/daffodil/pull/1112#discussion_r1387457854


##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/MetadataWalker.scala:
##########
@@ -0,0 +1,76 @@
+package org.apache.daffodil.runtime1.processors

Review Comment:
   Apache banner missing



##########
daffodil-japi/src/main/scala/org/apache/daffodil/japi/Daffodil.scala:
##########
@@ -514,6 +508,13 @@ class DataProcessor private[japi] (private var dp: 
SDataProcessor)
    */
   def save(output: WritableByteChannel): Unit = dp.save(output)
 
+  /**
+   * Walks the handler over the runtime metadata structures
+   *
+   * @param handler - the handler is called-back during the walk as each 
metadata structure is encountered.
+   */
+  def walkMetadata(handler: MetadataHandler) = dp.walkMetadata(handler)

Review Comment:
   Comment from prior PR: 
   https://github.com/apache/daffodil/pull/1092/files#r1360829216
   
   Substance of it is why do we need another walker. Answer is in the commit 
message, but in short - because it makes more sense to do it on the runtime1 
metadata objects since we're interfacing to runtime1, not to the schema 
compiler. 
   
   This may need more study. The NiFi integration uses a DSOM walker. 
Consolidation may be possible. 



##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/MetadataWalker.scala:
##########
@@ -0,0 +1,76 @@
+package org.apache.daffodil.runtime1.processors

Review Comment:
   Comment from prior PR:
   https://github.com/apache/daffodil/pull/1092/files#r1360834018
   
   Asked if this should be in some specific different package like perhaps 
"dfdlx.japi" or japix ?



##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/MetadataWalker.scala:
##########
@@ -0,0 +1,76 @@
+package org.apache.daffodil.runtime1.processors
+
+import org.apache.daffodil.lib.exceptions.Assert
+import org.apache.daffodil.runtime1.api.MetadataHandler
+import org.apache.daffodil.runtime1.api.SequenceMetadata
+
+/**
+ * Walks the schema, but not the DSOM schema, it walks the RuntimeData objects 
that
+ * represent the DFDL schema at runtime.
+ *
+ * @param dp
+ */
+class MetadataWalker(private val dp: DataProcessor) {
+
+  private lazy val rootERD = dp.ssrd.elementRuntimeData
+
+  def walk(handler: MetadataHandler): Unit = {
+    walkTerm(handler, rootERD)
+  }
+
+  private def walkTerm(handler: MetadataHandler, trd: TermRuntimeData): Unit = 
{
+    trd match {
+      case err: ErrorERD => Assert.invariantFailed("should not get ErrorERDs")
+      case erd: ElementRuntimeData => walkElement(handler, erd)
+      case srd: SequenceRuntimeData => walkSequence(handler, srd)
+      case crd: ChoiceRuntimeData => walkChoice(handler, crd)
+      case _ => Assert.invariantFailed(s"unrecognized TermRuntimeData subtype: 
$trd")
+    }
+  }
+
+  private def walkElement(handler: MetadataHandler, erd: ElementRuntimeData): 
Unit = {
+    if (erd.optComplexTypeModelGroupRuntimeData.isDefined)
+      walkComplexElement(handler, erd)
+    else
+      walkSimpleElement(handler, erd)
+  }
+
+  private def walkComplexElement(
+    handler: MetadataHandler,
+    erd: ElementRuntimeData,
+  ): Unit = {
+    val mgrd = erd.optComplexTypeModelGroupRuntimeData.getOrElse {
+      Assert.invariantFailed("not a complex type element")
+    }
+    handler.startComplexElementMetadata(erd)
+    walkTerm(handler, mgrd)
+    handler.endComplexElementMetadata(erd)
+  }
+
+  private def walkSimpleElement(
+    handler: MetadataHandler,
+    erd: ElementRuntimeData,
+  ): Unit = {
+    handler.simpleElementMetadata(erd)
+  }
+
+  private def walkSequence(handler: MetadataHandler, sm: SequenceMetadata): 
Unit = {
+    val srd = sm.asInstanceOf[SequenceRuntimeData]
+    if (!srd.isHidden) {

Review Comment:
   Prior PR comment:
   https://github.com/apache/daffodil/pull/1092/files#r1360846271
   
   Was observing the need for this isHidden handling. 
   
   The commit comment has a TODO about verifying that we don't share groups 
between hidden/not. 



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to