andrewjc2000 commented on a change in pull request #394: URL: https://github.com/apache/incubator-daffodil/pull/394#discussion_r454728698
########## File path: daffodil-core/src/main/scala/org/apache/daffodil/dsom/walker/RecordWalker.scala ########## @@ -0,0 +1,309 @@ +/* + * 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.dsom.walker + +import java.io.File +import java.util + +import org.apache.daffodil.dsom.{Choice, ComplexTypeBase, ElementBase, GroupRef, Root, Sequence, SimpleTypeBase, Term} +import org.apache.nifi.serialization.SimpleRecordSchema +import org.apache.nifi.serialization.record.{DataType, RecordField, RecordFieldType, RecordSchema, SchemaIdentifier} +import org.apache.nifi.serialization.record.`type`.RecordDataType +import scala.collection.mutable.ListBuffer + +/** + * Direct subclass of the NIFI RecordField. NIFI doesn't have "Optional" fields, so + * eventually this will either be removed from the Schema if an Infoset doesn't have the field, + * or it will become a regular RecordField if it does. + * @param fieldName the name for the RecordField + * @param dataType the NIFI DataType of this RecordField + */ +class OptionalRecordField(fieldName: String, dataType: DataType) + extends RecordField(fieldName, dataType) { + // this is the easiest way to construct it; essentially a "copy constructor" except to denote + // that we want to treat it as this special optional subclass. + def this(recordField: RecordField) = this(recordField.getFieldName, recordField.getDataType) + override def equals(obj: Any): Boolean = + obj match { + case _: OptionalRecordField => super.equals(obj) + case _ => false + } + override def hashCode(): Int = 31 * super.hashCode() + 1 + override def toString: String = "Optional" + super.toString +} + +/** + * Concrete implementation of the AbstractDSOMWalker abstract class. + * This class produces a NIFI RecordSchema that is intended to match the original DFDL file. + * + * The RecordSchema is built in 3 primary stages: + * 1) A tree of SchemaNodes is created as the DFDL file is walked; this walk is performed + * through the various event handlers defined in the parent abstract class. + * 2) The tree of SchemaNodes undergoes some post-processing, mainly to remove redundant Record wrappers. + * 3) The tree of SchemaNodes is converted into a RecordSchema; it is walked recursively within this class. + * @param schemaFile an input DFDL Schema file to parse + */ +class RecordWalker(schemaFile: File) extends AbstractDSOMWalker[RecordSchema](schemaFile) { Review comment: Now that the walk is initiated externally from `ProcessorFactory` rather than from the walker itself, there is currently no way to start it via the Java or Scala API. I am going to go ahead and add the `walkDSOM` method to the `ProcessorFactory` in the JAPI and SAPI modules; let me know if you think something else should be done instead. ---------------------------------------------------------------- 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]
