stevedlawrence commented on a change in pull request #214: Sequences and 
Separators Refactoring and Rewrite
URL: https://github.com/apache/incubator-daffodil/pull/214#discussion_r285190073
 
 

 ##########
 File path: 
daffodil-lib/src/main/scala/org/apache/daffodil/schema/annotation/props/ByHandMixins.scala
 ##########
 @@ -386,3 +397,76 @@ trait TextStandardExponentRepMixin   extends 
PropertyMixin {
     }
   }
 }
+
+/**
+ * By hand because we can set our preference for it via a tunable.
+ * And also can require it to be present or not via a tunable.
+ */
+sealed trait EmptyElementPolicy extends EmptyElementPolicy.Value
+object EmptyElementPolicy extends Enum[EmptyElementPolicy] {
+  case object EmptySuppressed extends EmptyElementPolicy; 
forceConstruction(EmptySuppressed)
+  case object EmptyAllowed extends EmptyElementPolicy; 
forceConstruction(EmptyAllowed)
+
+  def apply(name: String, context: ThrowsSDE): EmptyElementPolicy = 
stringToEnum("emptyElementPolicy", name, context)
+}
+trait EmptyElementPolicyMixin extends PropertyMixin {
+
+  def tunable: DaffodilTunables
+
+  /**
+   * get Some(property value) or None if not defined in scope.
+   *
+   * Mostly do not use this. Most code shouldn't need to test for
+   * property existence. Just insist on the property you need by
+   * using its name. E.g., if you need calendarTimeZone, just use
+   * a.calendarTimeZone (where a is an AnnotatedSchemaComponent)
+   */
+  private def optionEmptyElementPolicyRaw = 
cachePropertyOption("emptyElementPolicy")
+  private def emptyElementPolicyRaw =
+    EmptyElementPolicy(requireProperty(optionEmptyElementPolicyRaw).value, 
this)
+
+  /**
+   * Property determines whether Daffodil implements empty elements in a 
manner consistent with
+   * IBM DFDL (as of 2019-05-02), which has policy emptySuppressed, or 
implements what is
+   * described in the DFDL spec., which is mptyElements - if the syntax of
+   * empty (or nullness) is matched, create an empty (or null) item, even if 
optional, unless
+   * the element is entirely absent (e.g., no separator at all.)
+   */
+  final lazy val emptyElementPolicy = {
+    //
+    // check for conflicting property and tunable, in case you have both.
+    //
+    val optEmptyElementPolicyTunable = this.tunable.emptyElementPolicy
+
+    optionEmptyElementPolicyRaw match {
+      case Found(eepString, _, _, _) => {
+        val eep = emptyElementPolicyRaw
+        optEmptyElementPolicyTunable.foreach { eept =>
+          if (eep ne eept) {
+            SDW(WarnID.TunableParameterBeingIgnored,
+              "Tuning of emptyElementProperty is being ignored because 
property daf:emptyElementPolicy='%s' is specified in the schema.",
+              Misc.initialLowerCase(eep.toString))
+          }
+        }
+        eep
+      }
+      case _ => {
+        val eep =
+          if (this.tunable.requireEmptyElementPolicyProperty ||
+            optionEmptyElementPolicyRaw.isDefined) {
 
 Review comment:
   I think ``optionEmptyElementPoliyRaw.isDefined`` is always false here, since 
this is in the NotFound case?

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

Reply via email to