bsloane1650 commented on a change in pull request #207: Added support for
enumerations and TypeValueCalc
URL: https://github.com/apache/incubator-daffodil/pull/207#discussion_r275514346
##########
File path:
daffodil-core/src/main/scala/org/apache/daffodil/dsom/SimpleTypes.scala
##########
@@ -259,26 +591,91 @@ final class GlobalSimpleTypeDefFactory(xmlArg: Node,
schemaDocumentArg: SchemaDo
final class GlobalSimpleTypeDef(
derivedType: Option[SimpleTypeDefBase],
- val factory: GlobalSimpleTypeDefFactory,
+ factory: GlobalSimpleTypeDefFactory,
val referringElement: Option[ElementDeclMixin])
- extends SimpleTypeDefBase(factory.xml, factory.schemaDocument)
+ extends SimpleTypeDefBase(factory.xml, factory.schemaDocument, factory)
with GlobalNonElementComponentMixin
with NestingTraversesToReferenceMixin {
// override def term = element
+ override lazy val primType = factory.primType
+
override lazy val referringComponent: Option[SchemaComponent] =
(derivedType, referringElement) match {
case (Some(dt), None) => derivedType
case (None, Some(elem)) => referringElement
- case _ => Assert.impossible("SimpleType must either have a derivedType
or an element. Not both.")
+ case (Some(_), Some(_)) => Assert.impossible("SimpleType must either
have a derivedType or an element. Not both.")
+ case (None, None) => None
}
override lazy val elementDecl: ElementDeclMixin = referringComponent match {
case Some(dt: SimpleTypeDefBase) => dt.elementDecl
- case Some(e: ElementDeclMixin) => e
- case _ => Assert.invariantFailed("unexpected referringComponent")
+ case Some(e: ElementDeclMixin) => e
+ case _ => Assert.invariantFailed("unexpected
referringComponent")
}
}
+final class EnumerationDefFactory(
+ xml: Node,
+ parentTypeFactory: SimpleTypeDefFactory)
+ extends SchemaComponentFactory(xml, parentTypeFactory.schemaDocument)
+ with NestingLexicalMixin
+ with HasRepValueAttributes
+ with ResolvesProperties {
+
+ Assert.invariant(xml.label == "enumeration")
+
+ def enumerationDef(parentType: SimpleTypeDefBase) = {
+ Assert.invariant(parentType.factory == parentTypeFactory)
+ new EnumerationDef(parentType, this)
+ }
+
+ override lazy val optRepTypeFactory = parentTypeFactory.optRepTypeFactory
+
+ lazy val enumValueRaw: String = (xml \ "@value").head.text
+ lazy val enumValueCooked: AnyRef =
parentTypeFactory.primType.fromXMLString(enumValueRaw)
+
+ override lazy val optRepValueSet: Option[RepValueSet[AnyRef]] =
optRepValueSetFromAttribute
+ lazy val logicalValueSet: RepValueSet[AnyRef] =
RepValueSetCompiler.compile(Seq(enumValueCooked), Seq())
+ lazy val canonicalRepValue: Option[AnyRef] = {
+ val ans1 = repValuesAttrCooked.headOption
+ val ans2 = repValueRangesAttrCooked.headOption.map(_._1).flatMap(asBound
=> {
+ //TODO, currently, if the first repValue comes from an exclusive
restriction we cannot
+ //infer a canonical repValue
+ if (asBound.isInclusive) (Some(asBound.maybeBound.get)) else None
+ })
+ val ans = ans1.orElse(ans2)
+ Assert.invariant(ans.isDefined == optRepValueSet.isDefined)
+ ans
+ }
+
+ override protected val optReferredToComponent = None
+
+ protected def annotationFactory(node: Node): Option[DFDLAnnotation] =
Assert.invariantFailed("Should not be called")
+ protected def emptyFormatFactory: DFDLFormatAnnotation = new
DFDLEnumerationFactory(newDFDLAnnotationXML("enumeration"), this)
+ protected def isMyFormatAnnotation(a: DFDLAnnotation): Boolean =
Assert.invariantFailed("Should not be called")
+
+}
+
+final class EnumerationDef(
Review comment:
You appear to be correct, EnumerationDef is never actually used, so I will
get rid of it. I believe this means my refactoring of EnumerationDef amounts to
adding "Factory" to its class name.
This is a bit weird, as it means that we have a "Factory" class that is not
actually a factory, but in the context of DSOM, I think the name
EnumerationDefFactory still makes sense, as "Factory" here really means "schema
component considered in isolation of its context". Indeed even the
SimpleTypeDed/Restriction/Union "factories" are more than just factories, since
they do a fair amount of stuff unrelated to generating the "concrete" object
(and, in some cases, will never be even be called for their factory method).
I'll add a comment explaining this above EnumerationDefFactory, as I suspect
that is the place that will actually make people scratch their heads.
----------------------------------------------------------------
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