private def computeMinMaxLength:()

in daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/ElementBase.scala [1006:1088]


  private def computeMinMaxLength: (java.math.BigDecimal, java.math.BigDecimal) = {
    schemaDefinitionUnless(
      isSimpleType,
      "The length facet or minLength/maxLength facets are not allowed on complex types"
    )
    typeDef match {
      case _ if hasRepType => {
        // this minLength/maxLength is only used for the length of the representation. The
        // values used for facet restrictions during limited validation come from elsewhere
        (repTypeElementDecl.minLength, repTypeElementDecl.maxLength)
      }
      case prim: PrimitiveType => {
        val pt = prim.primType
        schemaDefinitionWhen(
          (pt == PrimType.String || pt == PrimType.HexBinary) && lengthKind == LengthKind.Implicit,
          "The length facet or minLength/maxLength facets must be defined for type %s with lengthKind='implicit'",
          pt.name
        )
        //
        // We handle text numbers by getting a stringValue first, then
        // we convert to the number type.
        //
        // This means we cannot check and SDE here on incorrect simple type.
        (zeroBD, unbBD)
      }
      case st: SimpleTypeDefBase if st.optRestriction.isDefined => {
        val r = st.optRestriction.get
        val pt = st.primType
        val typeOK = pt == PrimType.String || pt == PrimType.HexBinary
        schemaDefinitionWhen(
          !typeOK && (hasLength || hasMinLength || hasMaxLength),
          "The length facet or minLength/maxLength facets are not allowed on types derived from type %s.\nThey are allowed only on types derived from string and hexBinary.",
          pt.name
        )
        val res = (
          hasLength,
          hasMinLength,
          hasMaxLength,
          lengthKind,
          isRepresented
        ) match {
          case (true, false, false, _, _) => (r.lengthValue, r.lengthValue)
          case (true, _, _, _, _) =>
            Assert.invariantFailed(
              "Facet length cannot be defined with minLength and maxLength facets"
            )
          case (false, true, true, LengthKind.Implicit, true) => {
            schemaDefinitionUnless(
              r.minLengthValue.compareTo(r.maxLengthValue) == 0,
              "The minLength and maxLength must be equal for type %s with lengthKind='implicit'. Values were minLength of %s, maxLength of %s.",
              pt.name,
              r.minLengthValue,
              r.maxLengthValue
            )
            (r.minLengthValue, r.maxLengthValue)
          }
          case (false, true, true, _, _) => {
            schemaDefinitionWhen(
              r.minLengthValue.compareTo(r.maxLengthValue) > 0,
              // always true, so we don't bother to specify the type in the message.
              "The minLength facet value must be less than or equal to the maxLength facet value. Values were minLength of %s, maxLength of %s.",
              r.minLengthValue,
              r.maxLengthValue
            )
            (r.minLengthValue, r.maxLengthValue)
          }
          case (false, _, _, LengthKind.Implicit, true) =>
            SDE(
              "When lengthKind='implicit', both minLength and maxLength facets must be specified."
            )
          case (false, false, true, _, _) => (zeroBD, r.maxLengthValue)
          case (false, false, false, _, _) => (zeroBD, unbBD)
          case (false, true, false, _, _) => (r.minLengthValue, unbBD)
          case _ => Assert.impossible()
        }
        res
      }
      case st: SimpleTypeDefBase => {
        Assert.invariant(st.optRestriction.isEmpty)
        (zeroBD, unbBD)
      }
    }
  }