stevedlawrence commented on code in PR #1092:
URL: https://github.com/apache/daffodil/pull/1092#discussion_r1360822467
##########
daffodil-japi/src/main/scala/org/apache/daffodil/japi/Daffodil.scala:
##########
@@ -401,6 +388,12 @@ class DataProcessor private[japi] (private var dp:
SDataProcessor)
extends WithDiagnostics(dp)
with Serializable {
+ /**
+ * For use by the JAPI implementation only.
+ * @return the underlying data processor
+ */
+ private [japi] def getUnderlyingDataProcessor = dp
Review Comment:
Does scala's package private thing apply to the generated java docs? If not,
we might want to add a doc that says this shouldn't be used externally.
##########
daffodil-japi/src/main/scala/org/apache/daffodil/japi/schema/RuntimeSchemaWalker.scala:
##########
@@ -0,0 +1,135 @@
+package org.apache.daffodil.japi.schema
Review Comment:
I wonder if this wants to be in some experimental namespace? I consider japi
and sapi as being very strict about backwards compatibility. It might be nice
to put this in a namespace that makes it clear this maybe not be final and is
subject to change--I don't want to tie us down to an API that maybe isn't
completely fleshed out.
##########
daffodil-japi/src/main/scala/org/apache/daffodil/japi/Daffodil.scala:
##########
@@ -514,6 +507,11 @@ class DataProcessor private[japi] (private var dp:
SDataProcessor)
*/
def save(output: WritableByteChannel): Unit = dp.save(output)
+ def walkRuntimeSchema(handler: RuntimeSchemaHandler): Unit = {
+ val walker = new RuntimeSchemaWalker(dp)
Review Comment:
I think we already have a couple different walkers. We have an`
AbsractDSOMWalker` that is used by the experimental NiFi Daffodil Record
processor. We also have the walker used by the C Code generator. I think they
walk different things. Does this also walk something different? Is there any
chance these could all be combined? Seems we might be doing something wrong if
we have a bunch of different ways to walk different things?
##########
daffodil-japi/src/main/scala/org/apache/daffodil/japi/schema/RuntimeSchemaWalker.scala:
##########
@@ -0,0 +1,135 @@
+package org.apache.daffodil.japi.schema
+
+import org.apache.daffodil.japi.{ DataProcessor => JDataProcessor }
+import org.apache.daffodil.lib.exceptions.Assert
+import org.apache.daffodil.runtime1.dpath.NodeInfo.PrimType
+import org.apache.daffodil.runtime1.processors.{
+ ChoiceRuntimeData,
+ DataProcessor => SDataProcessor,
+ ElementRuntimeData,
+ ErrorERD,
+ SequenceRuntimeData,
+ TermRuntimeData,
+}
+
+/**
+ * Base class used by japi clients who want to walk the runtime schema
information.
+ */
+abstract class RuntimeSchemaHandler() {
+
+ /**
+ * Called for simple type element declarations.
+ *
+ * @param qnameString
+ * @param primTypeName
+ * @param isArray only true if more than one occurrence is possible.
Disjoint with isOptional
+ * @param isOptional true if 0 or 1 occurrence only. Allows for a different
representation of optional from a 0..1 array
+ */
+ def elementSimple(
+ qnameString: String,
+ primTypeName: String,
+ isArray: Boolean,
+ isOptional: Boolean,
+ ): Unit
+
+ /**
+ * Called for complex type element declarations
+ *
+ * Subsequent calls will be for the model group making up the content
+ * of the element.
+ *
+ * @param qnameString
+ */
+ def startElementComplex(qnameString: String, isArray: Boolean, isOptional:
Boolean): Unit
+ def endElementComplex(qnameString: String, isArray: Boolean, isOptional:
Boolean): Unit
+
+ def startSequence(): Unit
+
+ def endSequence(): Unit
+
+ def startChoice(): Unit
+
+ def endChoice(): Unit
+
+}
+
+/**
+ * Walks the schema, but not the DSOM schema, it walks the RuntimeData objects
that
+ * represent the DFDL schema at runtime.
+ *
+ * @param dp
+ */
+class RuntimeSchemaWalker(private val dp: SDataProcessor) {
+
+ // provided so that people can write various tests from JAPI only.
+ // we wouldn't need this otherwise.
+ def this(jdp: JDataProcessor) = this(jdp.getUnderlyingDataProcessor)
+
+ private lazy val rootERD = dp.ssrd.elementRuntimeData
+
+ def walk(handler: RuntimeSchemaHandler): Unit = {
+ walkTerm(handler, rootERD)
+ }
+
+ private def walkTerm(handler: RuntimeSchemaHandler, trd: TermRuntimeData):
Unit = {
Review Comment:
I'm not sure where the logic should be, but one difference between this
walker and the DSOM walker is the DSOM walker has a `isHidden` boolean to avoid
walking into hidden group refs that won't end up in the infoset. Does this need
something similar, or beause this is walking runtime1 constructs are hidden
elements implicitly skipped over?
##########
daffodil-japi/src/main/scala/org/apache/daffodil/japi/schema/RuntimeSchemaWalker.scala:
##########
@@ -0,0 +1,135 @@
+package org.apache.daffodil.japi.schema
+
+import org.apache.daffodil.japi.{ DataProcessor => JDataProcessor }
+import org.apache.daffodil.lib.exceptions.Assert
+import org.apache.daffodil.runtime1.dpath.NodeInfo.PrimType
+import org.apache.daffodil.runtime1.processors.{
+ ChoiceRuntimeData,
+ DataProcessor => SDataProcessor,
+ ElementRuntimeData,
+ ErrorERD,
+ SequenceRuntimeData,
+ TermRuntimeData,
+}
+
+/**
+ * Base class used by japi clients who want to walk the runtime schema
information.
+ */
+abstract class RuntimeSchemaHandler() {
Review Comment:
We already have a DSOM walker used by NiFi, is that not sufficient? Can you
add comments about how the two differ?
--
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]