stevedlawrence commented on a change in pull request #207: Added support for
enumerations and TypeValueCalc
URL: https://github.com/apache/incubator-daffodil/pull/207#discussion_r278610311
##########
File path:
daffodil-core/src/main/scala/org/apache/daffodil/dsom/SimpleTypes.scala
##########
@@ -117,58 +205,56 @@ object PrimitiveType {
}
-abstract class SimpleTypeDefBase(xml: Node, parent: SchemaComponent)
+abstract class SimpleTypeDefBase(xml: Node, parent: SchemaComponent, val
factory: SimpleTypeDefFactory)
extends AnnotatedSchemaComponentImpl(xml, parent)
with SimpleTypeBase
with NonPrimTypeMixin
with ProvidesDFDLStatementMixin
- with OverlapCheckMixin {
+ with OverlapCheckMixin
+ with hasOptRepTypeMixinImpl {
requiredEvaluations(if (elementDecl.isSimpleType)
simpleTypeRuntimeData.preSerialization)
- override def typeNode = primType
+ lazy val primType = factory.primType
- final lazy val restrictions = {
- val thisR = optRestriction.toSeq
- val res = thisR ++
- thisR.flatMap { _.derivationBaseRestrictions }
- res
- }
-
- /**
- * Exclusive of self.
- */
- final lazy val bases: Seq[SimpleTypeDefBase] =
- if (restrictions.isEmpty) Nil
- else restrictions.tail.map { _.simpleType }
+ override def typeNode = primType
- override final def optReferredToComponent = optRestriction.flatMap {
_.optBaseDef }
+ override final def optReferredToComponent = factory.optReferredToComponent
- protected final def emptyFormatFactory = new
DFDLSimpleType(newDFDLAnnotationXML("simpleType"), this)
+ protected final def emptyFormatFactory = factory.emptyFormatFactory
- protected final def isMyFormatAnnotation(a: DFDLAnnotation) =
a.isInstanceOf[DFDLSimpleType]
+ protected final def isMyFormatAnnotation(a: DFDLAnnotation) =
factory.isMyFormatAnnotation(a)
protected final def annotationFactory(node: Node): Option[DFDLAnnotation] = {
node match {
- case <dfdl:simpleType>{ contents @ _* }</dfdl:simpleType> => Some(new
DFDLSimpleType(node, this))
+ case <dfdl:simpleType>{ contents @ _* }</dfdl:simpleType> =>
factory.annotationFactory(node)
case _ => annotationFactoryForDFDLStatement(node, elementBase)
}
}
- final override lazy val (optRestriction, optUnion) = {
- val restrictionNodeSeq = xml \ "restriction"
- if (restrictionNodeSeq.isEmpty) {
- val unionNodeSeq = xml \ "union"
- Assert.invariant(unionNodeSeq.length == 1)
- (None, Some(new Union(unionNodeSeq(0), this)))
- } else {
- (Some(new Restriction(restrictionNodeSeq(0), this)), None)
+ def toOpt[R <: AnyRef](b: Boolean, v: => R) = Misc.boolToOpt(b, v)
+
+ lazy val optTypeCalculator = factory.optTypeCalculator
+ lazy val optRepTypeFactory = factory.optRepTypeFactory
+ lazy val optRepTypeDef = optRepTypeDefFactory.map(_.forDerivedType(this))
+ lazy val optRepValueSet = factory.optRepValueSet
+
+ override lazy val optRestriction =
factory.optRestriction.map(_.restriction(this))
+ override lazy val optUnion = factory.optUnion.map(_.union(this))
+
+ //Perfoming this validation on construction causes infinite loops
+ //So we defer it to later
+ def validate: Unit = {
+ if (optRepTypeFactory.isDefined
+ && optRepTypeFactory.get.isInstanceOf[PrimitiveSimpleTypeFactory]
+ && enclosingElement.isDefined
+ && enclosingElement.get.isRepresented) {
+ SDE("Primitive types can only be used as repTypes when the enclosing
element is computed with inputValueCalc")
Review comment:
This feels like a new pattern to me, for a problem that we must have already
solved. WIll the LV concept deal with infinite loop issues?
----------------------------------------------------------------
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