You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by mb...@apache.org on 2017/11/17 16:12:10 UTC
[1/6] incubator-daffodil git commit: Property Resolution - part of
fixing schema compilation
Repository: incubator-daffodil
Updated Branches:
refs/heads/master f761e4d13 -> 895177173
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section06/namespaces/namespaces.tdml
----------------------------------------------------------------------
diff --git a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section06/namespaces/namespaces.tdml b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section06/namespaces/namespaces.tdml
index 1cd8345..cc1d53a 100644
--- a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section06/namespaces/namespaces.tdml
+++ b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section06/namespaces/namespaces.tdml
@@ -1549,7 +1549,12 @@
<tdml:error>MinInclusive(16) must be less than or equal to MaxInclusive(10)</tdml:error>
<tdml:error>shishi</tdml:error>
<tdml:error>Location line</tdml:error>
- <tdml:error>section06/namespaces/shi</tdml:error>
+ <!--
+ No longer gives this location (which is the type definition location. Now it gives
+ the element reference having that type, which is a different file.
+
+ <tdml:error>section06/namespaces/shi</tdml:error>
+ -->
</tdml:errors>
</tdml:parserTestCase>
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section07/assertions/assert.tdml
----------------------------------------------------------------------
diff --git a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section07/assertions/assert.tdml b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section07/assertions/assert.tdml
index fdcd0e7..a5460d2 100644
--- a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section07/assertions/assert.tdml
+++ b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section07/assertions/assert.tdml
@@ -639,11 +639,12 @@
<tdml:parserTestCase name="assertOnGroupRef" root="Item"
model="s1" description="assert on a group reference - DFDL-7-050R">
-
<tdml:document><![CDATA[Shirts,30]]></tdml:document>
<tdml:errors>
- <tdml:error>Assert</tdml:error>
- <tdml:error>pattern</tdml:error>
+ <tdml:error>Parse Error</tdml:error>
+ <tdml:error>Assertion</tdml:error>
+ <tdml:error>Pattern</tdml:error>
+ <tdml:error>\p{L}{3},\d{3}</tdml:error>
</tdml:errors>
</tdml:parserTestCase>
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section07/external_variables/external_variables.tdml
----------------------------------------------------------------------
diff --git a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section07/external_variables/external_variables.tdml b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section07/external_variables/external_variables.tdml
index f925f6b..b380459 100644
--- a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section07/external_variables/external_variables.tdml
+++ b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section07/external_variables/external_variables.tdml
@@ -353,6 +353,31 @@
</tdml:dfdlInfoset>
</tdml:infoset>
</tdml:parserTestCase>
+
+ <!-- TODO: The test below doesn't work - left over data.
+ Furthermore, TDML runner doesn't currently compare attributes, so
+ cannot detect the error we're trying to detect, which is spurious
+ presence of a xmlns="" in the root element of the result infoset.
+ There is a ticket Daffodil-1846 about making the TDML runner not strip
+ off the attributes - presumably also namespace bindings. -->
+ <tdml:parserTestCase name="testNoRootUnnecessaryBinding"
+ root="row2" model="edu.illinois/ncsa/daffodil/section07/external_variables/external_variables.dfdl.xsd"
+ config="edu.illinois/ncsa/daffodil/section07/external_variables/daffodil_config_cli_test.xml"
+ description="Root XML should not have xmlns='' in it. "
+ roundTrip="false">
+
+ <tdml:document></tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <tns:row2 xmlns:tns="http://example.com"> <!-- should not have xmlns="" -->
+ <cell>-9</cell>
+ <cell>-2</cell>
+ <cell>-8</cell>
+ </tns:row2>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+
+ </tdml:parserTestCase>
</tdml:testSuite>
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section14/sequence_groups/SequenceGroupDelimiters.tdml
----------------------------------------------------------------------
diff --git a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section14/sequence_groups/SequenceGroupDelimiters.tdml b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section14/sequence_groups/SequenceGroupDelimiters.tdml
index 93cf2b1..567ca7d 100644
--- a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section14/sequence_groups/SequenceGroupDelimiters.tdml
+++ b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section14/sequence_groups/SequenceGroupDelimiters.tdml
@@ -357,7 +357,8 @@
<tdml:parserTestCase name="groupRefInheritProps"
root="list" model="groupRefInheritProps.xsd"
- description="separator defined on a group reference - DFDL-14-008R">
+ description="separator defined on a group reference - DFDL-14-008R"
+ roundTrip="false">
<tdml:document><![CDATA[Shirts,Sold on Monday,30,$17.99||Shoes,Sold on Tuesday,23,$89.99]]></tdml:document>
<tdml:infoset>
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section23/dfdl_expressions/expressions2.tdml
----------------------------------------------------------------------
diff --git a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section23/dfdl_expressions/expressions2.tdml b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section23/dfdl_expressions/expressions2.tdml
index 2baca72..689d48b 100644
--- a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section23/dfdl_expressions/expressions2.tdml
+++ b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section23/dfdl_expressions/expressions2.tdml
@@ -159,7 +159,6 @@
<tdml:error>past root element</tdml:error>
<tdml:error>ex:f1</tdml:error>
<tdml:error>line</tdml:error>
- <tdml:error>column</tdml:error>
<tdml:error>../ex:f2</tdml:error>
</tdml:errors>
</tdml:parserTestCase>
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-test/src/test/scala-debug/edu/illinois/ncsa/daffodil/section07/external_variables/TestExternalVariablesDebug.scala
----------------------------------------------------------------------
diff --git a/daffodil-test/src/test/scala-debug/edu/illinois/ncsa/daffodil/section07/external_variables/TestExternalVariablesDebug.scala b/daffodil-test/src/test/scala-debug/edu/illinois/ncsa/daffodil/section07/external_variables/TestExternalVariablesDebug.scala
new file mode 100644
index 0000000..a2811a1
--- /dev/null
+++ b/daffodil-test/src/test/scala-debug/edu/illinois/ncsa/daffodil/section07/external_variables/TestExternalVariablesDebug.scala
@@ -0,0 +1,57 @@
+/* Copyright (c) 2017 Tresys Technology, LLC. All rights reserved.
+ *
+ * Developed by: Tresys Technology, LLC
+ * http://www.tresys.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal with
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimers.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimers in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the names of Tresys Technology, nor the names of its contributors
+ * may be used to endorse or promote products derived from this Software
+ * without specific prior written permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
+ * SOFTWARE.
+ */
+
+package edu.illinois.ncsa.daffodil.section07.external_variables
+
+import edu.illinois.ncsa.daffodil.tdml.DFDLTestSuite
+import org.junit.Test
+import edu.illinois.ncsa.daffodil.util._
+
+class TestExternalVariablesDebug {
+
+ val testDir = "/edu/illinois/ncsa/daffodil/section07/external_variables/"
+ val tdml = testDir + "external_variables.tdml"
+
+ lazy val runner = new DFDLTestSuite(Misc.getRequiredResource(tdml))
+
+ // It's important to note here that external variables
+ // via the TDMLRunner are currently passed in during
+ // compilation.
+
+ //
+ // Use to reproduce CLI test test_2360_CLI_Parsing_SimpleParse_stdOut_extVars2
+ // TODO: When Daffodil-1846 is fixed this test could be enabled.
+ @Test
+ def test_testNoRootUnnecessaryBinding(): Unit = {
+ runner.trace.runOneTest("testNoRootUnnecessaryBinding")
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-test/src/test/scala-new/edu/illinois/ncsa/daffodil/section07/external_variables/TestExternalVariablesNew.scala
----------------------------------------------------------------------
diff --git a/daffodil-test/src/test/scala-new/edu/illinois/ncsa/daffodil/section07/external_variables/TestExternalVariablesNew.scala b/daffodil-test/src/test/scala-new/edu/illinois/ncsa/daffodil/section07/external_variables/TestExternalVariablesNew.scala
index 8e000c4..240149d 100644
--- a/daffodil-test/src/test/scala-new/edu/illinois/ncsa/daffodil/section07/external_variables/TestExternalVariablesNew.scala
+++ b/daffodil-test/src/test/scala-new/edu/illinois/ncsa/daffodil/section07/external_variables/TestExternalVariablesNew.scala
@@ -52,5 +52,4 @@ class TestExternalVariablesNew {
@Test def test_read_config_from_file() {
runner.runOneTest("read_config_from_file")
}
-
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-test/src/test/scala-new/edu/illinois/ncsa/daffodil/section14/sequence_groups/TestSequenceGroups3.scala
----------------------------------------------------------------------
diff --git a/daffodil-test/src/test/scala-new/edu/illinois/ncsa/daffodil/section14/sequence_groups/TestSequenceGroups3.scala b/daffodil-test/src/test/scala-new/edu/illinois/ncsa/daffodil/section14/sequence_groups/TestSequenceGroups3.scala
index a84ccf9..af7b9d4 100644
--- a/daffodil-test/src/test/scala-new/edu/illinois/ncsa/daffodil/section14/sequence_groups/TestSequenceGroups3.scala
+++ b/daffodil-test/src/test/scala-new/edu/illinois/ncsa/daffodil/section14/sequence_groups/TestSequenceGroups3.scala
@@ -41,7 +41,7 @@ object TestSequenceGroups3 {
val testDir_01 = "/edu/illinois/ncsa/daffodil/section14/sequence_groups/"
val runner_01 = Runner(testDir_01, "SequenceGroupDelimiters.tdml")
- var runner_02 = Runner(testDir_01, "SequenceGroup.tdml", validateTDMLFile = false)
+ val runner_02 = Runner(testDir_01, "SequenceGroup.tdml", validateTDMLFile = false)
@AfterClass def shutDown {
runner_01.reset
[4/6] incubator-daffodil git commit: Property Resolution - part of
fixing schema compilation
Posted by mb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SequenceGroup.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SequenceGroup.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SequenceGroup.scala
index ab4478c..cdc68e1 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SequenceGroup.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SequenceGroup.scala
@@ -48,9 +48,14 @@ import edu.illinois.ncsa.daffodil.Implicits.ns2String
import edu.illinois.ncsa.daffodil.grammar.SequenceGrammarMixin
import edu.illinois.ncsa.daffodil.exceptions.Assert
import edu.illinois.ncsa.daffodil.processors.SequenceRuntimeData
-
-class Sequence(xmlArg: Node, parent: SchemaComponent, position: Int)
- extends ModelGroup(xmlArg, parent, position)
+import edu.illinois.ncsa.daffodil.schema.annotation.props.Found
+import edu.illinois.ncsa.daffodil.schema.annotation.props.PropertyLookupResult
+
+abstract class SequenceTermBase(
+ final override val xml: Node,
+ final override val parent: SchemaComponent,
+ final override val position: Int)
+ extends ModelGroup
with Sequence_AnnotationMixin
with SequenceRuntimeValuedPropertiesMixin
with SequenceGrammarMixin
@@ -59,56 +64,13 @@ class Sequence(xmlArg: Node, parent: SchemaComponent, position: Int)
requiredEvaluations(checkIfValidUnorderedSequence)
requiredEvaluations(modelGroupRuntimeData.preSerialization)
+ protected def apparentXMLChildren: Seq[Node]
+
final override lazy val myPeers = sequencePeers
final override lazy val hasDelimiters = hasInitiator || hasTerminator || hasSeparator
- protected final def annotationFactory(node: Node): Option[DFDLAnnotation] = {
- node match {
- case <dfdl:sequence>{ contents @ _* }</dfdl:sequence> => Some(new DFDLSequence(node, this))
- case _ => annotationFactoryForDFDLStatement(node, this)
- }
- }
-
- protected final def emptyFormatFactory = new DFDLSequence(newDFDLAnnotationXML("sequence"), this)
- protected final def isMyFormatAnnotation(a: DFDLAnnotation) = a.isInstanceOf[DFDLSequence]
-
- // The dfdl:hiddenGroupRef property cannot be scoped, nor defaulted. It's really a special
- // attribute, not a format property in the usual sense.
- // So we retrieve it by this lower-level mechanism which only combines short and long form.
- //
- // FIXME: must call findPropertyOption so that it gets a context back which
- // allows resolution of a QName using the right scope.
- final lazy val hiddenGroupRefOption = getPropertyOption("hiddenGroupRef")
-
- /**
- * We're hidden if we're inside something hidden, or we're explicitly a
- * hidden group reference (sequence with hiddenGroupRef property)
- */
- final override lazy val isHidden = {
- val res = hiddenGroupRefOption match {
- case Some(_) => true
- case None => someEnclosingComponent.isHidden
- }
- res
- }
-
- private lazy val <sequence>{ apparentXMLChildren @ _* }</sequence> = xml
-
- final def xmlChildren = LV('xmlChildren) {
- hiddenGroupRefOption match {
- case Some(qname) => {
- schemaDefinitionUnless(apparentXMLChildren.length == 0, "A sequence with hiddenGroupRef cannot have children.")
- // synthesize a group reference here.
- val contextScope = xml.asInstanceOf[Elem].scope
- val hgr = {
- (<xs:group xmlns:xs={ XMLUtils.xsdURI } ref={ qname }/>).copy(scope = contextScope)
- }
- List(hgr)
- }
- case None => apparentXMLChildren
- }
- }.value
+ protected def hiddenGroupRefOption: PropertyLookupResult
final lazy val hasStaticallyRequiredInstances = {
// true if there are syntactic features
@@ -118,16 +80,16 @@ class Sequence(xmlArg: Node, parent: SchemaComponent, position: Int)
}
final override def hasKnownRequiredSyntax = LV('hasKnownRequiredSyntax) {
- lazy val memberHasRequiredSyntax = groupMembersNoRefs.exists(_.hasKnownRequiredSyntax)
+ lazy val memberHasRequiredSyntax = groupMembers.exists(_.hasKnownRequiredSyntax)
lazy val prefixOrPostfixAndStaticallyRequiredInstance =
- groupMembersNoRefs.filter { _.isRepresented }.exists { _.hasStaticallyRequiredInstances } &&
+ groupMembers.filter { _.isRepresented }.exists { _.hasStaticallyRequiredInstances } &&
(hasPrefixSep || hasPostfixSep)
lazy val infixAnd2OrMoreStaticallyRequiredInstances =
- groupMembersNoRefs.filter { m => m.isRepresented && m.hasStaticallyRequiredInstances }.length > 1 && hasInfixSep
+ groupMembers.filter { m => m.isRepresented && m.hasStaticallyRequiredInstances }.length > 1 && hasInfixSep
lazy val sepAndArryaWith2OrMoreStaticallyRequiredInstances =
- groupMembersNoRefs.filter { m =>
+ groupMembers.filter { m =>
m.isRepresented && m.hasStaticallyRequiredInstances && (m match {
- case e: LocalElementBase => e.minOccurs > 1
+ case e: ElementBase => e.minOccurs > 1
case _ => false
})
}.length > 0 && hasSeparator
@@ -153,9 +115,9 @@ class Sequence(xmlArg: Node, parent: SchemaComponent, position: Int)
}
private def checkMembersHaveValidOccursCountKind: Unit = {
- val validChildren: Seq[LocalElementBase] =
+ val validChildren: Seq[ElementBase] =
groupMembers.filter { m => m.isInstanceOf[LocalElementDecl] || m.isInstanceOf[ElementRef]
- }.map(_.asInstanceOf[LocalElementBase])
+ }.map(_.asInstanceOf[ElementBase])
val invalidChildren = validChildren.filter(e => {
if (e.minOccurs == 0 | !e.isScalar) {
@@ -203,7 +165,8 @@ class Sequence(xmlArg: Node, parent: SchemaComponent, position: Int)
def checkHiddenSequenceIsDefaultableOrOVC: Unit = {
if (this.isHidden) {
- val nonDefaultableOrOVC = this.childrenInHiddenGroupNotDefaultableOrOVC
+ val nonDefaultableOrOVC =
+ this.childrenInHiddenGroupNotDefaultableOrOVC
if (nonDefaultableOrOVC.length > 0) {
this.SDE("Element(s) of hidden group must define dfdl:outputValueCalc:\n%s", nonDefaultableOrOVC.mkString("\n"))
}
@@ -260,7 +223,7 @@ class Sequence(xmlArg: Node, parent: SchemaComponent, position: Int)
// Constructs a sequence of choice using newContent
val newXML = {
- xmlArg match {
+ xml match {
case Elem(prefix, "sequence", attrs, scope, content @ _*) => Elem(prefix, "sequence", attrs, scope, true, newContent: _*)
case other => other
}
@@ -296,6 +259,70 @@ class Sequence(xmlArg: Node, parent: SchemaComponent, position: Int)
}
+/**
+ * Captures concepts associated with definitions of Sequence groups.
+ *
+ * Used by GlobalSequenceGroupDef and local Sequence, but not by SequenceGroupRef.
+ * Used on objects that can carry DFDLSequence annotation objects.
+ */
+trait SequenceDefMixin
+ extends AnnotatedSchemaComponent
+ with GroupDefLike {
+
+ protected final def isMyFormatAnnotation(a: DFDLAnnotation) = a.isInstanceOf[DFDLSequence]
+
+ protected final def annotationFactory(node: Node): Option[DFDLAnnotation] = {
+ node match {
+ case <dfdl:sequence>{ contents @ _* }</dfdl:sequence> => Some(new DFDLSequence(node, this))
+ case _ => annotationFactoryForDFDLStatement(node, this)
+ }
+ }
+
+ protected final def emptyFormatFactory = new DFDLSequence(newDFDLAnnotationXML("sequence"), this)
+
+ final lazy val <sequence>{ apparentXMLChildren @ _* }</sequence> = (xml \\ "sequence")(0)
+
+ final def xmlChildren = apparentXMLChildren
+
+ // The dfdl:hiddenGroupRef property cannot be scoped, nor defaulted. It's really a special
+ // attribute, not a format property in the usual sense.
+ // So we retrieve it by this lower-level mechanism which only combines short and long form.
+ //
+ final lazy val hiddenGroupRefOption =
+ findPropertyOptionThisComponentOnly("hiddenGroupRef")
+
+}
+
+/**
+ * Represents a local sequence definition.
+ */
+class Sequence(xmlArg: Node, parent: SchemaComponent, position: Int)
+ extends SequenceTermBase(xmlArg, parent, position)
+ with SequenceDefMixin {
+
+ requiredEvaluations(checkHiddenGroupRefHasNoChildren)
+
+ override lazy val optReferredToComponent = None
+
+ private lazy val checkHiddenGroupRefHasNoChildren = {
+ if (hiddenGroupRefOption.isDefined) {
+ val axc = apparentXMLChildren
+ val len = axc.length
+ schemaDefinitionUnless(len == 0, "A sequence with hiddenGroupRef cannot have children.")
+ }
+ }
+
+ final lazy val hiddenGroupRefXML = LV('hiddenGroupRefXML) {
+ val Found(qname, _, _, _) = hiddenGroupRefOption
+ // synthesize a group reference here.
+ val contextScope = xml.asInstanceOf[Elem].scope
+ val hgr = {
+ (<xs:group xmlns:xs={ XMLUtils.xsdURI } ref={ qname }/>).copy(scope = contextScope)
+ }
+ hgr
+ }.value
+}
+
final class UnorderedSequence(xmlArg: Node, xmlContents: Seq[Node], parent: SchemaComponent, position: Int)
extends Sequence(xmlArg, parent, position) {
// A shell, the actual XML representation is passed in
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SimpleTypes.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SimpleTypes.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SimpleTypes.scala
index 3f84b91..1e61aec 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SimpleTypes.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SimpleTypes.scala
@@ -43,6 +43,16 @@ trait TypeBase {
def optRestriction: Option[Restriction] = None
def optUnion: Option[Union] = None
def typeNode: NodeInfo.AnyType.Kind
+
+}
+
+trait NonPrimTypeMixin {
+ def elementDecl: ElementDeclMixin
+
+ def elementBase: ElementBase = elementDecl match {
+ case eb: ElementBase => eb
+ case ged: GlobalElementDecl => ged.elementRef
+ }
}
sealed trait SimpleTypeBase extends TypeBase {
@@ -122,15 +132,14 @@ object PrimitiveType {
}
-abstract class SimpleTypeDefBase(xmlArg: Node, override val parent: SchemaComponent)
- extends AnnotatedSchemaComponent(xmlArg, parent)
+abstract class SimpleTypeDefBase(xml: Node, parent: SchemaComponent)
+ extends AnnotatedSchemaComponentImpl(xml, parent)
with SimpleTypeBase
- with DFDLStatementMixin
+ with NonPrimTypeMixin
+ with ProvidesDFDLStatementMixin
with OverlapCheckMixin {
- requiredEvaluations(if (element.isSimpleType) simpleTypeRuntimeData.preSerialization)
-
- def element: ElementBase
+ requiredEvaluations(if (elementDecl.isSimpleType) simpleTypeRuntimeData.preSerialization)
override def typeNode = primType
@@ -141,25 +150,14 @@ abstract class SimpleTypeDefBase(xmlArg: Node, override val parent: SchemaCompon
res
}
+ /**
+ * Exclusive of self.
+ */
final lazy val bases: Seq[SimpleTypeDefBase] =
if (restrictions.isEmpty) Nil
else restrictions.tail.map { _.simpleType }
- private lazy val sTypeNonDefault: Seq[ChainPropProvider] = bases.reverse.map { _.nonDefaultFormatChain }
- private lazy val sTypeDefault: Seq[ChainPropProvider] = bases.reverse.map { _.defaultFormatChain }
-
- // want a QueueSet i.e., fifo order if iterated, but duplicates
- // kept out of the set. Will simulate by calling distinct.
- def nonDefaultPropertySources = LV('nonDefaultPropertySources) {
- val seq = (this.nonDefaultFormatChain +: sTypeNonDefault).distinct
- checkNonOverlap(seq)
- seq
- }.value
-
- def defaultPropertySources = LV('defaultPropertySources) {
- val seq = (this.defaultFormatChain +: sTypeDefault).distinct
- seq
- }.value
+ override final def optReferredToComponent = optRestriction.flatMap { _.optBaseDef }
protected final def emptyFormatFactory = new DFDLSimpleType(newDFDLAnnotationXML("simpleType"), this)
@@ -168,7 +166,7 @@ abstract class SimpleTypeDefBase(xmlArg: Node, override val parent: SchemaCompon
protected final def annotationFactory(node: Node): Option[DFDLAnnotation] = {
node match {
case <dfdl:simpleType>{ contents @ _* }</dfdl:simpleType> => Some(new DFDLSimpleType(node, this))
- case _ => annotationFactoryForDFDLStatement(node, this)
+ case _ => annotationFactoryForDFDLStatement(node, elementBase)
}
}
@@ -183,33 +181,6 @@ abstract class SimpleTypeDefBase(xmlArg: Node, override val parent: SchemaCompon
}
}
- /**
- * Combine our statements with those of our base def (if there is one)
- *
- * The order is important here. I.e., we FIRST put in each list those from our base. Then our own local ones.
- */
- final lazy val statements: Seq[DFDLStatement] =
- bases.flatMap { _.statements } ++ localStatements
-
- private lazy val optBaseDef = optRestriction.flatMap { _.optBaseDef }
-
- // TODO: refactor into shared code for combining all the annotations in the resolved set of annotations
- // for a particular annotation point, checking that there is only one format annotation, that
- // asserts and discriminators are properly excluding each-other, etc.
- // Code should be sharable for many kinds of annotation points, perhaps specialized for groups, complex type
- // elements, and simple type elements.
- //
- // See JIRA issue DFDL-481
- final lazy val newVariableInstanceStatements: Seq[DFDLNewVariableInstance] =
- optBaseDef.map { _.newVariableInstanceStatements }.getOrElse(Seq.empty) ++ localNewVariableInstanceStatements
- final lazy val (discriminatorStatements, assertStatements) = checkDiscriminatorsAssertsDisjoint(combinedDiscrims, combinedAsserts)
- private lazy val combinedAsserts: Seq[DFDLAssert] = optBaseDef.map { _.assertStatements }.getOrElse(Nil) ++ localAssertStatements
- private lazy val combinedDiscrims: Seq[DFDLDiscriminator] = optBaseDef.map { _.discriminatorStatements }.getOrElse(Nil) ++ localDiscriminatorStatements
-
- final lazy val setVariableStatements: Seq[DFDLSetVariable] = {
- val combinedSvs = optBaseDef.map { _.setVariableStatements }.getOrElse(Nil) ++ localSetVariableStatements
- checkDistinctVariableNames(combinedSvs)
- }
def toOpt[R <: AnyRef](b: Boolean, v: => R) = Misc.boolToOpt(b, v)
lazy val simpleTypeRuntimeData: SimpleTypeRuntimeData = {
@@ -219,7 +190,7 @@ abstract class SimpleTypeDefBase(xmlArg: Node, override val parent: SchemaCompon
diagnosticDebugName,
path,
namespaces,
- element.simpleType.primType,
+ primType,
noFacetChecks,
//
// TODO: Cleanup code: really these should all have been option types
@@ -250,29 +221,13 @@ abstract class SimpleTypeDefBase(xmlArg: Node, override val parent: SchemaCompon
}.getOrElse(true)
}
-sealed abstract class SimpleTypeDefFactory(xml: Node, schemaDocumentArg: SchemaDocument)
- extends SchemaComponentFactory(xml, schemaDocumentArg) {
-
-}
-
-final class LocalSimpleTypeDefFactory(xmlArg: Node, schemaDocumentArg: SchemaDocument)
- extends SimpleTypeDefFactory(xmlArg, schemaDocumentArg)
- with LocalNonElementComponentMixin {
-
- def forElement(element: ElementBase) =
- new LocalSimpleTypeDef(this, element)
-
-}
-
final class LocalSimpleTypeDef(
- val factory: LocalSimpleTypeDefFactory,
- elementArg: ElementBase)
- extends SimpleTypeDefBase(factory.xml, elementArg)
+ xmlArg: Node, elementArg: ElementDeclMixin)
+ extends SimpleTypeDefBase(xmlArg, elementArg)
with LocalNonElementComponentMixin
with NestingLexicalMixin {
- override def term = element
- override lazy val element = elementArg
+ override lazy val elementDecl = elementArg
/**
* For anonymous simple type def, uses the base name, or primitive type name
@@ -303,13 +258,13 @@ final class LocalSimpleTypeDef(
*/
final class GlobalSimpleTypeDefFactory(xmlArg: Node, schemaDocumentArg: SchemaDocument)
- extends SimpleTypeDefFactory(xmlArg, schemaDocumentArg)
+ extends SchemaComponentFactory(xmlArg, schemaDocumentArg)
with GlobalNonElementComponentMixin {
/**
* Create a private instance for this element's use.
*/
- def forElement(element: ElementBase) = new GlobalSimpleTypeDef(None, this, Some(element))
+ def forElement(elementDecl: ElementDeclMixin) = new GlobalSimpleTypeDef(None, this, Some(elementDecl))
def forDerivedType(derivedType: SimpleTypeDefBase) = new GlobalSimpleTypeDef(Some(derivedType), this, None)
}
@@ -320,12 +275,12 @@ final class GlobalSimpleTypeDefFactory(xmlArg: Node, schemaDocumentArg: SchemaDo
final class GlobalSimpleTypeDef(
derivedType: Option[SimpleTypeDefBase],
val factory: GlobalSimpleTypeDefFactory,
- val referringElement: Option[ElementBase])
+ val referringElement: Option[ElementDeclMixin])
extends SimpleTypeDefBase(factory.xml, factory.schemaDocument)
with GlobalNonElementComponentMixin
with NestingTraversesToReferenceMixin {
- override def term = element
+ // override def term = element
override lazy val referringComponent: Option[SchemaComponent] =
(derivedType, referringElement) match {
@@ -334,9 +289,9 @@ final class GlobalSimpleTypeDef(
case _ => Assert.impossible("SimpleType must either have a derivedType or an element. Not both.")
}
- override lazy val element: ElementBase = referringComponent match {
- case Some(dt: SimpleTypeDefBase) => dt.element
- case Some(e: ElementBase) => e
+ override lazy val elementDecl: ElementDeclMixin = referringComponent match {
+ case Some(dt: SimpleTypeDefBase) => dt.elementDecl
+ case Some(e: ElementDeclMixin) => e
case _ => Assert.invariantFailed("unexpected referringComponent")
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/Term.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/Term.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/Term.scala
index 1b7fae3..fad0853 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/Term.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/Term.scala
@@ -33,8 +33,6 @@
package edu.illinois.ncsa.daffodil.dsom
import java.util.UUID
-import scala.xml.Node
-import scala.xml._
import edu.illinois.ncsa.daffodil.exceptions.Assert
import edu.illinois.ncsa.daffodil.processors.TermRuntimeData
import edu.illinois.ncsa.daffodil.grammar.TermGrammarMixin
@@ -43,19 +41,28 @@ import java.lang.{ Integer => JInt }
import edu.illinois.ncsa.daffodil.schema.annotation.props.Found
import edu.illinois.ncsa.daffodil.schema.annotation.props.gen.NilKind
-/////////////////////////////////////////////////////////////////
-// Groups System
-/////////////////////////////////////////////////////////////////
-
-// A term is content of a group
-abstract class Term(xmlArg: Node, parentArg: SchemaComponent, val position: Int)
- extends AnnotatedSchemaComponent(xmlArg, parentArg)
+/**
+ * Term, and what is and isn't a Term, is a key concept in DSOM.
+ *
+ * From elements, ElementRef and LocalElementDecl are Term. A GlobalElementDecl is *not* a Term.
+ * From sequences, Sequence and SequenceGroupRef are Term. GlobalSequenceGroupDef is *not* a Term.
+ * From choices, Choice and ChoiceGroupRef are Term. GlobalChoiceGroupDef is *not* a Term.
+ *
+ * Terms are the things we actually generate parsers/unparsers for. Non-Terms just
+ * contribute information used by Terms.
+ */
+trait Term
+ extends AnnotatedSchemaComponent
+ with ResolvesProperties
+ with ResolvesDFDLStatementMixin
with TermRuntimeValuedPropertiesMixin
with TermGrammarMixin
with DelimitedRuntimeValuedPropertiesMixin
with InitiatedTerminatedMixin
with TermEncodingMixin {
+ def position: Int
+
def optIgnoreCase: Option[YesNo] = {
val ic = cachePropertyOption("ignoreCase")
ic match {
@@ -64,8 +71,6 @@ abstract class Term(xmlArg: Node, parentArg: SchemaComponent, val position: Int)
}
}
- override final def term = this
-
/**
* A scalar means has no dimension. Exactly one occurrence.
*
@@ -115,15 +120,6 @@ abstract class Term(xmlArg: Node, parentArg: SchemaComponent, val position: Int)
def elementChildren: Seq[ElementBase]
- override lazy val dpathCompileInfo =
- new DPathCompileInfo(
- enclosingComponent.map { _.dpathCompileInfo },
- variableMap,
- namespaces,
- path,
- schemaFileLocation,
- tunable)
-
/**
* An integer which is the alignment of this term. This takes into account the
* representation, type, charset encoding and alignment-related properties.
@@ -153,6 +149,9 @@ abstract class Term(xmlArg: Node, parentArg: SchemaComponent, val position: Int)
* base class. This is to make it clear
* we're not talking about the XML structures inside the XML parent (which might
* include annotations, etc.
+ *
+ * For elements this is Nil for simple types, a single model group for
+ * complex types. For model groups there can be more children.
*/
def termChildren: Seq[Term]
@@ -166,9 +165,8 @@ abstract class Term(xmlArg: Node, parentArg: SchemaComponent, val position: Int)
lazy val someEnclosingComponent = enclosingComponent.getOrElse(Assert.invariantFailed("All terms except a root element have an enclosing component."))
- lazy val referredToComponent = this // override in ElementRef and GroupRef
-
- lazy val isRepresented = true // overridden by elements, which might have inputValueCalc turning this off
+ /** Overridden as false for elements with dfdl:inputValueCalc property. */
+ lazy val isRepresented = true
/**
* nearestEnclosingSequence
@@ -182,36 +180,36 @@ abstract class Term(xmlArg: Node, parentArg: SchemaComponent, val position: Int)
* This is why we have to have the GlobalXYZDefFactory stuff. Because this kind of back
* pointer (contextual sensitivity) prevents sharing.
*/
- final lazy val nearestEnclosingSequence: Option[Sequence] = enclosingTerm match {
+ final lazy val nearestEnclosingSequence: Option[SequenceTermBase] = enclosingTerm match {
case None => None
- case Some(s: Sequence) => Some(s)
+ case Some(s: SequenceTermBase) => Some(s)
case Some(_) => enclosingTerm.get.nearestEnclosingSequence
}
- final lazy val nearestEnclosingChoiceBeforeSequence: Option[Choice] = enclosingTerm match {
+ final lazy val nearestEnclosingChoiceBeforeSequence: Option[ChoiceTermBase] = enclosingTerm match {
case None => None
- case Some(s: Sequence) => None
- case Some(c: Choice) => Some(c)
+ case Some(s: SequenceTermBase) => None
+ case Some(c: ChoiceTermBase) => Some(c)
case Some(_) => enclosingTerm.get.nearestEnclosingChoiceBeforeSequence
}
- final lazy val nearestEnclosingUnorderedSequence: Option[Sequence] = enclosingTerm match {
+ final lazy val nearestEnclosingUnorderedSequence: Option[SequenceTermBase] = enclosingTerm match {
case None => None
- case Some(s: Sequence) if !s.isOrdered => Some(s)
+ case Some(s: SequenceTermBase) if !s.isOrdered => Some(s)
case Some(_) => enclosingTerm.get.nearestEnclosingUnorderedSequence
}
- final lazy val nearestEnclosingUnorderedSequenceBeforeSequence: Option[Sequence] = enclosingTerm match {
+ final lazy val nearestEnclosingUnorderedSequenceBeforeSequence: Option[SequenceTermBase] = enclosingTerm match {
case None => None
- case Some(s: Sequence) if !s.isOrdered => Some(s)
- case Some(s: Sequence) => None
+ case Some(s: SequenceTermBase) if !s.isOrdered => Some(s)
+ case Some(s: SequenceTermBase) => None
case Some(_) => enclosingTerm.get.nearestEnclosingUnorderedSequence
}
final lazy val inChoiceBeforeNearestEnclosingSequence: Boolean = enclosingTerm match {
case None => false
- case Some(s: Sequence) => false
- case Some(c: Choice) => true
+ case Some(s: SequenceTermBase) => false
+ case Some(c: ChoiceTermBase) => true
case Some(_) => enclosingTerm.get.inChoiceBeforeNearestEnclosingSequence
}
@@ -221,47 +219,6 @@ abstract class Term(xmlArg: Node, parentArg: SchemaComponent, val position: Int)
case Some(_) => enclosingTerm.get.nearestEnclosingElement
}
- final lazy val nearestEnclosingElementNotRef: Option[ElementBase] = nearestEnclosingElement match {
- case None => None
- case Some(er: ElementRef) => er.nearestEnclosingElement // can't be an element ref again
- case x => x
- }
-
- protected final def thisTermNoRefs: Term = LV('thisTermNoRefs) {
- val es = nearestEnclosingSequence
-
- val thisTerm = this match {
- case eRef: ElementRef => eRef.referencedElement
- // case gd: GlobalGroupDef => gd.thisTermNoRefs // TODO: scala 2.10 compiler says this line is impossible.
- case gb: GroupBase if gb.enclosingTerm.isDefined => {
- // We're a group. We need to determine what we're enclosed by.
- gb.enclosingTerm.get match {
- case encGRef: GroupRef => {
- // We're enclosed by a GroupRef. We need to retrieve
- // what encloses that GroupRef
-
- val res = encGRef.enclosingTerm match {
- case None => encGRef.group
- case Some(encTerm) => encTerm.thisTermNoRefs
- }
- //encGRef.thisTerm
- res
- }
- case encGB: GroupBase if es.isDefined && encGB == es.get => {
- // We're an immediate child of the nearestEnclosingSequence
- // therefore we just return our self as the Term
- this
- }
- case e: LocalElementBase => e // Immediate enclosed by LocalElementBase, return it.
- case _ => gb.group
- }
- }
- case gb: GroupBase => gb.group
- case x => x
- }
- thisTerm
- }.value
-
/**
* We want to determine if we're in an unordered sequence
* at any point along our parents.
@@ -281,22 +238,16 @@ abstract class Term(xmlArg: Node, parentArg: SchemaComponent, val position: Int)
final lazy val immediatelyEnclosingModelGroup: Option[ModelGroup] = {
val res = parent match {
- case c: Choice => Some(c)
- case s: Sequence => Some(s)
+ case c: ChoiceTermBase => Some(c)
+ case s: SequenceTermBase => Some(s)
case d: SchemaDocument => {
- // we're a global object. Our parent is a schema document
- // so follow backpointers to whatever is referencing us.
- this match {
- case ge: GlobalElementDecl => ge.elementRef match {
- case None => {
- // we are root. So there is no enclosing model group at all
- None
- }
- case Some(er) => er.immediatelyEnclosingModelGroup
- }
- }
+ // we must be the Root elementRef
+ Assert.invariant(this.isInstanceOf[Root])
+ None
}
- case gdd: GlobalGroupDef => gdd.groupRef.immediatelyEnclosingModelGroup
+ case gr: GroupRef => gr.asModelGroup.immediatelyEnclosingModelGroup
+ case gdd: GlobalGroupDef => gdd.groupRef.asModelGroup.immediatelyEnclosingModelGroup
+ case ged: GlobalElementDecl => ged.elementRef.immediatelyEnclosingModelGroup
case ct: ComplexTypeBase => {
None
// The above formerly was ct.element.immediatelyEnclosingModelGroup,
@@ -311,16 +262,19 @@ abstract class Term(xmlArg: Node, parentArg: SchemaComponent, val position: Int)
final lazy val positionInNearestEnclosingSequence: Int = {
val res =
if (enclosingComponent == nearestEnclosingSequence) position
+ else if (this.isInstanceOf[Root]) 1
else {
enclosingComponent match {
case Some(term: Term) => term.positionInNearestEnclosingSequence
case Some(ct: ComplexTypeBase) => {
- val ctElem = ct.element
- val ctPos = ctElem.positionInNearestEnclosingSequence
+ val ctPos = ct.elementDecl match {
+ case eb: ElementBase => eb.positionInNearestEnclosingSequence
+ case ged: GlobalElementDecl => ged.elementRef.positionInNearestEnclosingSequence
+ }
ctPos
}
- case Some(ggd: GlobalGroupDef) => ggd.groupRef.positionInNearestEnclosingSequence
- case _ => Assert.invariantFailed("unable to compute position in nearest enclosing sequence")
+ case Some(ggd: GlobalGroupDef) => ggd.groupRef.asModelGroup.positionInNearestEnclosingSequence
+ case x => Assert.invariantFailed("For " + this + " unable to compute position in nearest enclosing sequence. The enclosingComponent was " + x)
}
}
res
@@ -332,7 +286,7 @@ abstract class Term(xmlArg: Node, parentArg: SchemaComponent, val position: Int)
final lazy val allSiblings: Seq[Term] = {
val res = nearestEnclosingSequence.map { enc =>
- val allSiblings = enc.groupMembers.map { _.referredToComponent }
+ val allSiblings = enc.groupMembers
allSiblings
}
res.getOrElse(Nil)
@@ -420,17 +374,19 @@ abstract class Term(xmlArg: Node, parentArg: SchemaComponent, val position: Int)
def isKnownRequiredElement = false
def hasKnownRequiredSyntax = false
- // Returns a tuple, where the first item in the tuple is the list of sibling
- // terms that could appear before this. The second item in the tuple is a
- // One(parent) if all siblings are optional or this element has no prior siblings
+ /**
+ * Returns a tuple, where the first item in the tuple is the list of sibling
+ * terms that could appear before this. The second item in the tuple is a
+ * One(parent) if all siblings are optional or this element has no prior siblings
+ */
lazy val potentialPriorTerms: (Seq[Term], Option[Term]) = {
val (potentialPrior, parent) = enclosingTerm match {
case None => (Seq(), None)
case Some(eb: ElementBase) => (Seq(), Some(eb))
- case Some(ch: Choice) => (Seq(), Some(ch))
- case Some(sq: Sequence) if !sq.isOrdered => (sq.groupMembersNoRefs, Some(sq))
- case Some(sq: Sequence) if sq.isOrdered => {
- val previousTerms = sq.groupMembersNoRefs.takeWhile { _ != this }
+ case Some(ch: ChoiceTermBase) => (Seq(), Some(ch))
+ case Some(sq: SequenceTermBase) if !sq.isOrdered => (sq.groupMembers, Some(sq))
+ case Some(sq: SequenceTermBase) if sq.isOrdered => {
+ val previousTerms = sq.groupMembers.takeWhile { _ != this }
if (previousTerms.isEmpty) {
// first child of seq, the seq is the only previous term
(Seq(), Some(sq))
@@ -473,14 +429,18 @@ abstract class Term(xmlArg: Node, parentArg: SchemaComponent, val position: Int)
*/
lazy val childrenInHiddenGroupNotDefaultableOrOVC: Seq[ElementBase] = {
// this should only be called on hidden elements
- Assert.invariant(this.isHidden)
+ val isH = isHidden
+ Assert.invariant(isH)
val res = this match {
- case s: Sequence => {
- s.groupMembersNoRefs.flatMap { _.childrenInHiddenGroupNotDefaultableOrOVC }
+ case s: SequenceTermBase => {
+ s.groupMembers.flatMap { member =>
+ val res = member.childrenInHiddenGroupNotDefaultableOrOVC
+ res
+ }
}
- case c: Choice => {
- val branches = c.groupMembersNoRefs.map { _.childrenInHiddenGroupNotDefaultableOrOVC }
+ case c: ChoiceTermBase => {
+ val branches = c.groupMembers.map { _.childrenInHiddenGroupNotDefaultableOrOVC }
val countFullyDefaultableOrOVCBranches = branches.count { _.length == 0 }
if (countFullyDefaultableOrOVCBranches == 0) {
c.SDE("xs:choice inside a hidden group must contain a branch with all children having the dfdl:outputValueCalc property set.")
@@ -525,11 +485,226 @@ abstract class Term(xmlArg: Node, parentArg: SchemaComponent, val position: Int)
case mg: ModelGroup => {
val modelGroupCouldHaveSuspensions =
commonCouldHaveSuspensions ||
- mg.groupMembersNoRefs.exists { _.couldHaveSuspensions }
+ mg.groupMembers.exists { _.couldHaveSuspensions }
modelGroupCouldHaveSuspensions
}
}
}
+ final lazy val possibleNextTerms: Seq[Term] = LV('possibleNextTerms) {
+ val es = this.nearestEnclosingSequence
+ val eus = this.nearestEnclosingUnorderedSequenceBeforeSequence
+ val ec = this.nearestEnclosingChoiceBeforeSequence
+
+ val enclosingUnorderedGroup = {
+ (ec, eus) match {
+ case (None, None) => None
+ case (Some(choice), _) => Some(choice)
+ case (None, Some(uoSeq)) => Some(uoSeq)
+ }
+ }
+ val listOfNextTerm = (enclosingUnorderedGroup, es) match {
+ case (None, None) => Seq.empty
+ case (Some(unorderedGroup), _) => {
+ // We're in a choice or unordered sequence
+ //
+ // List must be all of our peers since (as well as our self)
+ // we could be followed by any of them plus
+ // whatever follows the unordered group.
+ val peersCouldBeNext = unorderedGroup.groupMembers
+
+ val termsUntilFirstRequiredTerm = peersCouldBeNext ++ unorderedGroup.possibleNextTerms
+ termsUntilFirstRequiredTerm
+ }
+ case (None, Some(oSeq)) => {
+ // We're in an ordered sequence
+
+ val termsUntilFirstRequiredTerm =
+ isDeclaredLastInSequence match {
+ case true => oSeq.possibleNextTerms
+ case false => {
+
+ val members = oSeq.groupMembers
+
+ val selfAndAfter = members.dropWhile(m => m ne this)
+ val after = selfAndAfter.drop(1)
+ val nextMember = after.headOption
+
+ val nextMembers =
+ nextMember match {
+ case Some(e: ElementBase) if e.isOptional => Seq(e) ++ e.possibleNextTerms
+ case Some(e: ElementBase) => Seq(e)
+ case Some(mg: ModelGroup) => Seq(mg)
+ case None => Nil // Assert.impossibleCase
+ }
+ nextMembers
+ }
+ }
+ termsUntilFirstRequiredTerm
+ }
+ }
+ listOfNextTerm
+ }.value
+
+ final def isDeclaredLastInSequence = LV('isDeclaredLastInSequence) {
+ val es = nearestEnclosingSequence
+ // how do we determine what child node we are? We search.
+ // TODO: better structure for O(1) answer to this.
+ es match {
+ case None => Assert.invariantFailed("We are not in a sequence therefore isDeclaredLastInSequence is an invalid question.")
+ case Some(s) => {
+ val members = s.groupMembers
+ if (members.last eq this) true // we want object identity comparison here, not equality.
+ else false
+ }
+ }
+ }.value
+
+ protected def possibleFirstChildTerms: Seq[Term]
+
+ /*
+ * Returns list of Elements that could be the first child in the infoset of this model group or element.
+ */
+ final def possibleFirstChildElementsInInfoset: Seq[ElementBase] = LV('possibleFirstChildElementsInInfoset) {
+ val pfct = possibleFirstChildTerms
+ val firstChildren = pfct.flatMap {
+ case e: ElementBase if e.isHidden => Nil
+ case e: ElementBase => Seq(e)
+ case s: SequenceTermBase if s.isHidden => Nil
+ case mg: ModelGroup => mg.possibleFirstChildElementsInInfoset
+ }
+ firstChildren.distinct
+ }.value
+
+ /*
+ * Returns a list of Elements that could follow this Term, including
+ * siblings, children of siblings, and siblings of the parent and their children.
+ *
+ * What stops this is when the end of an enclosing element has to be next.
+ */
+ final def possibleNextChildElementsInInfoset: Seq[ElementBase] = LV('possibleNextChildElementsInInfoset) {
+ val arrayNext = if (isArray) Seq(this.asInstanceOf[ElementBase]) else Nil
+
+ val nextSiblingElements = {
+ val poss = possibleNextSiblingTerms
+ val res = poss.flatMap {
+ possible =>
+ possible match {
+ case e: ElementBase => Seq(e)
+ case mg: ModelGroup => mg.possibleFirstChildElementsInInfoset
+ }
+ }
+ res
+ }
+
+ val nextParentElts = nextParentElements
+ val res = arrayNext ++ nextSiblingElements ++ nextParentElts
+ res
+ }.value
+
+ def nextParentElements: Seq[ElementBase]
+
+ protected def couldBeLastElementInModelGroup: Boolean
+
+ /*
+ * Returns a list of sibling Terms that could follow this term. This will not
+ * return any children of sibling Terms, or any siblings of the parent.
+ */
+ final def possibleNextSiblingTerms: Seq[Term] = LV('possibleNextSiblingTerms) {
+ val et = enclosingTerm
+ val listOfNextTerm = et match {
+ case None => Nil // root element, has no siblings
+ case Some(e: ElementBase) => Nil // complex element, cannot have another model group other than this one
+ case Some(c: ChoiceTermBase) => Nil // in choice, no other siblings could come after this one
+ case Some(s: SequenceTermBase) if !s.isOrdered => s.groupMembers // unorderd sequence, all siblings (and myself) could be next
+ case Some(s: SequenceTermBase) => {
+ // in a sequence, the next term could be any later sibling that is not
+ // or does not have a required element, up to and including the first
+ // term that is/has a required element
+ // def isOutputValueCalc(term: Term) =
+ // term match { case eb: ElementBase if eb.isOutputValueCalc => true; case _ => false }
+ val selfAndAllNextSiblings = s.groupMembers.dropWhile(_ != this)
+ val allNextSiblings = if (selfAndAllNextSiblings.length > 0) selfAndAllNextSiblings.tail else Nil
+ val nextSiblings = allNextSiblings // .dropWhile(isOutputValueCalc(_))
+ val (optional, firstRequiredAndLater) = nextSiblings.span {
+ case e: ElementBase => e.canBeAbsentFromUnparseInfoset
+ case mg: ModelGroup => !mg.mustHaveRequiredElement
+ }
+ optional ++ firstRequiredAndLater.take(1)
+ }
+ }
+ listOfNextTerm
+ }.value
+
+ /**
+ * Set of elements referenced from an expression in the scope of this term.
+ *
+ * Specific to certain function call contexts e.g., only elements referenced
+ * by dfdl:valueLength or dfdl:contentLength.
+ *
+ * Separated by parser/unparser since parsers have to derive from
+ * dfdl:inputValueCalc, and must include discriminators and assert test
+ * expressions. Unparsers must derive from dfdl:outputValueCalc and exclude
+ * discriminators and asserts. Both must include setVariable/newVariableInstance,
+ * and property expressions are nearly the same. There are some unparser-specfic
+ * properties that take runtime-valued expressions - dfdl:outputNewLine is
+ * one example.
+ */
+ final lazy val contentLengthParserReferencedElementInfos: Set[DPathElementCompileInfo] = {
+ val propRefs = propertyContentReferencedElementInfos
+ val stmtRefs = statementContentParserReferencedElementInfos
+ val calcRefs = calcContentParserReferencedElementInfos
+ val locRefs = propRefs ++ stmtRefs ++ calcRefs
+ val res = realChildren.foldLeft(locRefs) { (s, i) => s.union(i.contentLengthParserReferencedElementInfos) }
+ res
+ }
+
+ /**
+ * Any element referenced from an expression in the scope of this term
+ * is in this set.
+ */
+ final lazy val contentLengthUnparserReferencedElementInfos: Set[DPathElementCompileInfo] = {
+ val propRefs = propertyContentReferencedElementInfos
+ val stmtRefs = statementContentUnparserReferencedElementInfos
+ val calcRefs = calcContentUnparserReferencedElementInfos
+ val locRefs = propRefs ++ stmtRefs ++ calcRefs
+ val res = realChildren.foldLeft(locRefs) { (s, i) => s.union(i.contentLengthUnparserReferencedElementInfos) }
+ res
+ }
+
+ /**
+ * Any element referenced from an expression in the scope of this term
+ * is in this set.
+ */
+ final lazy val valueLengthParserReferencedElementInfos: Set[DPathElementCompileInfo] = {
+ val propRefs = propertyValueReferencedElementInfos
+ val stmtRefs = statementValueParserReferencedElementInfos
+ val calcRefs = calcValueParserReferencedElementInfos
+ val locRefs = propRefs ++ stmtRefs ++ calcRefs
+ val res = realChildren.foldLeft(locRefs) { (s, i) => s.union(i.valueLengthParserReferencedElementInfos) }
+ res
+ }
+
+ /**
+ * Any element referenced from an expression in the scope of this term
+ * is in this set.
+ */
+ final lazy val valueLengthUnparserReferencedElementInfos: Set[DPathElementCompileInfo] = {
+ val propRefs = propertyValueReferencedElementInfos
+ val stmtRefs = statementValueUnparserReferencedElementInfos
+ val calcRefs = calcValueUnparserReferencedElementInfos
+ val locRefs = propRefs ++ stmtRefs ++ calcRefs
+ val res = realChildren.foldLeft(locRefs) { (s, i) => s.union(i.valueLengthUnparserReferencedElementInfos) }
+ res
+ }
+
+ private lazy val realChildren: Seq[Term] = {
+ this match {
+ case mg: ModelGroup => mg.groupMembers.asInstanceOf[Seq[Term]]
+ case eb: ElementBase if (eb.isComplexType) => Seq(eb.complexType.group)
+ case eb: ElementBase => Seq()
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/TermEncodingMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/TermEncodingMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/TermEncodingMixin.scala
index bdb55a7..4dd1f96 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/TermEncodingMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/TermEncodingMixin.scala
@@ -38,6 +38,11 @@ import edu.illinois.ncsa.daffodil.schema.annotation.props.gen.EncodingErrorPolic
import edu.illinois.ncsa.daffodil.processors.KnownEncodingMixin
import edu.illinois.ncsa.daffodil.io.NonByteSizeCharset
+/**
+ * Captures concepts around dfdl:encoding property and Terms.
+ *
+ * Just factored out into a trait for isolation of related code.
+ */
trait TermEncodingMixin extends KnownEncodingMixin { self: Term =>
requiredEvaluations(encodingInfo.preSerialization)
@@ -114,9 +119,6 @@ trait TermEncodingMixin extends KnownEncodingMixin { self: Term =>
mg.hasNoSkipRegions &&
hasTextAlignment
}
- case gr: GroupRef => {
- gr.group.isLocallyTextOnly
- }
}
res
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/package.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/package.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/package.scala
new file mode 100644
index 0000000..4391be1
--- /dev/null
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/package.scala
@@ -0,0 +1,101 @@
+package edu.illinois.ncsa.daffodil
+
+/**
+ * DSOM - DFDL Schema Object Model
+ *
+ * ==Overview==
+ * DSOM is the abstract syntax "tree" of a DFDL schema. It is not actually a tree, it is
+ * a graph, as there are back-pointers, and shared objects.
+ *
+ * A schema is made up of [[SchemaComponent]] objects. A [[SchemaSet]] is a collection of
+ * [[Schema]]. A schema is a collection of [[SchemaDocument]] that have a common
+ * namespace. The [[SchemaSet]] is the
+ * ultimate root of all the objects in a compilation unit. The [[Term]] class is the
+ * base for everything that can have a representation in the data stream. .
+ *
+ * Many [[SchemaComponent]] carry DFDL annotations; hence, [[AnnotatedSchemaComponent]]
+ * is a key base trait.
+ *
+ * ==UML Class Diagram==
+ *
+ * See the
+ * [[https://cwiki.apache.org/confluence/display/DAFFODIL/DFDL+Schema+Object+Model+%28DSOM%29+with+UML
+ * Daffodil Wiki]]
+ * for class diagrams.
+ *
+ * ==Terminology==
+ *
+ * Parsing - in this description we are talking about the Daffodil Schema Compiler.
+ * So when we refer to "parsing" the XML, we are referring
+ * to the recursive descent walk of the DFDL schema, with that schema represented as Scala's
+ * `scala.xml.Node` objects. Strictly speaking, the string text in files of the DFDL
+ * schema's XML is already parsed into Scala's `scala.xml.Node` objects, but
+ * it is the walk through that structure constructing the DSOM tree/graph that we
+ * refer to as "parsing" the DFDL schema.
+ *
+ * ==Principles of Operation==
+ *
+ * === Constructing the DSOM Graph===
+ *
+ * The DSOM object graph must be constructed by looking at only the XML without
+ * examining any DFDL annotations. The DSOM structure is required in order to
+ * implement DFDL's scoping rules for finding annotations including both
+ * properties (like dfdl:byteOrder) and statements (like dfdl:assert); hence,
+ * one must have the DSOM graph before one can begin
+ * accessing DFDL annotations or you end up in cycles/stack-overflows.
+ *
+ * This requires a careful consideration of class/trait members and methods that
+ * are used when constructing the DSOM graph, and those used after the DSOM
+ * graph has been created, in order to compile it into the runtime data structures.
+ *
+ * There are a few exceptions to the above. The dfdl:hiddenGroupRef attribute is one such. It
+ * must be local to the [[Sequence]] object, and has implications for the parsing
+ * of the XML as it implies there should be no children of that xs:sequence.
+ * Since it is not scoped, the DSOM graph is not needed in order to access it.
+ * Only the local [[Sequence]] object and it's [[DFDLSequence]] annotation object.
+ * The [[AnnotatedSchemaComponent]] trait provides methods for this local-only
+ * property lookup.
+ *
+ * The DSOM object graph is also needed in order to issue good diagnostic
+ * messages from the compiler; hence, Daffodil validates the DFDL schema before
+ * parsing it into the DSOM graph. Careful consideration must be given if a
+ * SchemaDefinitionError (SDE) is issued while constructing the DSOM graph.
+ *
+ * If you run into stack-overflows while the DSOM graph is being constructed, the
+ * above is a common cause of them, as the SDE diagnostic messaging uses DSOM graph
+ * information to construct context information about the error for inclusion
+ * in the messages. If the DSOM graph is still being constructed at that time, then
+ * this can be circular.
+ *
+ * ===Using the DSOM Graph===
+ *
+ * DSOM supports Daffodil schema compilation by way of the
+ * `OOLAG` pattern which
+ * is an object oriented way of using the
+ * [[https://en.wikipedia.org/wiki/Attribute_grammar attribute grammars]] compiler technique.
+ *
+ * Many attributes (in the attribute grammar sense, nothing to do with XML attributes)
+ * are simply Scala lazy val definitions, but some are declared as OOLAG
+ * attributes (using `edu.illinois.ncsa.daffodil.oolag.OOLAG.OOLAGHost.LV`) which
+ * provides for gathering of multiple diagnostic messages (`SchemaDefinitionError`)
+ * before abandoning compilation.
+ *
+ * DFDL schema compilation largely occurs by evaluating lazy val members of DSOM
+ * objects. These include the members of the grammar traits
+ * (@see [[edu.illinois.ncsa.daffodil.grammar]] package), which are mixed
+ * in to the appropriate DSOM traits/classes.
+ *
+ * ===FAQ===
+ * Q: Why invent this? Why not use XSOM, or the Apache XML Schema library?
+ *
+ * A:We had trouble with other XML-schema libraries for
+ * lack of adequate support for annotations, non-native attributes, and schema
+ * documents as first class objects. So DSOM is specific to Daffodil Basically these
+ * libraries are more about implementing XML Schema and validation, and not so
+ * much about a complex language built on the annotations of the schema. DSOM
+ * is really mostly about the annotations.
+ *
+ */
+package object dsom {
+ // This package object is just for scaladoc
+}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/AlignedMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/AlignedMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/AlignedMixin.scala
index 08bfa01..eba81ac 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/AlignedMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/AlignedMixin.scala
@@ -40,8 +40,7 @@ import edu.illinois.ncsa.daffodil.schema.annotation.props.gen.LengthKind
import edu.illinois.ncsa.daffodil.schema.annotation.props.gen.LengthUnits
import edu.illinois.ncsa.daffodil.util.Math
import edu.illinois.ncsa.daffodil.io.NonByteSizeCharset
-
-
+import edu.illinois.ncsa.daffodil.dsom.Root
case class AlignmentMultipleOf(nBits: Long) {
def *(that: AlignmentMultipleOf) = AlignmentMultipleOf(Math.gcd(nBits, that.nBits))
@@ -53,14 +52,12 @@ trait LengthApprox {
val nBits: Long
def +(that: LengthApprox): LengthApprox = (this, that) match {
case (l: LengthExact, r: LengthExact) => LengthExact(l.nBits + r.nBits)
- case (l, r) => LengthMultipleOf(Math.gcd(l.nBits, r.nBits))
+ case (l, r) => LengthMultipleOf(Math.gcd(l.nBits, r.nBits))
}
}
case class LengthExact(nBits: Long) extends LengthApprox
case class LengthMultipleOf(nBits: Long) extends LengthApprox
-
-
trait AlignedMixin extends GrammarMixin { self: Term =>
/**
@@ -84,7 +81,7 @@ trait AlignedMixin extends GrammarMixin { self: Term =>
true
else
false
- } else if (this.rootElement.get.isScannable)
+ } else if (this.rootElementRef.get.isScannable)
true
else
false
@@ -98,7 +95,7 @@ trait AlignedMixin extends GrammarMixin { self: Term =>
true
else
false
- } else if (this.rootElement.get.isScannable)
+ } else if (this.rootElementRef.get.isScannable)
true
else
false
@@ -106,7 +103,6 @@ trait AlignedMixin extends GrammarMixin { self: Term =>
final lazy val hasNoSkipRegions = leadingSkip == 0 && trailingSkip == 0
-
private lazy val alignmentApprox: AlignmentMultipleOf = {
AlignmentMultipleOf(alignmentValueInBits.toLong)
}
@@ -134,7 +130,7 @@ trait AlignedMixin extends GrammarMixin { self: Term =>
}
private lazy val priorAlignmentApprox: AlignmentMultipleOf = {
- if (enclosingComponent.isEmpty) {
+ if (this.isInstanceOf[Root]) {
AlignmentMultipleOf(0) // root is aligned with anything
} else {
val (priorSibs, parent) = potentialPriorTerms
@@ -175,7 +171,7 @@ trait AlignedMixin extends GrammarMixin { self: Term =>
} else {
Seq()
}
-
+
val priorAlignmentsApprox = priorSibs.map(_.endingAlignmentApprox) ++ parent.map(_.contentStartAlignment).toSeq ++ arraySelfAlignment
priorAlignmentsApprox.reduce(_ * _)
}
@@ -233,8 +229,7 @@ trait AlignedMixin extends GrammarMixin { self: Term =>
// multiple of 8
LengthMultipleOf(8)
}
- }
- else eb.lengthUnits match {
+ } else eb.lengthUnits match {
case LengthUnits.Bits => LengthMultipleOf(1)
case LengthUnits.Bytes => LengthMultipleOf(8)
case LengthUnits.Characters => encodingLengthApprox
@@ -242,8 +237,8 @@ trait AlignedMixin extends GrammarMixin { self: Term =>
}
case LengthKind.Delimited => encodingLengthApprox
case LengthKind.Pattern => encodingLengthApprox
- case LengthKind.EndOfParent => LengthMultipleOf(1)// NYI
- case LengthKind.Prefixed => LengthMultipleOf(1)// NYI
+ case LengthKind.EndOfParent => LengthMultipleOf(1) // NYI
+ case LengthKind.Prefixed => LengthMultipleOf(1) // NYI
}
}
}
@@ -266,10 +261,10 @@ trait AlignedMixin extends GrammarMixin { self: Term =>
val isSkipRegionByteLength = (leadingSkipInBits % 8 == 0) && (trailingSkipInBits % 8 == 0)
val isByteLength = this match {
- case mg: ModelGroup => mg.groupMembersNoRefs.forall { _.isKnownToBeByteAlignedAndByteLength }
+ case mg: ModelGroup => mg.groupMembers.forall { _.isKnownToBeByteAlignedAndByteLength }
case eb: ElementBase => {
val isSelfByteSizeEncoding = eb.charsetEv.optConstant.map { !_.charset.isInstanceOf[NonByteSizeCharset] }.getOrElse(false)
- val isSelfByteLength =
+ val isSelfByteLength =
if (eb.isComplexType && eb.lengthKind == LengthKind.Implicit) {
eb.complexType.group.isKnownToBeByteAlignedAndByteLength
} else {
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ChoiceGrammarMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ChoiceGrammarMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ChoiceGrammarMixin.scala
index 55e8986..5309307 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ChoiceGrammarMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ChoiceGrammarMixin.scala
@@ -32,10 +32,10 @@
package edu.illinois.ncsa.daffodil.grammar
-import edu.illinois.ncsa.daffodil.dsom.Choice
+import edu.illinois.ncsa.daffodil.dsom.ChoiceTermBase
import edu.illinois.ncsa.daffodil.grammar.primitives.ChoiceCombinator
-trait ChoiceGrammarMixin extends GrammarMixin { self: Choice =>
+trait ChoiceGrammarMixin extends GrammarMixin { self: ChoiceTermBase =>
override lazy val groupContent = prod("choiceContent") {
ChoiceCombinator(this, alternatives)
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementBaseGrammarMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementBaseGrammarMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementBaseGrammarMixin.scala
index a5f3f2f..1bc9909 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementBaseGrammarMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementBaseGrammarMixin.scala
@@ -37,7 +37,6 @@ import edu.illinois.ncsa.daffodil.processors._
import edu.illinois.ncsa.daffodil.schema.annotation.props.gen._
import edu.illinois.ncsa.daffodil.dpath.NodeInfo.PrimType
import edu.illinois.ncsa.daffodil.dsom.InitiatedTerminatedMixin
-import edu.illinois.ncsa.daffodil.dsom.SimpleTypeBase
import edu.illinois.ncsa.daffodil.dsom.ElementBase
import java.lang.{ Long => JLong }
import edu.illinois.ncsa.daffodil.dpath.NodeInfo
@@ -414,7 +413,7 @@ trait ElementBaseGrammarMixin
protected lazy val elementUnused = new ElementUnused(context)
/**
- * provided by LocalElementBase for array considerations, and GlobalElementDecl - scalar only
+ * provided by ElementBase for array considerations, and GlobalElementDecl - scalar only
*/
protected def allowedValue: Gram
//
@@ -657,11 +656,7 @@ trait ElementBaseGrammarMixin
ConvertTextCombinator(this, stringValue, ConvertTextBooleanPrim(this))
}
- // shorthand
- final lazy val primType = {
- val res = typeDef.asInstanceOf[SimpleTypeBase].primType
- res
- }
+ def primType: PrimType
protected final lazy val value = prod("value", isSimpleType) {
// TODO: Consider issues with matching a stopValue. Can't say isScalar here because
@@ -1025,7 +1020,7 @@ trait ElementBaseGrammarMixin
private lazy val elementRightFraming = prod("elementRightFraming") { TrailingSkipRegion(this) }
- protected final lazy val enclosedElement = prod("enclosedElement") {
+ protected lazy val enclosedElement = prod("enclosedElement") {
//
// not isScalar, because this is reused inside arrays
// that is, we're counting on reusuing this production for array elements
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementDeclGrammarMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementDeclGrammarMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementDeclGrammarMixin.scala
index 31ad470..0ae7f8e 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementDeclGrammarMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementDeclGrammarMixin.scala
@@ -33,11 +33,11 @@
package edu.illinois.ncsa.daffodil.grammar
import edu.illinois.ncsa.daffodil.grammar.primitives.UnicodeByteOrderMark
-import edu.illinois.ncsa.daffodil.dsom.GlobalElementDecl
+import edu.illinois.ncsa.daffodil.dsom.Root
-trait GlobalElementDeclGrammarMixin
+trait RootGrammarMixin
extends LocalElementGrammarMixin // can be repeating if not root
- { self: GlobalElementDecl =>
+ { self: Root =>
final lazy val document = prod("document") {
schemaDefinitionUnless(isScalar, "The document element cannot be an array.")
@@ -45,4 +45,5 @@ trait GlobalElementDeclGrammarMixin
}
private def documentElement = enclosedElement
+
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementReferenceGrammarMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementReferenceGrammarMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementReferenceGrammarMixin.scala
index beb84be..71c2659 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementReferenceGrammarMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ElementReferenceGrammarMixin.scala
@@ -32,10 +32,8 @@
package edu.illinois.ncsa.daffodil.grammar
-import edu.illinois.ncsa.daffodil.dsom.ElementRef
+import edu.illinois.ncsa.daffodil.dsom.AbstractElementRef
-trait ElementReferenceGrammarMixin { self: ElementRef =>
-
- final override lazy val termContentBody = self.referencedElement.termContentBody
+trait ElementReferenceGrammarMixin { self: AbstractElementRef =>
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/Grammar.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/Grammar.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/Grammar.scala
index e1d43b8..e123489 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/Grammar.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/Grammar.scala
@@ -120,7 +120,17 @@ class SeqComp private (context: SchemaComponent, children: Seq[Gram]) extends Bi
else new SeqCompParser(context.runtimeData, parserChildren.toArray)
}
- lazy val unparserChildren = children.filter(x => !x.isEmpty && (x.forWhat != ForParser)).map { _.unparser }.filterNot { _.isInstanceOf[NadaUnparser] }
+ lazy val unparserChildren = {
+ val unparserKeptChildren =
+ children.filter(
+ x =>
+ !x.isEmpty && (x.forWhat != ForParser))
+ val unparsers =
+ unparserKeptChildren.map { x =>
+ x.unparser
+ }.filterNot { _.isInstanceOf[NadaUnparser] }
+ unparsers
+ }
final override lazy val unparser = {
if (unparserChildren.isEmpty) new NadaUnparser(context.runtimeData)
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/GrammarMixins.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/GrammarMixins.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/GrammarMixins.scala
index 5cf6e96..f8afb1e 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/GrammarMixins.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/GrammarMixins.scala
@@ -37,8 +37,6 @@ import edu.illinois.ncsa.daffodil.grammar.primitives.ComplexTypeCombinator
trait GroupRefGrammarMixin extends GrammarMixin { self: GroupRef =>
- override lazy val termContentBody = self.group.termContentBody
-
}
/////////////////////////////////////////////////////////////////
@@ -50,6 +48,6 @@ trait ComplexTypeBaseGrammarMixin extends GrammarMixin { self: ComplexTypeBase =
override protected final def grammarContext = this
lazy val mainGrammar = prod("mainGrammar") {
- ComplexTypeCombinator(this, modelGroup.group.asChildOfComplexType)
+ ComplexTypeCombinator(this, group.asChildOfComplexType)
}
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/GrammarTerm.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/GrammarTerm.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/GrammarTerm.scala
index 374606d..ca1aa63 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/GrammarTerm.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/GrammarTerm.scala
@@ -37,7 +37,7 @@ import edu.illinois.ncsa.daffodil.processors.parsers.Parser
import edu.illinois.ncsa.daffodil.processors.unparsers.Unparser
import edu.illinois.ncsa.daffodil.grammar.primitives.Nada
import edu.illinois.ncsa.daffodil.dsom.SchemaComponent
-import edu.illinois.ncsa.daffodil.oolag.OOLAG.OOLAGHost
+import edu.illinois.ncsa.daffodil.oolag.OOLAG.OOLAGHostImpl
import edu.illinois.ncsa.daffodil.compiler.ParserOrUnparser
import edu.illinois.ncsa.daffodil.util.Misc
import edu.illinois.ncsa.daffodil.compiler.BothParserAndUnparser
@@ -55,7 +55,7 @@ trait HasNoUnparser {
* because this one has to actually be operationalized.
*/
abstract class Gram(contextArg: SchemaComponent)
- extends OOLAGHost(contextArg) {
+ extends OOLAGHostImpl(contextArg) {
final def SDE(str: String, args: Any*): Nothing = context.SDE(str, args: _*)
final def SDW(str: String, args: Any*): Unit = context.SDW(str, args: _*)
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/HasStatementsGrammarMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/HasStatementsGrammarMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/HasStatementsGrammarMixin.scala
index dc1c6d2..03744c2 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/HasStatementsGrammarMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/HasStatementsGrammarMixin.scala
@@ -32,10 +32,9 @@
package edu.illinois.ncsa.daffodil.grammar
-import edu.illinois.ncsa.daffodil.dsom.DFDLStatementMixin
import edu.illinois.ncsa.daffodil.dsom.Term
-trait HasStatementsGrammarMixin extends GrammarMixin { self: Term with DFDLStatementMixin =>
+trait HasStatementsGrammarMixin extends GrammarMixin { self: Term =>
private lazy val statementGrams = statements.map { _.gram }
// TODO: statements (but specifically not newVariableInstance) can appear on simple type definitions as well as terms.
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/LocalElementGrammarMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/LocalElementGrammarMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/LocalElementGrammarMixin.scala
index e3e412d..84a2db3 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/LocalElementGrammarMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/LocalElementGrammarMixin.scala
@@ -33,7 +33,7 @@
package edu.illinois.ncsa.daffodil.grammar
import edu.illinois.ncsa.daffodil.schema.annotation.props._
import edu.illinois.ncsa.daffodil.schema.annotation.props.gen._
-import edu.illinois.ncsa.daffodil.dsom.LocalElementBase
+import edu.illinois.ncsa.daffodil.dsom.ElementBase
import edu.illinois.ncsa.daffodil.equality._; object ENoWarn2 { EqualitySuppressUnusedImportWarning() }
import edu.illinois.ncsa.daffodil.grammar.primitives.StopValue
import edu.illinois.ncsa.daffodil.grammar.primitives.NotStopValue
@@ -47,11 +47,8 @@ import edu.illinois.ncsa.daffodil.grammar.primitives.OccursCountExpression
import edu.illinois.ncsa.daffodil.grammar.primitives.OptionalCombinator
import edu.illinois.ncsa.daffodil.grammar.primitives.ArrayCombinator
-trait LocalElementGrammarMixin extends GrammarMixin { self: LocalElementBase =>
+trait LocalElementGrammarMixin extends GrammarMixin { self: ElementBase =>
- /**
- * further overridden in ElementRefGrammarMixin
- */
override lazy val termContentBody = prod("termContentBody") { // override in ElementRef
(if (isScalar) enclosedElement else recurrance)
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ModelGroupGrammarMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ModelGroupGrammarMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ModelGroupGrammarMixin.scala
index 1447d2c..66c8865 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ModelGroupGrammarMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/ModelGroupGrammarMixin.scala
@@ -35,13 +35,13 @@ package edu.illinois.ncsa.daffodil.grammar
import edu.illinois.ncsa.daffodil.schema.annotation.props.gen._
import edu.illinois.ncsa.daffodil.dsom.InitiatedTerminatedMixin
import edu.illinois.ncsa.daffodil.dsom.ModelGroup
-import edu.illinois.ncsa.daffodil.dsom.Sequence
-import edu.illinois.ncsa.daffodil.dsom.Choice
import edu.illinois.ncsa.daffodil.grammar.primitives.TrailingSkipRegion
import edu.illinois.ncsa.daffodil.grammar.primitives.LeadingSkipRegion
import edu.illinois.ncsa.daffodil.grammar.primitives.AlignmentFill
import edu.illinois.ncsa.daffodil.grammar.primitives.DelimiterStackCombinatorSequence
import edu.illinois.ncsa.daffodil.grammar.primitives.DelimiterStackCombinatorChoice
+import edu.illinois.ncsa.daffodil.dsom.SequenceTermBase
+import edu.illinois.ncsa.daffodil.dsom.ChoiceTermBase
trait ModelGroupGrammarMixin
extends InitiatedTerminatedMixin
@@ -78,8 +78,8 @@ trait ModelGroupGrammarMixin
) {
val content = initiatorRegion ~ groupContent ~ terminatorRegion
self match {
- case c: Choice => DelimiterStackCombinatorChoice(c, content)
- case s: Sequence => DelimiterStackCombinatorSequence(s, content)
+ case c: ChoiceTermBase => DelimiterStackCombinatorChoice(c, content)
+ case s: SequenceTermBase => DelimiterStackCombinatorSequence(s, content)
}
} else { groupContent }
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/SequenceGrammarMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/SequenceGrammarMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/SequenceGrammarMixin.scala
index 5c6ac4e..383cf53 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/SequenceGrammarMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/SequenceGrammarMixin.scala
@@ -32,10 +32,10 @@
package edu.illinois.ncsa.daffodil.grammar
import edu.illinois.ncsa.daffodil.schema.annotation.props.gen._
-import edu.illinois.ncsa.daffodil.dsom.Sequence
import edu.illinois.ncsa.daffodil.grammar.primitives.SequenceCombinator
+import edu.illinois.ncsa.daffodil.dsom.SequenceTermBase
-trait SequenceGrammarMixin extends GrammarMixin { self: Sequence =>
+trait SequenceGrammarMixin extends GrammarMixin { self: SequenceTermBase =>
final override lazy val groupContent = prod("groupContent") {
self.sequenceKind match {
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/package.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/package.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/package.scala
new file mode 100644
index 0000000..0deae3a
--- /dev/null
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/package.scala
@@ -0,0 +1,104 @@
+package edu.illinois.ncsa.daffodil
+
+/**
+ * Grammar Mixins for Schema Compilation
+ *
+ * DFDL is defined using a data syntax grammar. Daffodil compiles a DFDL schema
+ * into runtime data structures using a technique that tries to be faithful to
+ * this notion of a data syntax grammar. The exact data syntax grammar used
+ * in the DFDL specification is not really suitable to base an implementation on,
+ * but where possible we have named the grammar production rules, and terminals of
+ * the grammar consistently with the DFDL specification.
+ *
+ * The grammar rules are members of the DSOM traits/classes that use a
+ * grammar notation, organized as grammar rules the applicability of which
+ * is controlled by boolean test guard expressions.
+ *
+ * In addition to the grammar rules, these mixins contain the methods that analzye
+ * the DFDL schema with its DFDL annotations, to determine whether the grammar
+ * rule is applicable. Most optimizations in the Daffodil schema compiler are
+ * implemented by way of a grammar rule or [[Terminal]] which is included or
+ * excluded (aka guarded) by an optimization.
+ *
+ * The grammar rule mixins all inherit from the [[Gram]] trait which provides
+ * operators for expressing the rules. The concrete classes are the
+ * terminals of the grammar (instances of [[Terminal]]) and these
+ * are either primitives or combinators. The primitves and combinators are
+ * defined in the [[edu.illinois.ncsa.daffodil.grammar.primitives]] package.
+ *
+ * This all works very much like Scala's `scala.util.parsing.combinator` library,
+ * which is described in the [[http://www.artima.com/pins1ed/ Programming in Scala]] book
+ * in the [[http://www.artima.com/pins1ed/combinator-parsing.html chapter on Combinator Parsing]].
+ * However, Daffodil's grammar adds the notion of rich predicate guards controlling
+ * the rules, and of course the result of the grammar is an entirely different
+ * data structure. But but the way rules are expressed and use of operators
+ * like "`~`" and "`||`" to create a little grammar composition language are similar.
+ *
+ * It is best to illustrate how the grammar works by an example drawn from model groups.
+ * This example no longer matches the code of the actual implementation, but
+ * illustrates the ideas behind the grammar:
+ * @example
+ * {{{
+ * trait ModelGroupMixin extends ... {
+ *
+ * lazy val modelGroup = groupLeftFraming ~ groupContent ~ groupRightFraming
+ *
+ * lazy val groupLeftFraming = LeadingSkipRegion(this) ~ AlignmentFill(this)
+ *
+ * lazy val groupRightFraming = TrailingSkipRegion(this)
+ * }
+ * }}}
+ * Non-terminals of the data syntax grammar are ordinary lazy val members named
+ * beginning with lower case letter. Terminals of the grammar are classes
+ * and so are named beginning with an upper case letter.
+ *
+ * A terminal like `LeadingSkipRegion` will optimize itself out by evaluating a
+ * guard predicate test. Basically, if the DFDL schema has a `dfdl:leadingSkip`
+ * property of '0', then the `LeadingSkipRegion` of the data syntax grammar is zero
+ * width, so this terminal defines itself so that the `isEmpty` method returns
+ * `true`. That enables the "`~`" operator to see that it has an empty grammar term
+ * on it's left, hence, the "`~`" operator can reduce to just the right grammar term.
+ *
+ * The right grammar term, `AlignmentFill`, requires a much more sophisticated
+ * analysis of the schema and properties, but ultimately could also decide that
+ * it is not needed, and so `isEmpty`. Then the "`~`" operator will see that both sides are
+ * empty and it itself is then empty. That allows the modelGroup rule to recognize that
+ * for this DFDL schema there is no `groupLeftFraming`.
+ *
+ * The net result of this is all the grammar regions that are not applicable disappear
+ * from the grammar. What is left is a nest of combinators and primitives suitable
+ * for this specific DFDL schema's runtime to be generated.
+ *
+ * Lazy evaluation and by-name argument passing insure that this occurs without
+ * evaluating any irrelevant grammar rules.
+ *
+ * At the end, the schema compiler generates a parser or unparser instance
+ * by "asking" the now-optimized grammar data structure for a parser or unparser.
+ * This means really by invoking the corresponding
+ * method (`parser()` or `unparser()`) on the grammar object.
+ * Recursively each combinator constructs an instance of
+ * a class that implements
+ * `edu.illinois.ncsa.daffodil.processors.parsers.Parser` (or
+ * `edu.illinois.ncsa.daffodil.processors.unparsers.Unparser`)
+ * and that instance recursively calls the parsers (or unparsers) generated
+ * from the parts of the grammar which did not optimize themselves away.
+ * Primitves construct atomic primitive parsers (and unparsers) for things like
+ * delimiters, alignment regions, or simple type values.
+ *
+ * ==Futures==
+ *
+ * Many grammar rules are defined as instances of the [[Prod]] class using the `prod` method.
+ * This is not strictly speaking needed (the example above doesn't use it), but is intended
+ * to define named extension points in the grammar for a future DFDL extension
+ * capability. The idea is that the named productions would be the places
+ * where external extensions to the grammar would be examined and utilized to
+ * augment the internal grammar rule definitions. These externally defined productions
+ * could then incorporate into the grammar, new externally defined primitives,
+ * or possibly even combinators, which ultimately generate calls to externally
+ * defined parser (or unparser) instances.
+ *
+ * Currently the use of `prod` is ad-hoc and haphazard.
+ */
+package object grammar {
+ // This object exists for scaladoc purposes.
+}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/Primitives.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/Primitives.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/Primitives.scala
index fc3c2bc..7baaf30 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/Primitives.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/Primitives.scala
@@ -37,7 +37,7 @@ import edu.illinois.ncsa.daffodil.grammar.Terminal
import edu.illinois.ncsa.daffodil.grammar.HasNoUnparser
abstract class Primitive(e: Term, guard: Boolean = false)
- extends Terminal(e, guard) {
+ extends Terminal(e, guard) {
override def toString = "Prim[" + name + "]"
}
@@ -45,14 +45,14 @@ abstract class Primitive(e: Term, guard: Boolean = false)
* For stubbing out primitives that are placeholders
*/
abstract class UnimplementedPrimitive(e: Term, guard: Boolean = false)
- extends Primitive(e, guard)
- with HasNoUnparser {
+ extends Primitive(e, guard)
+ with HasNoUnparser {
override final lazy val parser = hasNoParser
}
// base stub classes
-case class NoValue(e: GlobalElementDecl, guard: Boolean = true) extends UnimplementedPrimitive(e, guard)
+// case class NoValue(e: GlobalElementDecl, guard: Boolean = true) extends UnimplementedPrimitive(e, guard)
case class SaveInputStream(e: ElementBase, guard: Boolean = true) extends UnimplementedPrimitive(e, guard)
@@ -66,4 +66,4 @@ case class StopValue(e: ElementBase with LocalElementMixin) extends Unimplemente
case class TheDefaultValue(e: ElementBase) extends UnimplementedPrimitive(e, e.isDefaultable)
-case class UnicodeByteOrderMark(e: GlobalElementDecl) extends UnimplementedPrimitive(e, false)
+case class UnicodeByteOrderMark(e: Root) extends UnimplementedPrimitive(e, false)
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesDelimiters.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesDelimiters.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesDelimiters.scala
index 0b16b6d..138f000 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesDelimiters.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesDelimiters.scala
@@ -172,7 +172,7 @@ case class Initiator(e: Term) extends DelimiterText(e, e) {
Assert.invariant(e.hasInitiator)
val delimiterType: DelimiterTextType.Type = DelimiterTextType.Initiator
}
-case class Separator(s: Sequence, t: Term) extends DelimiterText(s, t) {
+case class Separator(s: SequenceTermBase, t: Term) extends DelimiterText(s, t) {
Assert.invariant(s.hasSeparator)
val delimiterType: DelimiterTextType.Type = DelimiterTextType.Separator
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesElementKinds.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesElementKinds.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesElementKinds.scala
index 04459ae..b2a94ef 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesElementKinds.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesElementKinds.scala
@@ -62,7 +62,7 @@ import edu.illinois.ncsa.daffodil.cookers.ChoiceBranchKeyCooker
object ENoWarn3 { EqualitySuppressUnusedImportWarning() }
-case class DelimiterStackCombinatorSequence(sq: Sequence, body: Gram) extends Terminal(sq, !body.isEmpty) {
+case class DelimiterStackCombinatorSequence(sq: SequenceTermBase, body: Gram) extends Terminal(sq, !body.isEmpty) {
lazy val pInit = if (sq.initiatorParseEv.isKnownNonEmpty) One(sq.initiatorParseEv) else Nope
lazy val pSep = if (sq.separatorParseEv.isKnownNonEmpty) One(sq.separatorParseEv) else Nope
lazy val pTerm = if (sq.terminatorParseEv.isKnownNonEmpty) One(sq.terminatorParseEv) else Nope
@@ -76,7 +76,7 @@ case class DelimiterStackCombinatorSequence(sq: Sequence, body: Gram) extends Te
override lazy val unparser: DaffodilUnparser = new DelimiterStackUnparser(uInit, uSep, uTerm, sq.runtimeData, body.unparser)
}
-case class DelimiterStackCombinatorChoice(ch: Choice, body: Gram) extends Terminal(ch, !body.isEmpty) {
+case class DelimiterStackCombinatorChoice(ch: ChoiceTermBase, body: Gram) extends Terminal(ch, !body.isEmpty) {
lazy val pInit = if (ch.initiatorParseEv.isKnownNonEmpty) One(ch.initiatorParseEv) else Nope
lazy val pTerm = if (ch.terminatorParseEv.isKnownNonEmpty) One(ch.terminatorParseEv) else Nope
@@ -113,7 +113,7 @@ case class DynamicEscapeSchemeCombinatorElement(e: ElementBase, body: Gram) exte
override lazy val unparser: DaffodilUnparser = new DynamicEscapeSchemeUnparser(schemeUnparseOpt.get, e.runtimeData, body.unparser)
}
-case class ComplexTypeCombinator(ct: ComplexTypeBase, body: Gram) extends Terminal(ct.element, !body.isEmpty) {
+case class ComplexTypeCombinator(ct: ComplexTypeBase, body: Gram) extends Terminal(ct.elementDecl, !body.isEmpty) {
override def isEmpty = body.isEmpty
@@ -123,13 +123,24 @@ case class ComplexTypeCombinator(ct: ComplexTypeBase, body: Gram) extends Termin
new ComplexTypeUnparser(ct.runtimeData, body.unparser)
}
-case class SequenceCombinator(sq: Sequence, rawTerms: Seq[Gram])
- extends Terminal(sq, !rawTerms.filterNot { _.isEmpty }.isEmpty) {
+case class SequenceCombinator(sq: SequenceTermBase, rawTerms: Seq[Gram])
+ extends Terminal(sq, true) {
+
+ override lazy val isEmpty = {
+ val rt = rawTerms
+ val frt = rt.filterNot { _.isEmpty }
+ val res = frt.isEmpty
+ res
+ }
private val mt: Gram = EmptyGram
lazy val body = rawTerms.foldRight(mt) { _ ~ _ }
+
lazy val terms = rawTerms.filterNot { _.isEmpty }
- lazy val unparsers = terms.map { _.unparser }.toVector
+
+ lazy val unparsers = terms.map { term =>
+ term.unparser
+ }.toVector
lazy val parser: DaffodilParser = new SequenceCombinatorParser(sq.termRuntimeData, body.parser)
@@ -167,7 +178,7 @@ case class OptionalCombinator(e: ElementBase, body: Gram) extends Terminal(e, !b
* need to determine which branch of the choice to take at runtime. This
* unparser uses a Map to make the determination based on the element seen.
*/
-case class ChoiceCombinator(ch: Choice, alternatives: Seq[Gram]) extends Terminal(ch, !alternatives.isEmpty) {
+case class ChoiceCombinator(ch: ChoiceTermBase, alternatives: Seq[Gram]) extends Terminal(ch, !alternatives.isEmpty) {
lazy val parser: DaffodilParser = {
if (!ch.isDirectDispatch) {
val folded = alternatives.map { gf => gf }.foldRight(EmptyGram.asInstanceOf[Gram]) { _ | _ }
@@ -224,7 +235,7 @@ case class ChoiceCombinator(ch: Choice, alternatives: Seq[Gram]) extends Termina
// this call is necessary since it will throw an SDE if no choice branch
// was defaultable
ch.childrenInHiddenGroupNotDefaultableOrOVC
- val defaultableBranches = ch.groupMembersNoRefs.filter { _.childrenInHiddenGroupNotDefaultableOrOVC.length == 0 }
+ val defaultableBranches = ch.groupMembers.filter { _.childrenInHiddenGroupNotDefaultableOrOVC.length == 0 }
Assert.invariant(defaultableBranches.length > 0)
if (defaultableBranches.length > 1) {
SDW("xs:choice inside a hidden group has unparse ambiguity: multiple branches exist with all children either defaulable or have the dfdl:outputValueCalc property set. The first branch will be chosen during unparse. Defaultable branches are:\n%s",
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesExpressions.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesExpressions.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesExpressions.scala
index 36d0d14..db992a5 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesExpressions.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesExpressions.scala
@@ -270,7 +270,7 @@ case class InputValueCalc(e: ElementBase,
// }
//}
-abstract class AssertPatternPrimBase(decl: AnnotatedSchemaComponent, stmt: DFDLAssertionBase)
+abstract class AssertPatternPrimBase(decl: Term, stmt: DFDLAssertionBase)
extends Terminal(decl, true) {
lazy val eName = decl.diagnosticDebugName
@@ -286,22 +286,22 @@ abstract class AssertPatternPrimBase(decl: AnnotatedSchemaComponent, stmt: DFDLA
override def unparser: DaffodilUnparser = Assert.invariantFailed("should not request unparser for asserts/discriminators")
}
-case class AssertPatternPrim(decl: AnnotatedSchemaComponent, stmt: DFDLAssert)
- extends AssertPatternPrimBase(decl, stmt) {
+case class AssertPatternPrim(term: Term, stmt: DFDLAssert)
+ extends AssertPatternPrimBase(term, stmt) {
val kindString = "AssertPatternPrim"
lazy val parser: DaffodilParser = {
- new AssertPatternParser(eName, kindString, decl.term.termRuntimeData, testPattern, stmt.message)
+ new AssertPatternParser(eName, kindString, term.termRuntimeData, testPattern, stmt.message)
}
}
-case class DiscriminatorPatternPrim(decl: AnnotatedSchemaComponent, stmt: DFDLAssertionBase)
- extends AssertPatternPrimBase(decl, stmt) {
+case class DiscriminatorPatternPrim(term: Term, stmt: DFDLAssertionBase)
+ extends AssertPatternPrimBase(term, stmt) {
val kindString = "DiscriminatorPatternPrim"
- lazy val parser: DaffodilParser = new DiscriminatorPatternParser(testPattern, eName, kindString, decl.term.termRuntimeData, stmt.message)
+ lazy val parser: DaffodilParser = new DiscriminatorPatternParser(testPattern, eName, kindString, term.termRuntimeData, stmt.message)
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesUnorderedSequence.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesUnorderedSequence.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesUnorderedSequence.scala
index 9f4f22a..469a453 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesUnorderedSequence.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/PrimitivesUnorderedSequence.scala
@@ -36,7 +36,7 @@ import edu.illinois.ncsa.daffodil.grammar.Gram
import edu.illinois.ncsa.daffodil.exceptions.Assert
import edu.illinois.ncsa.daffodil.dsom.ElementBase
import edu.illinois.ncsa.daffodil.dsom.Term
-import edu.illinois.ncsa.daffodil.dsom.Sequence
+import edu.illinois.ncsa.daffodil.dsom.SequenceTermBase
import edu.illinois.ncsa.daffodil.grammar.UnaryGram
import edu.illinois.ncsa.daffodil.grammar.HasNoUnparser
import edu.illinois.ncsa.daffodil.processors.ElementRuntimeData
@@ -47,15 +47,15 @@ object UnorderedSequence {
// mandatory little optimization here. If there are no statements (most common case), then let's
// shortcut and just use the guts parser.
- Assert.usageErrorUnless(context.isInstanceOf[Sequence], "The context passed to UnorderedSequence must be a Sequence.")
+ Assert.usageErrorUnless(context.isInstanceOf[SequenceTermBase], "The context passed to UnorderedSequence must be a Sequence.")
- val ctxt = context.asInstanceOf[Sequence]
+ val ctxt = context.asInstanceOf[SequenceTermBase]
new UnorderedSequence(ctxt, eGram)
}
}
-class UnorderedSequence private (context: Sequence, eGramArg: => Gram) // private to force use of the object as factory
+class UnorderedSequence private (context: SequenceTermBase, eGramArg: => Gram) // private to force use of the object as factory
extends UnaryGram(context, eGramArg) with HasNoUnparser {
lazy val eGram = eGramArg // once only
@@ -67,7 +67,7 @@ class UnorderedSequence private (context: Sequence, eGramArg: => Gram) // privat
val sortOrder = {
val members = context.groupMembers.map(t => {
t match {
- case s: Sequence => s.groupMembers
+ case s: SequenceTermBase => s.groupMembers
case _ => Seq(t)
}
}).flatten
[3/6] incubator-daffodil git commit: Property Resolution - part of
fixing schema compilation
Posted by mb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/RepPrims.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/RepPrims.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/RepPrims.scala
index fd45a1f..0e2a355 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/RepPrims.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/grammar/primitives/RepPrims.scala
@@ -57,7 +57,7 @@ object INoWarn6 { ImplicitsSuppressUnusedImportWarning() }
object ENoWarn6 { EqualitySuppressUnusedImportWarning() }
object RepPrims {
- abstract class RepPrim(context: LocalElementBase, n: Long, r: => Gram)
+ abstract class RepPrim(context: ElementBase, n: Long, r: => Gram)
extends UnaryGram(context, r) {
Assert.invariant(n > 0)
lazy val rd = context.elementRuntimeData
@@ -67,23 +67,23 @@ object RepPrims {
}
- abstract class Rep3Arg(f: (LocalElementBase, Long, => Gram) => Gram) {
- def apply(context: LocalElementBase, n: Long, rr: => Gram) = {
+ abstract class Rep3Arg(f: (ElementBase, Long, => Gram) => Gram) {
+ def apply(context: ElementBase, n: Long, rr: => Gram) = {
lazy val r = rr
if (n == 0 || r.isEmpty) EmptyGram
else f(context, n, r)
}
}
- abstract class Rep2Arg(f: (LocalElementBase, => Gram) => Gram) {
- def apply(context: LocalElementBase, r: => Gram) = {
+ abstract class Rep2Arg(f: (ElementBase, => Gram) => Gram) {
+ def apply(context: ElementBase, r: => Gram) = {
lazy val rr = r
if (rr.isEmpty) EmptyGram
else f(context, r)
}
}
- class RepExactlyNPrim(context: LocalElementBase, n: Long, r: => Gram) extends RepPrim(context, n, r) {
+ class RepExactlyNPrim(context: ElementBase, n: Long, r: => Gram) extends RepPrim(context, n, r) {
// Since this is Exactly N, there is no new point of uncertainty considerations here.
override lazy val parser = new RepExactlyNParser(n, r.parser, context.elementRuntimeData)
@@ -91,27 +91,27 @@ object RepPrims {
}
- class RepAtMostTotalNPrim(context: LocalElementBase, n: Long, r: => Gram) extends RepPrim(context, n, r) {
+ class RepAtMostTotalNPrim(context: ElementBase, n: Long, r: => Gram) extends RepPrim(context, n, r) {
override lazy val parser = new RepAtMostTotalNParser(n, r.parser, context.elementRuntimeData)
override lazy val unparser = new RepAtMostTotalNUnparser(n, r.unparser, context.elementRuntimeData)
}
- class RepExactlyTotalNPrim(context: LocalElementBase, n: Long, r: => Gram) extends RepPrim(context, n, r) {
+ class RepExactlyTotalNPrim(context: ElementBase, n: Long, r: => Gram) extends RepPrim(context, n, r) {
override lazy val parser = new RepExactlyTotalNParser(n, r.parser, context.elementRuntimeData)
override lazy val unparser = new RepExactlyTotalNUnparser(n, r.unparser, context.elementRuntimeData)
}
- class RepUnboundedPrim(e: LocalElementBase, r: => Gram) extends RepPrim(e, 1, r) {
+ class RepUnboundedPrim(e: ElementBase, r: => Gram) extends RepPrim(e, 1, r) {
override lazy val parser = new RepUnboundedParser(e.occursCountKind, r.parser, e.elementRuntimeData)
override lazy val unparser = new RepUnboundedUnparser(e.occursCountKind, r.unparser, e.elementRuntimeData)
}
- class RepAtMostOccursCountPrim(e: LocalElementBase, n: Long, r: => Gram)
+ class RepAtMostOccursCountPrim(e: ElementBase, n: Long, r: => Gram)
extends RepPrim(e, n, r) {
override lazy val parser = new RepAtMostOccursCountParser(r.parser, n, e.elementRuntimeData)
@@ -119,7 +119,7 @@ object RepPrims {
}
- class RepExactlyTotalOccursCountPrim(e: LocalElementBase, r: => Gram)
+ class RepExactlyTotalOccursCountPrim(e: ElementBase, r: => Gram)
extends RepPrim(e, 1, r) {
override lazy val parser = new RepExactlyTotalOccursCountParser(r.parser, e.elementRuntimeData)
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/test/resources/test/example-of-most-dfdl-constructs.dfdl.xml
----------------------------------------------------------------------
diff --git a/daffodil-core/src/test/resources/test/example-of-most-dfdl-constructs.dfdl.xml b/daffodil-core/src/test/resources/test/example-of-most-dfdl-constructs.dfdl.xml
index b9d57d4..1d66b68 100644
--- a/daffodil-core/src/test/resources/test/example-of-most-dfdl-constructs.dfdl.xml
+++ b/daffodil-core/src/test/resources/test/example-of-most-dfdl-constructs.dfdl.xml
@@ -8,6 +8,8 @@
xsi:schemaLocation="http://www.ogf.org/dfdl/dfdl-1.0/ xsd/DFDL_part3_model.xsd
http://www.w3.org/2001/XMLSchema xsd/XMLSchema_for_DFDL.xsd">
+ <xs:include schemaLocation="edu/illinois/ncsa/daffodil/xsd/built-in-formats.xsd"/>
+
<annotation>
<documentation>
The goal of this schema is to make one use of every XSD
@@ -79,7 +81,8 @@
<!-- note use of Japanese Kanji in the name -->
<dfdl:defineFormat name="def2年月日">
<dfdl:format representation="binary"
- textStandardBase="10" escapeSchemeRef="tns:quotingScheme" sequenceKind="ordered" />
+ textStandardBase="10" escapeSchemeRef="tns:quotingScheme" sequenceKind="ordered"
+ ref="ex:daffodilTest1" />
</dfdl:defineFormat>
<dfdl:defineEscapeScheme name="quotingScheme">
<dfdl:escapeScheme escapeCharacter="%%"
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/test/scala-debug/edu/illinois/ncsa/daffodil/dsom/TestDsomCompilerNew.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/test/scala-debug/edu/illinois/ncsa/daffodil/dsom/TestDsomCompilerNew.scala b/daffodil-core/src/test/scala-debug/edu/illinois/ncsa/daffodil/dsom/TestDsomCompilerNew.scala
index e4dc979..cb4efaf 100644
--- a/daffodil-core/src/test/scala-debug/edu/illinois/ncsa/daffodil/dsom/TestDsomCompilerNew.scala
+++ b/daffodil-core/src/test/scala-debug/edu/illinois/ncsa/daffodil/dsom/TestDsomCompilerNew.scala
@@ -191,22 +191,22 @@ class TestDsomCompilerNew extends Logging {
val elemsFollowingRootSeq = rootCTSeq.possibleNextTerms
assertEquals(0, elemsFollowingRootSeq.length)
- val Seq(one: LocalElementBase, two: LocalElementBase, three: LocalElementBase, _: Sequence) =
+ val Seq(one: ElementBase, two: ElementBase, three: ElementBase, _: Sequence) =
rootCTSeq.groupMembers // has an element and a sub-sequence as its children.
val elemsFollowingOne = one.possibleNextTerms
assertEquals(1, elemsFollowingOne.length)
- assertEquals("two", elemsFollowingOne(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("two", elemsFollowingOne(0).asInstanceOf[ElementBase].name)
val elemsFollowingTwo = two.possibleNextTerms
assertEquals(1, elemsFollowingTwo.length)
- assertEquals("three", elemsFollowingTwo(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("three", elemsFollowingTwo(0).asInstanceOf[ElementBase].name)
val elemsFollowingThree = three.possibleNextTerms
assertEquals(1, elemsFollowingThree.length)
val seqFollowingThree = elemsFollowingThree(0).asInstanceOf[Sequence]
- val Seq(four: LocalElementBase) = seqFollowingThree.allSelfContainedTermsTerminatedByRequiredElement
+ val Seq(four: ElementBase) = seqFollowingThree.allSelfContainedTermsTerminatedByRequiredElement
assertEquals("four", four.name)
}
@@ -282,24 +282,24 @@ class TestDsomCompilerNew extends Logging {
val elemsFollowingRootSeq = rootCTSeq.possibleNextTerms
assertEquals(0, elemsFollowingRootSeq.length)
- val Seq(one: LocalElementBase, two: LocalElementBase, three: LocalElementBase, _: Sequence) =
+ val Seq(one: ElementBase, two: ElementBase, three: ElementBase, _: Sequence) =
rootCTSeq.groupMembers // has an element and a sub-sequence as its children.
val elemsFollowingOne = one.possibleNextTerms
assertEquals(1, elemsFollowingOne.length)
- assertEquals("two", elemsFollowingOne(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("two", elemsFollowingOne(0).asInstanceOf[ElementBase].name)
val elemsFollowingTwo = two.possibleNextTerms
assertEquals(2, elemsFollowingTwo.length)
- assertEquals("three", elemsFollowingTwo(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("three", elemsFollowingTwo(0).asInstanceOf[ElementBase].name)
val seqFollowingThree = elemsFollowingTwo(1).asInstanceOf[Sequence]
- val Seq(four: LocalElementBase) = seqFollowingThree.groupMembers
+ val Seq(four: ElementBase) = seqFollowingThree.groupMembers
assertEquals("four", four.name)
val elemsFollowingThree = three.possibleNextTerms
assertEquals(1, elemsFollowingThree.length)
val seqFollowingThree2 = elemsFollowingThree(0).asInstanceOf[Sequence]
- val Seq(four2: LocalElementBase) = seqFollowingThree2.groupMembers
+ val Seq(four2: ElementBase) = seqFollowingThree2.groupMembers
assertEquals("four", four2.name)
}
@@ -373,22 +373,22 @@ class TestDsomCompilerNew extends Logging {
val elemsFollowingRootSeq = rootCTSeq.possibleNextTerms
assertEquals(0, elemsFollowingRootSeq.length)
- val Seq(one: LocalElementBase, two: LocalElementBase, three: LocalElementBase, _: Sequence) =
+ val Seq(one: ElementBase, two: ElementBase, three: ElementBase, _: Sequence) =
rootCTSeq.groupMembers // has an element and a sub-sequence as its children.
val elemsFollowingOne = one.possibleNextTerms
assertEquals(2, elemsFollowingOne.length)
- assertEquals("two", elemsFollowingOne(0).asInstanceOf[LocalElementBase].name)
- assertEquals("three", elemsFollowingOne(1).asInstanceOf[LocalElementBase].name)
+ assertEquals("two", elemsFollowingOne(0).asInstanceOf[ElementBase].name)
+ assertEquals("three", elemsFollowingOne(1).asInstanceOf[ElementBase].name)
val elemsFollowingTwo = two.possibleNextTerms
assertEquals(1, elemsFollowingTwo.length)
- assertEquals("three", elemsFollowingTwo(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("three", elemsFollowingTwo(0).asInstanceOf[ElementBase].name)
val elemsFollowingThree = three.possibleNextTerms
assertEquals(1, elemsFollowingThree.length)
val seqFollowingThree = elemsFollowingThree(0).asInstanceOf[Sequence]
- val Seq(four: LocalElementBase) = seqFollowingThree.groupMembers
+ val Seq(four: ElementBase) = seqFollowingThree.groupMembers
assertEquals("four", four.name)
}
@@ -463,21 +463,21 @@ class TestDsomCompilerNew extends Logging {
val elemsFollowingRootSeq = rootCTSeq.possibleNextTerms
assertEquals(0, elemsFollowingRootSeq.length)
- val Seq(one: LocalElementBase, two: LocalElementBase, three: LocalElementBase, _: Sequence) =
+ val Seq(one: ElementBase, two: ElementBase, three: ElementBase, _: Sequence) =
rootCTSeq.groupMembers // has an element and a sub-sequence as its children.
val elemsFollowingOne = one.possibleNextTerms
assertEquals(1, elemsFollowingOne.length)
- assertEquals("two", elemsFollowingOne(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("two", elemsFollowingOne(0).asInstanceOf[ElementBase].name)
val elemsFollowingTwo = two.possibleNextTerms
assertEquals(1, elemsFollowingTwo.length)
- assertEquals("three", elemsFollowingTwo(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("three", elemsFollowingTwo(0).asInstanceOf[ElementBase].name)
val elemsFollowingThree = three.possibleNextTerms
assertEquals(1, elemsFollowingThree.length)
val seqFollowingThree = elemsFollowingThree(0).asInstanceOf[Sequence]
- val Seq(four: LocalElementBase) = seqFollowingThree.groupMembers
+ val Seq(four: ElementBase) = seqFollowingThree.groupMembers
assertEquals("four", four.name)
}
@@ -558,30 +558,30 @@ class TestDsomCompilerNew extends Logging {
val elemsFollowingRootSeq = rootCTSeq.possibleNextTerms
assertEquals(0, elemsFollowingRootSeq.length)
- val Seq(one: LocalElementBase, two: LocalElementBase, three: LocalElementBase, seq: Sequence) =
+ val Seq(one: ElementBase, two: ElementBase, three: ElementBase, seq: Sequence) =
rootCTSeq.groupMembers // has an element and a sub-sequence as its children.
- val Seq(four: LocalElementBase) = seq.groupMembers
+ val Seq(four: ElementBase) = seq.groupMembers
val elemsFollowingOne = one.possibleNextTerms
- val Seq(eTwo: LocalElementBase, eThree: LocalElementBase, seqFollowingThree: Sequence) = one.possibleNextTerms
+ val Seq(eTwo: ElementBase, eThree: ElementBase, seqFollowingThree: Sequence) = one.possibleNextTerms
assertEquals(3, elemsFollowingOne.length)
assertEquals("two", eTwo.name)
assertEquals("three", eThree.name)
- val Seq(eFour: LocalElementBase) = seqFollowingThree.groupMembers
+ val Seq(eFour: ElementBase) = seqFollowingThree.groupMembers
assertEquals("four", eFour.name)
val elemsFollowingTwo = two.possibleNextTerms
- val Seq(eThree_2: LocalElementBase, seqFollowingThree_2: Sequence) = two.possibleNextTerms
+ val Seq(eThree_2: ElementBase, seqFollowingThree_2: Sequence) = two.possibleNextTerms
assertEquals(2, elemsFollowingTwo.length)
assertEquals("three", eThree_2.name)
- val Seq(eFour_2: LocalElementBase) = seqFollowingThree_2.groupMembers
+ val Seq(eFour_2: ElementBase) = seqFollowingThree_2.groupMembers
assertEquals("four", eFour_2.name)
val elemsFollowingThree = three.possibleNextTerms
val Seq(seqFollowingThree_3: Sequence) = three.possibleNextTerms
assertEquals(1, elemsFollowingThree.length)
- val Seq(eFour_3: LocalElementBase) = seqFollowingThree_3.groupMembers
+ val Seq(eFour_3: ElementBase) = seqFollowingThree_3.groupMembers
assertEquals("four", eFour_3.name)
val elemsFollowingFour = four.possibleNextTerms
@@ -665,29 +665,29 @@ class TestDsomCompilerNew extends Logging {
val elemsFollowingRootSeq = rootCTSeq.possibleNextTerms
assertEquals(0, elemsFollowingRootSeq.length)
- val Seq(one: LocalElementBase, two: LocalElementBase, three: LocalElementBase, seq: Sequence) =
+ val Seq(one: ElementBase, two: ElementBase, three: ElementBase, seq: Sequence) =
rootCTSeq.groupMembers // has an element and a sub-sequence as its children.
- val Seq(four: LocalElementBase) = seq.groupMembers
+ val Seq(four: ElementBase) = seq.groupMembers
val elemsFollowingOne = one.possibleNextTerms
- val Seq(two_1: LocalElementBase, three_1: LocalElementBase, seqFollowingThree_1: Sequence) = one.possibleNextTerms
- val Seq(four_1: LocalElementBase) = seqFollowingThree_1.groupMembers
+ val Seq(two_1: ElementBase, three_1: ElementBase, seqFollowingThree_1: Sequence) = one.possibleNextTerms
+ val Seq(four_1: ElementBase) = seqFollowingThree_1.groupMembers
assertEquals(3, elemsFollowingOne.length)
assertEquals("two", two_1.name)
assertEquals("three", three_1.name)
assertEquals("four", four_1.name)
val elemsFollowingTwo = two.possibleNextTerms
- val Seq(three_2: LocalElementBase, seqFollowingThree_2: Sequence) = two.possibleNextTerms
- val Seq(four_2: LocalElementBase) = seqFollowingThree_2.groupMembers
+ val Seq(three_2: ElementBase, seqFollowingThree_2: Sequence) = two.possibleNextTerms
+ val Seq(four_2: ElementBase) = seqFollowingThree_2.groupMembers
assertEquals(2, elemsFollowingTwo.length)
assertEquals("three", three_2.name)
assertEquals("four", four_2.name)
val elemsFollowingThree = three.possibleNextTerms
val Seq(seqFollowingThree_3: Sequence) = three.possibleNextTerms
- val Seq(four_3: LocalElementBase) = seqFollowingThree_3.groupMembers
+ val Seq(four_3: ElementBase) = seqFollowingThree_3.groupMembers
assertEquals(1, elemsFollowingThree.length)
assertEquals("four", four_3.name)
@@ -784,8 +784,8 @@ class TestDsomCompilerNew extends Logging {
val oneCTSeq = oneCT.sequence
val elemsFollowingOneCTSeq = oneCTSeq.possibleNextTerms
- val Seq(two_1: LocalElementBase, three_1: LocalElementBase, seqFollowingThree_1: Sequence) = oneCTSeq.possibleNextTerms
- val Seq(four_1: LocalElementBase) = seqFollowingThree_1.groupMembers
+ val Seq(two_1: ElementBase, three_1: ElementBase, seqFollowingThree_1: Sequence) = oneCTSeq.possibleNextTerms
+ val Seq(four_1: ElementBase) = seqFollowingThree_1.groupMembers
assertEquals(3, elemsFollowingOneCTSeq.length)
assertEquals("two", two_1.name)
assertEquals("three", three_1.name)
@@ -795,30 +795,30 @@ class TestDsomCompilerNew extends Logging {
val elemsFollowingA = a.possibleNextTerms
assertEquals(1, elemsFollowingA.length)
- assertEquals("b", elemsFollowingA(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("b", elemsFollowingA(0).asInstanceOf[ElementBase].name)
val elemsFollowingB = b.possibleNextTerms
assertEquals(1, elemsFollowingB.length)
- assertEquals("c", elemsFollowingB(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("c", elemsFollowingB(0).asInstanceOf[ElementBase].name)
val elemsFollowingC = c.possibleNextTerms
- val Seq(two_2: LocalElementBase, three_2: LocalElementBase, seqFollowingThree_2: Sequence) = c.possibleNextTerms
- val Seq(four_2: LocalElementBase) = seqFollowingThree_2.groupMembers
+ val Seq(two_2: ElementBase, three_2: ElementBase, seqFollowingThree_2: Sequence) = c.possibleNextTerms
+ val Seq(four_2: ElementBase) = seqFollowingThree_2.groupMembers
assertEquals(3, elemsFollowingC.length)
assertEquals("two", two_2.name)
assertEquals("three", three_2.name)
assertEquals("four", four_2.name)
val elemsFollowingTwo = two.possibleNextTerms
- val Seq(three_3: LocalElementBase, seqFollowingThree_3: Sequence) = two.possibleNextTerms
- val Seq(four_3: LocalElementBase) = seqFollowingThree_3.groupMembers
+ val Seq(three_3: ElementBase, seqFollowingThree_3: Sequence) = two.possibleNextTerms
+ val Seq(four_3: ElementBase) = seqFollowingThree_3.groupMembers
assertEquals(2, elemsFollowingTwo.length)
assertEquals("three", three_3.name)
assertEquals("four", four_3.name)
val elemsFollowingThree = three.possibleNextTerms
val Seq(seqFollowingThree_4: Sequence) = three.possibleNextTerms
- val Seq(four_4: LocalElementBase) = seqFollowingThree_4.groupMembers
+ val Seq(four_4: ElementBase) = seqFollowingThree_4.groupMembers
assertEquals(1, elemsFollowingThree.length)
assertEquals("four", four_4.name)
@@ -923,8 +923,8 @@ class TestDsomCompilerNew extends Logging {
val oneCTSeq = oneCT.sequence
val elemsFollowingOneCTSeq = oneCTSeq.possibleNextTerms
- val Seq(two_1: LocalElementBase, three_1: LocalElementBase, seqFollowingThree_1: Sequence) = oneCTSeq.possibleNextTerms
- val Seq(four_1: LocalElementBase) = seqFollowingThree_1.groupMembers
+ val Seq(two_1: ElementBase, three_1: ElementBase, seqFollowingThree_1: Sequence) = oneCTSeq.possibleNextTerms
+ val Seq(four_1: ElementBase) = seqFollowingThree_1.groupMembers
assertEquals(3, elemsFollowingOneCTSeq.length)
assertEquals("two", two_1.name)
assertEquals("three", three_1.name)
@@ -933,8 +933,8 @@ class TestDsomCompilerNew extends Logging {
val Seq(a: LocalElementDecl, b: LocalElementDecl, c: LocalElementDecl, _: Sequence) = oneCTSeq.groupMembers
val elemsFollowingA = a.possibleNextTerms
- val Seq(b_1: LocalElementBase, c_1: LocalElementBase, seqFollowingC_1: Sequence) = a.possibleNextTerms
- val Seq(s1_1: LocalElementBase, s2_1: LocalElementBase, s3_1: LocalElementBase) = seqFollowingC_1.groupMembers
+ val Seq(b_1: ElementBase, c_1: ElementBase, seqFollowingC_1: Sequence) = a.possibleNextTerms
+ val Seq(s1_1: ElementBase, s2_1: ElementBase, s3_1: ElementBase) = seqFollowingC_1.groupMembers
assertEquals(3, elemsFollowingA.length)
assertEquals("b", b_1.name)
assertEquals("c", c_1.name)
@@ -943,8 +943,8 @@ class TestDsomCompilerNew extends Logging {
assertEquals("s-3", s3_1.name)
val elemsFollowingB = b.possibleNextTerms
- val Seq(c_2: LocalElementBase, seqFollowingC_2: Sequence) = b.possibleNextTerms
- val Seq(s1_2: LocalElementBase, s2_2: LocalElementBase, s3_2: LocalElementBase) = seqFollowingC_2.groupMembers
+ val Seq(c_2: ElementBase, seqFollowingC_2: Sequence) = b.possibleNextTerms
+ val Seq(s1_2: ElementBase, s2_2: ElementBase, s3_2: ElementBase) = seqFollowingC_2.groupMembers
assertEquals(2, elemsFollowingB.length)
assertEquals("c", c_2.name)
assertEquals("s-1", s1_2.name)
@@ -953,22 +953,22 @@ class TestDsomCompilerNew extends Logging {
val elemsFollowingC = c.possibleNextTerms
val Seq(seqFollowingC_3: Sequence) = c.possibleNextTerms
- val Seq(s1_3: LocalElementBase, s2_3: LocalElementBase, s3_3: LocalElementBase) = seqFollowingC_3.groupMembers
+ val Seq(s1_3: ElementBase, s2_3: ElementBase, s3_3: ElementBase) = seqFollowingC_3.groupMembers
assertEquals(1, elemsFollowingC.length)
assertEquals("s-1", s1_3.name)
assertEquals("s-2", s2_3.name)
assertEquals("s-3", s3_3.name)
val elemsFollowingTwo = two.possibleNextTerms
- val Seq(three_2: LocalElementBase, seqFollowingThree_2: Sequence) = two.possibleNextTerms
- val Seq(four_2: LocalElementBase) = seqFollowingThree_2.groupMembers
+ val Seq(three_2: ElementBase, seqFollowingThree_2: Sequence) = two.possibleNextTerms
+ val Seq(four_2: ElementBase) = seqFollowingThree_2.groupMembers
assertEquals(2, elemsFollowingTwo.length)
assertEquals("three", three_2.name)
assertEquals("four", four_2.name)
val elemsFollowingThree = three.possibleNextTerms
val Seq(seqFollowingThree_3: Sequence) = three.possibleNextTerms
- val Seq(four_3: LocalElementBase) = seqFollowingThree_3.groupMembers
+ val Seq(four_3: ElementBase) = seqFollowingThree_3.groupMembers
assertEquals(1, elemsFollowingThree.length)
assertEquals("four", four_3.name)
@@ -1073,8 +1073,8 @@ class TestDsomCompilerNew extends Logging {
val oneCTSeq = oneCT.sequence
val elemsFollowingOneCTSeq = oneCTSeq.possibleNextTerms
- val Seq(two_1: LocalElementBase, three_1: LocalElementBase, seqFollowingThree_1: Sequence) = oneCTSeq.possibleNextTerms
- val Seq(four_1: LocalElementBase) = seqFollowingThree_1.groupMembers
+ val Seq(two_1: ElementBase, three_1: ElementBase, seqFollowingThree_1: Sequence) = oneCTSeq.possibleNextTerms
+ val Seq(four_1: ElementBase) = seqFollowingThree_1.groupMembers
assertEquals(3, elemsFollowingOneCTSeq.length)
assertEquals("two", two_1.name)
assertEquals("three", three_1.name)
@@ -1083,8 +1083,8 @@ class TestDsomCompilerNew extends Logging {
val Seq(a: LocalElementDecl, b: LocalElementDecl, _: Sequence, c: LocalElementDecl) = oneCTSeq.groupMembers
val elemsFollowingA = a.possibleNextTerms
- val Seq(b_1: LocalElementBase, seqFollowingA: Sequence) = a.possibleNextTerms
- val Seq(s1_1: LocalElementBase, s2_1: LocalElementBase, s3_1: LocalElementBase) = seqFollowingA.groupMembers
+ val Seq(b_1: ElementBase, seqFollowingA: Sequence) = a.possibleNextTerms
+ val Seq(s1_1: ElementBase, s2_1: ElementBase, s3_1: ElementBase) = seqFollowingA.groupMembers
assertEquals(2, elemsFollowingA.length)
assertEquals("b", b_1.name)
assertEquals("s-1", s1_1.name)
@@ -1093,30 +1093,30 @@ class TestDsomCompilerNew extends Logging {
val elemsFollowingB = b.possibleNextTerms
val Seq(seqFollowingB: Sequence) = b.possibleNextTerms
- val Seq(s1_2: LocalElementBase, s2_2: LocalElementBase, s3_2: LocalElementBase) = seqFollowingB.groupMembers
+ val Seq(s1_2: ElementBase, s2_2: ElementBase, s3_2: ElementBase) = seqFollowingB.groupMembers
assertEquals(1, elemsFollowingB.length)
assertEquals("s-1", s1_2.name)
assertEquals("s-2", s2_2.name)
assertEquals("s-3", s3_2.name)
val elemsFollowingC = c.possibleNextTerms
- val Seq(two_2: LocalElementBase, three_2: LocalElementBase, seqFollowingThree_2: Sequence) = c.possibleNextTerms
- val Seq(four_2: LocalElementBase) = seqFollowingThree_2.groupMembers
+ val Seq(two_2: ElementBase, three_2: ElementBase, seqFollowingThree_2: Sequence) = c.possibleNextTerms
+ val Seq(four_2: ElementBase) = seqFollowingThree_2.groupMembers
assertEquals(3, elemsFollowingC.length)
assertEquals("two", two_2.name)
assertEquals("three", three_2.name)
assertEquals("four", four_2.name)
val elemsFollowingTwo = two.possibleNextTerms
- val Seq(three_3: LocalElementBase, seqFollowingThree_3: Sequence) = two.possibleNextTerms
- val Seq(four_3: LocalElementBase) = seqFollowingThree_3.groupMembers
+ val Seq(three_3: ElementBase, seqFollowingThree_3: Sequence) = two.possibleNextTerms
+ val Seq(four_3: ElementBase) = seqFollowingThree_3.groupMembers
assertEquals(2, elemsFollowingTwo.length)
assertEquals("three", three_3.name)
assertEquals("four", four_3.name)
val elemsFollowingThree = three.possibleNextTerms
val Seq(seqFollowingThree_4: Sequence) = three.possibleNextTerms
- val Seq(four_4: LocalElementBase) = seqFollowingThree_4.groupMembers
+ val Seq(four_4: ElementBase) = seqFollowingThree_4.groupMembers
assertEquals(1, elemsFollowingThree.length)
assertEquals("four", four_4.name)
@@ -1221,8 +1221,8 @@ class TestDsomCompilerNew extends Logging {
val oneCTSeq = oneCT.sequence
val elemsFollowingOneCTSeq = oneCTSeq.possibleNextTerms
- val Seq(two_1: LocalElementBase, three_1: LocalElementBase, seqFollowingThree_1: Sequence) = oneCTSeq.possibleNextTerms
- val Seq(four_1: LocalElementBase) = seqFollowingThree_1.groupMembers
+ val Seq(two_1: ElementBase, three_1: ElementBase, seqFollowingThree_1: Sequence) = oneCTSeq.possibleNextTerms
+ val Seq(four_1: ElementBase) = seqFollowingThree_1.groupMembers
assertEquals(3, elemsFollowingOneCTSeq.length)
assertEquals("two", two_1.name)
assertEquals("three", three_1.name)
@@ -1231,8 +1231,8 @@ class TestDsomCompilerNew extends Logging {
val Seq(_: Sequence, a: LocalElementDecl, b: LocalElementDecl, c: LocalElementDecl) = oneCTSeq.groupMembers
val elemsFollowingA = a.possibleNextTerms
- val Seq(b_2: LocalElementBase, c_2: LocalElementBase, two_2: LocalElementBase, three_2: LocalElementBase, seqFollowingThree_2: Sequence) = a.possibleNextTerms
- val Seq(four_2: LocalElementBase) = seqFollowingThree_2.groupMembers
+ val Seq(b_2: ElementBase, c_2: ElementBase, two_2: ElementBase, three_2: ElementBase, seqFollowingThree_2: Sequence) = a.possibleNextTerms
+ val Seq(four_2: ElementBase) = seqFollowingThree_2.groupMembers
assertEquals(5, elemsFollowingA.length)
assertEquals("b", b_2.name)
assertEquals("c", c_2.name)
@@ -1241,8 +1241,8 @@ class TestDsomCompilerNew extends Logging {
assertEquals("four", four_2.name)
val elemsFollowingB = b.possibleNextTerms
- val Seq(c_3: LocalElementBase, two_3: LocalElementBase, three_3: LocalElementBase, seqFollowingThree_3: Sequence) = b.possibleNextTerms
- val Seq(four_3: LocalElementBase) = seqFollowingThree_3.groupMembers
+ val Seq(c_3: ElementBase, two_3: ElementBase, three_3: ElementBase, seqFollowingThree_3: Sequence) = b.possibleNextTerms
+ val Seq(four_3: ElementBase) = seqFollowingThree_3.groupMembers
assertEquals(4, elemsFollowingB.length)
assertEquals("c", c_3.name)
assertEquals("two", two_3.name)
@@ -1250,23 +1250,23 @@ class TestDsomCompilerNew extends Logging {
assertEquals("four", four_3.name)
val elemsFollowingC = c.possibleNextTerms
- val Seq(two_4: LocalElementBase, three_4: LocalElementBase, seqFollowingThree_4: Sequence) = c.possibleNextTerms
- val Seq(four_4: LocalElementBase) = seqFollowingThree_4.groupMembers
+ val Seq(two_4: ElementBase, three_4: ElementBase, seqFollowingThree_4: Sequence) = c.possibleNextTerms
+ val Seq(four_4: ElementBase) = seqFollowingThree_4.groupMembers
assertEquals(3, elemsFollowingC.length)
assertEquals("two", two_4.name)
assertEquals("three", three_4.name)
assertEquals("four", four_4.name)
val elemsFollowingTwo = two.possibleNextTerms
- val Seq(three_5: LocalElementBase, seqFollowingThree_5: Sequence) = two.possibleNextTerms
- val Seq(four_5: LocalElementBase) = seqFollowingThree_5.groupMembers
+ val Seq(three_5: ElementBase, seqFollowingThree_5: Sequence) = two.possibleNextTerms
+ val Seq(four_5: ElementBase) = seqFollowingThree_5.groupMembers
assertEquals(2, elemsFollowingTwo.length)
assertEquals("three", three_5.name)
assertEquals("four", four_5.name)
val elemsFollowingThree = three.possibleNextTerms
val Seq(seqFollowingThree_6: Sequence) = three.possibleNextTerms
- val Seq(four_6: LocalElementBase) = seqFollowingThree_6.groupMembers
+ val Seq(four_6: ElementBase) = seqFollowingThree_6.groupMembers
assertEquals(1, elemsFollowingThree.length)
assertEquals("four", four_6.name)
@@ -1335,26 +1335,26 @@ class TestDsomCompilerNew extends Logging {
val elemsFollowingRootSeq = rootCTSeq.possibleNextTerms
assertEquals(0, elemsFollowingRootSeq.length)
- val Seq(one: LocalElementBase, two: LocalElementBase, three: LocalElementBase) =
+ val Seq(one: ElementBase, two: ElementBase, three: ElementBase) =
rootCTSeq.groupMembers // has an element and a sub-sequence as its children.
val elemsFollowingOne = one.possibleNextTerms
assertEquals(3, elemsFollowingOne.length)
- assertEquals("one", elemsFollowingOne(0).asInstanceOf[LocalElementBase].name)
- assertEquals("two", elemsFollowingOne(1).asInstanceOf[LocalElementBase].name)
- assertEquals("three", elemsFollowingOne(2).asInstanceOf[LocalElementBase].name)
+ assertEquals("one", elemsFollowingOne(0).asInstanceOf[ElementBase].name)
+ assertEquals("two", elemsFollowingOne(1).asInstanceOf[ElementBase].name)
+ assertEquals("three", elemsFollowingOne(2).asInstanceOf[ElementBase].name)
val elemsFollowingTwo = two.possibleNextTerms
assertEquals(3, elemsFollowingTwo.length)
- assertEquals("one", elemsFollowingTwo(0).asInstanceOf[LocalElementBase].name)
- assertEquals("two", elemsFollowingTwo(1).asInstanceOf[LocalElementBase].name)
- assertEquals("three", elemsFollowingTwo(2).asInstanceOf[LocalElementBase].name)
+ assertEquals("one", elemsFollowingTwo(0).asInstanceOf[ElementBase].name)
+ assertEquals("two", elemsFollowingTwo(1).asInstanceOf[ElementBase].name)
+ assertEquals("three", elemsFollowingTwo(2).asInstanceOf[ElementBase].name)
val elemsFollowingThree = three.possibleNextTerms
assertEquals(3, elemsFollowingThree.length)
- assertEquals("one", elemsFollowingThree(0).asInstanceOf[LocalElementBase].name)
- assertEquals("two", elemsFollowingThree(1).asInstanceOf[LocalElementBase].name)
- assertEquals("three", elemsFollowingThree(2).asInstanceOf[LocalElementBase].name)
+ assertEquals("one", elemsFollowingThree(0).asInstanceOf[ElementBase].name)
+ assertEquals("two", elemsFollowingThree(1).asInstanceOf[ElementBase].name)
+ assertEquals("three", elemsFollowingThree(2).asInstanceOf[ElementBase].name)
}
/**
@@ -1419,26 +1419,26 @@ class TestDsomCompilerNew extends Logging {
val elemsFollowingRootSeq = rootCTSeq.possibleNextTerms
assertEquals(0, elemsFollowingRootSeq.length)
- val Seq(one: LocalElementBase, two: LocalElementBase, three: LocalElementBase) =
+ val Seq(one: ElementBase, two: ElementBase, three: ElementBase) =
rootCTSeq.groupMembers
val elemsFollowingOne = one.possibleNextTerms
assertEquals(3, elemsFollowingOne.length)
- assertEquals("one", elemsFollowingOne(0).asInstanceOf[LocalElementBase].name)
- assertEquals("two", elemsFollowingOne(1).asInstanceOf[LocalElementBase].name)
- assertEquals("three", elemsFollowingOne(2).asInstanceOf[LocalElementBase].name)
+ assertEquals("one", elemsFollowingOne(0).asInstanceOf[ElementBase].name)
+ assertEquals("two", elemsFollowingOne(1).asInstanceOf[ElementBase].name)
+ assertEquals("three", elemsFollowingOne(2).asInstanceOf[ElementBase].name)
val elemsFollowingTwo = two.possibleNextTerms
assertEquals(3, elemsFollowingTwo.length)
- assertEquals("one", elemsFollowingTwo(0).asInstanceOf[LocalElementBase].name)
- assertEquals("two", elemsFollowingTwo(1).asInstanceOf[LocalElementBase].name)
- assertEquals("three", elemsFollowingTwo(2).asInstanceOf[LocalElementBase].name)
+ assertEquals("one", elemsFollowingTwo(0).asInstanceOf[ElementBase].name)
+ assertEquals("two", elemsFollowingTwo(1).asInstanceOf[ElementBase].name)
+ assertEquals("three", elemsFollowingTwo(2).asInstanceOf[ElementBase].name)
val elemsFollowingThree = three.possibleNextTerms
assertEquals(3, elemsFollowingThree.length)
- assertEquals("one", elemsFollowingThree(0).asInstanceOf[LocalElementBase].name)
- assertEquals("two", elemsFollowingThree(1).asInstanceOf[LocalElementBase].name)
- assertEquals("three", elemsFollowingThree(2).asInstanceOf[LocalElementBase].name)
+ assertEquals("one", elemsFollowingThree(0).asInstanceOf[ElementBase].name)
+ assertEquals("two", elemsFollowingThree(1).asInstanceOf[ElementBase].name)
+ assertEquals("three", elemsFollowingThree(2).asInstanceOf[ElementBase].name)
}
/**
@@ -1517,7 +1517,7 @@ class TestDsomCompilerNew extends Logging {
val oneCTSeq = oneCT.sequence
val elemsFollowingOneCTSeq = oneCTSeq.possibleNextTerms
- val Seq(one_1: LocalElementBase, two_1: LocalElementBase, three_1: LocalElementBase) = oneCTSeq.possibleNextTerms
+ val Seq(one_1: ElementBase, two_1: ElementBase, three_1: ElementBase) = oneCTSeq.possibleNextTerms
assertEquals(3, elemsFollowingOneCTSeq.length)
assertEquals("one", one_1.name)
assertEquals("two", two_1.name)
@@ -1527,24 +1527,24 @@ class TestDsomCompilerNew extends Logging {
val elemsFollowingA = a.possibleNextTerms
assertEquals(6, elemsFollowingA.length)
- assertEquals("a", elemsFollowingA(0).asInstanceOf[LocalElementBase].name)
- assertEquals("b", elemsFollowingA(1).asInstanceOf[LocalElementBase].name)
- assertEquals("c", elemsFollowingA(2).asInstanceOf[LocalElementBase].name)
- assertEquals("one", elemsFollowingA(3).asInstanceOf[LocalElementBase].name)
- assertEquals("two", elemsFollowingA(4).asInstanceOf[LocalElementBase].name)
- assertEquals("three", elemsFollowingA(5).asInstanceOf[LocalElementBase].name)
+ assertEquals("a", elemsFollowingA(0).asInstanceOf[ElementBase].name)
+ assertEquals("b", elemsFollowingA(1).asInstanceOf[ElementBase].name)
+ assertEquals("c", elemsFollowingA(2).asInstanceOf[ElementBase].name)
+ assertEquals("one", elemsFollowingA(3).asInstanceOf[ElementBase].name)
+ assertEquals("two", elemsFollowingA(4).asInstanceOf[ElementBase].name)
+ assertEquals("three", elemsFollowingA(5).asInstanceOf[ElementBase].name)
val elemsFollowingB = b.possibleNextTerms
assertEquals(6, elemsFollowingB.length)
- assertEquals("a", elemsFollowingB(0).asInstanceOf[LocalElementBase].name)
- assertEquals("b", elemsFollowingB(1).asInstanceOf[LocalElementBase].name)
- assertEquals("c", elemsFollowingB(2).asInstanceOf[LocalElementBase].name)
- assertEquals("one", elemsFollowingB(3).asInstanceOf[LocalElementBase].name)
- assertEquals("two", elemsFollowingB(4).asInstanceOf[LocalElementBase].name)
- assertEquals("three", elemsFollowingB(5).asInstanceOf[LocalElementBase].name)
+ assertEquals("a", elemsFollowingB(0).asInstanceOf[ElementBase].name)
+ assertEquals("b", elemsFollowingB(1).asInstanceOf[ElementBase].name)
+ assertEquals("c", elemsFollowingB(2).asInstanceOf[ElementBase].name)
+ assertEquals("one", elemsFollowingB(3).asInstanceOf[ElementBase].name)
+ assertEquals("two", elemsFollowingB(4).asInstanceOf[ElementBase].name)
+ assertEquals("three", elemsFollowingB(5).asInstanceOf[ElementBase].name)
val elemsFollowingC = c.possibleNextTerms
- val Seq(a_2: LocalElementBase, b_2: LocalElementBase, c_2: LocalElementBase, one_2: LocalElementBase, two_2: LocalElementBase, three_2: LocalElementBase) = c.possibleNextTerms
+ val Seq(a_2: ElementBase, b_2: ElementBase, c_2: ElementBase, one_2: ElementBase, two_2: ElementBase, three_2: ElementBase) = c.possibleNextTerms
assertEquals(6, elemsFollowingC.length)
assertEquals("a", a_2.name)
assertEquals("b", b_2.name)
@@ -1554,14 +1554,14 @@ class TestDsomCompilerNew extends Logging {
assertEquals("three", three_2.name)
val elemsFollowingTwo = two.possibleNextTerms
- val Seq(one_3: LocalElementBase, two_3: LocalElementBase, three_3: LocalElementBase) = two.possibleNextTerms
+ val Seq(one_3: ElementBase, two_3: ElementBase, three_3: ElementBase) = two.possibleNextTerms
assertEquals(3, elemsFollowingTwo.length)
assertEquals("one", one_3.name)
assertEquals("two", two_3.name)
assertEquals("three", three_3.name)
val elemsFollowingThree = three.possibleNextTerms
- val Seq(one_4: LocalElementBase, two_4: LocalElementBase, three_4: LocalElementBase) = three.possibleNextTerms
+ val Seq(one_4: ElementBase, two_4: ElementBase, three_4: ElementBase) = three.possibleNextTerms
assertEquals(3, elemsFollowingThree.length)
assertEquals("one", one_4.name)
assertEquals("two", two_4.name)
@@ -1644,7 +1644,7 @@ class TestDsomCompilerNew extends Logging {
val oneCTSeq = oneCT.sequence
val elemsFollowingOneCTSeq = oneCTSeq.possibleNextTerms
- val Seq(one_1: LocalElementBase, two_1: LocalElementBase, three_1: LocalElementBase) = oneCTSeq.possibleNextTerms
+ val Seq(one_1: ElementBase, two_1: ElementBase, three_1: ElementBase) = oneCTSeq.possibleNextTerms
assertEquals(3, elemsFollowingOneCTSeq.length)
assertEquals("one", one_1.name)
assertEquals("two", two_1.name)
@@ -1654,28 +1654,28 @@ class TestDsomCompilerNew extends Logging {
val elemsFollowingA = a.possibleNextTerms
assertEquals(1, elemsFollowingA.length)
- assertEquals("b", elemsFollowingA(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("b", elemsFollowingA(0).asInstanceOf[ElementBase].name)
val elemsFollowingB = b.possibleNextTerms
assertEquals(1, elemsFollowingB.length)
- assertEquals("c", elemsFollowingB(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("c", elemsFollowingB(0).asInstanceOf[ElementBase].name)
val elemsFollowingC = c.possibleNextTerms
- val Seq(one_2: LocalElementBase, two_2: LocalElementBase, three_2: LocalElementBase) = c.possibleNextTerms
+ val Seq(one_2: ElementBase, two_2: ElementBase, three_2: ElementBase) = c.possibleNextTerms
assertEquals(3, elemsFollowingC.length)
assertEquals("one", one_2.name)
assertEquals("two", two_2.name)
assertEquals("three", three_2.name)
val elemsFollowingTwo = two.possibleNextTerms
- val Seq(one_3: LocalElementBase, two_3: LocalElementBase, three_3: LocalElementBase) = two.possibleNextTerms
+ val Seq(one_3: ElementBase, two_3: ElementBase, three_3: ElementBase) = two.possibleNextTerms
assertEquals(3, elemsFollowingTwo.length)
assertEquals("one", one_3.name)
assertEquals("two", two_3.name)
assertEquals("three", three_3.name)
val elemsFollowingThree = three.possibleNextTerms
- val Seq(one_4: LocalElementBase, two_4: LocalElementBase, three_4: LocalElementBase) = three.possibleNextTerms
+ val Seq(one_4: ElementBase, two_4: ElementBase, three_4: ElementBase) = three.possibleNextTerms
assertEquals(3, elemsFollowingThree.length)
assertEquals("one", one_4.name)
assertEquals("two", two_4.name)
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/test/scala-new/edu/illinois/ncsa/daffodil/dsom/TestMiddleEndAttributes3.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/test/scala-new/edu/illinois/ncsa/daffodil/dsom/TestMiddleEndAttributes3.scala b/daffodil-core/src/test/scala-new/edu/illinois/ncsa/daffodil/dsom/TestMiddleEndAttributes3.scala
index 8472871..8ea89a5 100644
--- a/daffodil-core/src/test/scala-new/edu/illinois/ncsa/daffodil/dsom/TestMiddleEndAttributes3.scala
+++ b/daffodil-core/src/test/scala-new/edu/illinois/ncsa/daffodil/dsom/TestMiddleEndAttributes3.scala
@@ -138,7 +138,7 @@ class TestMiddleEndAttributes3 {
assertNotNull(ile_nextSibling)
val ilct = ile.complexType
val ilseq = ilct.sequence
- val Seq(_: ElementBase, _: Sequence, ipsrcle: ElementBase) = ilseq.groupMembers
+ val Seq(_: ElementBase, _: SequenceGroupRef, ipsrcle: ElementBase) = ilseq.groupMembers
val nextSiblings = ipsrcle.nextSibling
assertNotNull(nextSiblings)
val nextParents = ipsrcle.nextParentElements
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestCouldBeNextElement.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestCouldBeNextElement.scala b/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestCouldBeNextElement.scala
index 1fc274f..159d1ec 100644
--- a/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestCouldBeNextElement.scala
+++ b/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestCouldBeNextElement.scala
@@ -55,10 +55,10 @@ class TestCouldBeNextElement {
</xs:sequence>
<xs:sequence>
</xs:sequence>
- <xs:element name="bar1" type="xs:string"/>
+ <xs:element name="bar1" type="xs:string" dfdl:lengthKind="explicit" dfdl:length="1"/>
</xs:choice>
- <xs:element name="barOpt" minOccurs="0" dfdl:occursCountKind="implicit" type="xs:string"/>
- <xs:element name="bar2" type="xs:string"/>
+ <xs:element name="barOpt" minOccurs="0" dfdl:occursCountKind="implicit" type="xs:string" dfdl:lengthKind="explicit" dfdl:length="1"/>
+ <xs:element name="bar2" type="xs:string" dfdl:lengthKind="explicit" dfdl:length="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>)
@@ -72,25 +72,27 @@ class TestCouldBeNextElement {
val rootCT = root.complexType
val rootSeq = rootCT.sequence
- val Seq(choice1: Choice, barOpt: LocalElementBase, bar2: LocalElementBase) = rootSeq.groupMembers
- val Seq(choice1seq1: Sequence, choice1seq2: Sequence, bar1: LocalElementBase) = choice1.groupMembers
+ val Seq(choice1: Choice, barOpt: ElementBase, bar2: ElementBase) = rootSeq.groupMembers
+ val Seq(choice1seq1: Sequence, choice1seq2: Sequence, bar1: ElementBase) = choice1.groupMembers
val Seq(gm: Sequence) = choice1seq1.groupMembers
assertNotNull(gm)
assertEquals(0, root.possibleNextChildElementsInInfoset.length)
assertEquals(3, root.possibleFirstChildElementsInInfoset.length)
- assertEquals("bar1", root.possibleFirstChildElementsInInfoset(0).asInstanceOf[LocalElementBase].name)
- assertEquals("barOpt", root.possibleFirstChildElementsInInfoset(1).asInstanceOf[LocalElementBase].name)
- assertEquals("bar2", root.possibleFirstChildElementsInInfoset(2).asInstanceOf[LocalElementBase].name)
+ assertEquals("bar1", root.possibleFirstChildElementsInInfoset(0).asInstanceOf[ElementBase].name)
+ assertEquals("barOpt", root.possibleFirstChildElementsInInfoset(1).asInstanceOf[ElementBase].name)
+ assertEquals("bar2", root.possibleFirstChildElementsInInfoset(2).asInstanceOf[ElementBase].name)
+ //val bar1PFCEII = bar1.possibleFirstChildElementsInInfoset
+ //val bar1PNCEII = bar1.possibleNextChildElementsInInfoset
assertEquals(0, bar1.possibleFirstChildElementsInInfoset.length)
assertEquals(2, bar1.possibleNextChildElementsInInfoset.length)
- assertEquals("barOpt", bar1.possibleNextChildElementsInInfoset(0).asInstanceOf[LocalElementBase].name)
- assertEquals("bar2", bar1.possibleNextChildElementsInInfoset(1).asInstanceOf[LocalElementBase].name)
+ assertEquals("barOpt", bar1.possibleNextChildElementsInInfoset(0).asInstanceOf[ElementBase].name)
+ assertEquals("bar2", bar1.possibleNextChildElementsInInfoset(1).asInstanceOf[ElementBase].name)
assertEquals(0, barOpt.possibleFirstChildElementsInInfoset.length)
assertEquals(1, barOpt.possibleNextChildElementsInInfoset.length)
- assertEquals("bar2", barOpt.possibleNextChildElementsInInfoset(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("bar2", barOpt.possibleNextChildElementsInInfoset(0).asInstanceOf[ElementBase].name)
assertEquals(0, bar2.possibleFirstChildElementsInInfoset.length)
assertEquals(0, bar2.possibleNextChildElementsInInfoset.length)
@@ -139,24 +141,24 @@ class TestCouldBeNextElement {
val rootCT = root.complexType
val rootSeq = rootCT.sequence
- val Seq(array: LocalElementBase, after: LocalElementBase) = rootSeq.groupMembers
+ val Seq(array: ElementBase, after: ElementBase) = rootSeq.groupMembers
val arrayCT = array.complexType
val choice = arrayCT.modelGroup.asInstanceOf[Choice]
- val Seq(ch1: LocalElementBase, ch2: LocalElementBase, array2: LocalElementBase, choiceSeq: Sequence) = choice.groupMembers
+ val Seq(ch1: ElementBase, ch2: ElementBase, array2: ElementBase, choiceSeq: Sequence) = choice.groupMembers
assertEquals(0, root.possibleNextChildElementsInInfoset.length)
assertEquals(2, root.possibleFirstChildElementsInInfoset.length)
- assertEquals("array", root.possibleFirstChildElementsInInfoset(0).asInstanceOf[LocalElementBase].name)
- assertEquals("after", root.possibleFirstChildElementsInInfoset(1).asInstanceOf[LocalElementBase].name)
+ assertEquals("array", root.possibleFirstChildElementsInInfoset(0).asInstanceOf[ElementBase].name)
+ assertEquals("after", root.possibleFirstChildElementsInInfoset(1).asInstanceOf[ElementBase].name)
assertEquals(3, array.possibleFirstChildElementsInInfoset.length)
- assertEquals("ch1", array.possibleFirstChildElementsInInfoset(0).asInstanceOf[LocalElementBase].name)
- assertEquals("ch2", array.possibleFirstChildElementsInInfoset(1).asInstanceOf[LocalElementBase].name)
- assertEquals("array", array.possibleFirstChildElementsInInfoset(2).asInstanceOf[LocalElementBase].name)
+ assertEquals("ch1", array.possibleFirstChildElementsInInfoset(0).asInstanceOf[ElementBase].name)
+ assertEquals("ch2", array.possibleFirstChildElementsInInfoset(1).asInstanceOf[ElementBase].name)
+ assertEquals("array", array.possibleFirstChildElementsInInfoset(2).asInstanceOf[ElementBase].name)
assertEquals(2, array.possibleNextChildElementsInInfoset.length)
- assertEquals("array", array.possibleNextChildElementsInInfoset(0).asInstanceOf[LocalElementBase].name)
- assertEquals("after", array.possibleNextChildElementsInInfoset(1).asInstanceOf[LocalElementBase].name)
+ assertEquals("array", array.possibleNextChildElementsInInfoset(0).asInstanceOf[ElementBase].name)
+ assertEquals("after", array.possibleNextChildElementsInInfoset(1).asInstanceOf[ElementBase].name)
assertEquals(0, after.possibleFirstChildElementsInInfoset.length)
assertEquals(0, after.possibleNextChildElementsInInfoset.length)
@@ -199,17 +201,17 @@ class TestCouldBeNextElement {
val rootCT = root.complexType
val rootSeq = rootCT.sequence
- val Seq(e1: LocalElementBase, e2: LocalElementBase, e3: LocalElementBase) = rootSeq.groupMembers
+ val Seq(e1: ElementBase, e2: ElementBase, e3: ElementBase) = rootSeq.groupMembers
assertEquals(0, root.possibleNextChildElementsInInfoset.length)
assertEquals(1, root.possibleFirstChildElementsInInfoset.length)
- assertEquals("e1", root.possibleFirstChildElementsInInfoset(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("e1", root.possibleFirstChildElementsInInfoset(0).asInstanceOf[ElementBase].name)
assertEquals(1, e1.possibleNextChildElementsInInfoset.length)
- assertEquals("e2", e1.possibleNextChildElementsInInfoset(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("e2", e1.possibleNextChildElementsInInfoset(0).asInstanceOf[ElementBase].name)
assertEquals(1, e2.possibleNextChildElementsInInfoset.length)
- assertEquals("e3", e2.possibleNextChildElementsInInfoset(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("e3", e2.possibleNextChildElementsInInfoset(0).asInstanceOf[ElementBase].name)
assertEquals(0, e3.possibleNextChildElementsInInfoset.length)
}
@@ -220,15 +222,15 @@ class TestCouldBeNextElement {
<xs:element name="root">
<xs:complexType>
<xs:sequence>
- <xs:element name="e1" type="xs:string" />
- <xs:sequence dfdl:hiddenGroupRef="g1_hidden" />
- <xs:element name="e2" type="xs:string" dfdl:occursCountKind="parsed" />
+ <xs:element name="e1" type="xs:string"/>
+ <xs:sequence dfdl:hiddenGroupRef="g1_hidden"/>
+ <xs:element name="e2" type="xs:string" dfdl:occursCountKind="parsed"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:group name="g1_hidden">
<xs:sequence>
- <xs:element name="e2_hidden" type="xs:string" dfdl:occursCountKind="parsed" />
+ <xs:element name="e2_hidden" type="xs:string" dfdl:occursCountKind="parsed"/>
</xs:sequence>
</xs:group>)
@@ -242,11 +244,11 @@ class TestCouldBeNextElement {
assertEquals(0, root.possibleNextChildElementsInInfoset.length)
assertEquals(1, root.possibleFirstChildElementsInInfoset.length)
- val e1 = root.possibleFirstChildElementsInInfoset(0).asInstanceOf[LocalElementBase]
+ val e1 = root.possibleFirstChildElementsInInfoset(0).asInstanceOf[ElementBase]
assertEquals("e1", e1.name)
assertEquals(1, e1.possibleNextChildElementsInInfoset.length)
- assertEquals("e2", e1.possibleNextChildElementsInInfoset(0).asInstanceOf[LocalElementBase].name)
+ assertEquals("e2", e1.possibleNextChildElementsInInfoset(0).asInstanceOf[ElementBase].name)
}
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestDsomCompiler.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestDsomCompiler.scala b/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestDsomCompiler.scala
index 9ed89d4..df2413d 100644
--- a/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestDsomCompiler.scala
+++ b/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestDsomCompiler.scala
@@ -45,7 +45,6 @@ import junit.framework.Assert._
import edu.illinois.ncsa.daffodil.api.Diagnostic
import edu.illinois.ncsa.daffodil.util.SchemaUtils
import org.junit.Test
-import edu.illinois.ncsa.daffodil.util.Fakes
import edu.illinois.ncsa.daffodil.schema.annotation.props.Found
class TestDsomCompiler extends Logging {
@@ -61,7 +60,6 @@ class TestDsomCompiler extends Logging {
// these tests don't use this. If you make this an eager val, then if there
// is any problem in the Fakes, the whole class can't be constructed, and None
// of the tests will run. Lazy lets this class be constructed no matter what.
- lazy val dummyGroupRef = Fakes.fakeGroupRef
@Test def testHasProps() {
val testSchema = SchemaUtils.dfdlTestSchema(
@@ -229,7 +227,7 @@ class TestDsomCompiler extends Logging {
val sset = new SchemaSet(testSchema)
val Seq(sch) = sset.schemas
- val Seq(sd) = sch.schemaDocuments
+ val Seq(sd, _) = sch.schemaDocuments
// No annotations
val Seq(gct) = sd.globalComplexTypeDefs
@@ -237,9 +235,10 @@ class TestDsomCompiler extends Logging {
// Explore global element decl
val Seq(e1f, e2f, e3f, _, _) = sd.globalElementDecls // there are 3 factories
- val e1 = e1f.forRoot()
+ val root1 = e1f.forRoot()
+ val e1 = root1.referencedElement
e2f.forRoot()
- val e3 = e3f.forRoot()
+ val e3 = e3f.forRoot().referencedElement
assertEquals(
ByteOrder.BigEndian.toString.toLowerCase(),
e1.formatAnnotation.asInstanceOf[DFDLElement].getProperty("byteOrder").toLowerCase())
@@ -278,29 +277,33 @@ class TestDsomCompiler extends Logging {
assertEquals("%%", es) // has escapeCharacter="%%" (note: string literals not digested yet, so %% is %%, not %.
// Explore global group defs
- val Seq(gr1, gr2, _, _, _) = sd.globalGroupDefs // there are two
- val seq1 = gr1.forGroupRef(dummyGroupRef, 1).modelGroup.asInstanceOf[Sequence]
+ val Seq(_, gedf, _*) = sd.globalElementDecls
+ val root = gedf.forRoot()
+ val seq1 = root.complexType.modelGroup.asInstanceOf[SequenceGroupRef]
+
+ val Seq(e1r: ElementRef, cgr: ChoiceGroupRef) = seq1.groupMembers
+
+ val Seq(ggd1, ggd2, _, _, _) = sd.globalGroupDefs // there are two
+ assertEquals("gr", ggd1.namedQName.local)
+ assertEquals("hiddenGroup", ggd2.namedQName.local)
//Explore LocalSimpleTypeDef
- val Seq(gr2c1, _, gr2c3) = gr2.forGroupRef(dummyGroupRef, 1).modelGroup.asInstanceOf[ModelGroup].groupMembers
- val ist = gr2c3.asInstanceOf[LocalElementDecl].immediateType.get.asInstanceOf[LocalSimpleTypeDef]
+ val Seq(c1: LocalElementDecl, _: LocalElementDecl, c3: LocalElementDecl) = cgr.groupMembers
+ val ist = c3.asInstanceOf[LocalElementDecl].immediateType.get.asInstanceOf[LocalSimpleTypeDef]
val istBase = ist.optRestriction.get.baseQName.toQNameString
assertEquals("tns:aType", istBase)
//Explore LocalElementDecl
- val led = gr2c1.asInstanceOf[LocalElementDecl]
- assertEquals(1, led.maxOccurs)
- val Seq(leda) = led.annotationObjs
- assertEquals("{ $myVar1 eq (+47 mod 4) }", leda.asInstanceOf[DFDLDiscriminator].testBody.get)
+ assertEquals(1, c1.maxOccurs)
+ val Seq(c1a) = c1.annotationObjs
+ assertEquals("{ $myVar1 eq (+47 mod 4) }", c1a.asInstanceOf[DFDLDiscriminator].testBody.get)
// Explore sequence
- val Seq(ann: DFDLSequence) = seq1.annotationObjs // one format annotation with a property
+ val Seq(ann: DFDLGroup) = seq1.annotationObjs // one format annotation with a property
assertNotNull(ann)
assertEquals(SeparatorPosition.Infix, seq1.separatorPosition)
- val Seq(seq1e1, seq1s1) = seq1.groupMembers // has an element and a sub-sequence as its children.
- assertEquals(2, seq1e1.asInstanceOf[ElementRef].maxOccurs)
- assertEquals("ex:a", seq1e1.asInstanceOf[ElementRef].ref)
- assertEquals(1, seq1s1.asInstanceOf[Sequence].groupMembers.length) // it has the hidden group
+ assertEquals(2, e1r.maxOccurs)
+ assertEquals("ex:a", e1r.ref)
}
@Test def test4 {
@@ -308,23 +311,28 @@ class TestDsomCompiler extends Logging {
val sset = new SchemaSet(testSchema)
val Seq(sch) = sset.schemas
- val Seq(sd) = sch.schemaDocuments
+ val Seq(sd, _) = sch.schemaDocuments
+
+ // Explore global group defs
+ val Seq(_, gedf, _*) = sd.globalElementDecls
+ val root = gedf.forRoot()
+ val seq1 = root.complexType.modelGroup.asInstanceOf[SequenceGroupRef]
- val Seq(_, gd2f, _, _, _) = sd.globalGroupDefs // Obtain Group nodes
- val gd2 = gd2f.forGroupRef(dummyGroupRef, 1)
- val ch1 = gd2.modelGroup.asInstanceOf[Choice] // Downcast child-node of group to Choice
- val Seq(_, cd2, _) = ch1.groupMembers // Children nodes of Choice-node, there are 3
+ val Seq(_: ElementRef, gr: GroupRef) = seq1.groupMembers
+ val cgd = gr.groupDef.asInstanceOf[GlobalChoiceGroupDef]
+ val cgr = cgd.groupRef.asInstanceOf[ChoiceGroupRef]
+ val Seq(_, cd2: LocalElementDecl, _) = cgd.groupMembers // Children nodes of Choice-node, there are 3
// val Seq(a1: DFDLChoice) = ch1.annotationObjs // Obtain the annotation object that is a child
// of the group node.
- assertEquals(AlignmentType.Implicit, ch1.alignment)
- assertEquals(ChoiceLengthKind.Implicit, ch1.choiceLengthKind)
+ assertEquals(AlignmentType.Implicit, cgr.alignment)
+ assertEquals(ChoiceLengthKind.Implicit, cgr.choiceLengthKind)
- val Seq(asrt1) = cd2.asInstanceOf[LocalElementDecl].annotationObjs // Obtain Annotation object that is child
+ val Seq(asrt1: DFDLAssert) = cd2.annotationObjs // Obtain Annotation object that is child
// of cd2.
- assertEquals("{ $myVar1 eq xs:int(xs:string(fn:round-half-to-even(8.5))) }", asrt1.asInstanceOf[DFDLAssert].testTxt)
+ assertEquals("{ $myVar1 eq xs:int(xs:string(fn:round-half-to-even(8.5))) }", asrt1.testTxt)
}
@Test def test_named_format_chaining {
@@ -338,7 +346,7 @@ class TestDsomCompiler extends Logging {
val Seq(sd) = sch.schemaDocuments
val Seq(ge1f, _, _, _, _, _) = sd.globalElementDecls // Obtain global element nodes
- val ge1 = ge1f.forRoot()
+ val ge1 = ge1f.forRoot().referencedElement
val Seq(a1: DFDLElement) = ge1.annotationObjs
assertEquals(true, a1.verifyPropValue("occursCountKind", "parsed"))
@@ -407,7 +415,7 @@ class TestDsomCompiler extends Logging {
val sset = new SchemaSet(testSchema)
val Seq(sch) = sset.schemas
- val Seq(sd) = sch.schemaDocuments
+ val Seq(sd, _) = sch.schemaDocuments
// No annotations
val Seq(gct) = sd.globalComplexTypeDefs
@@ -415,7 +423,7 @@ class TestDsomCompiler extends Logging {
// Explore global element decl
val Seq(e1f, e2f, e3f, _, _) = sd.globalElementDecls // there are 3 factories
- val e1 = e1f.forRoot()
+ val e1 = e1f.forRoot().referencedElement
e2f.forRoot()
e3f.forRoot()
@@ -428,14 +436,14 @@ class TestDsomCompiler extends Logging {
assertEquals("ex", baseQName.prefix.get)
assertEquals("aaType", baseQName.local)
- assertTrue(gs1.verifyPropValue("alignmentUnits", "bytes")) // SimpleType - Local
+ assertTrue(gs1.term.verifyPropValue("alignmentUnits", "bytes")) // SimpleType - Local
- assertTrue(gs1.verifyPropValue("byteOrder", "bigEndian")) // SimpleType - Base
- assertTrue(gs1.verifyPropValue("occursCountKind", "implicit")) // Default Format
- assertTrue(gs1.verifyPropValue("representation", "text")) // Define Format - def1
- assertTrue(gs1.verifyPropValue("encoding", "utf-8")) // Define Format - def1
- assertTrue(gs1.verifyPropValue("textStandardBase", "10")) // Define Format - def2
- assertTrue(gs1.verifyPropValue("escapeSchemeRef", "tns:quotingScheme")) // Define Format - def2
+ assertTrue(gs1.term.verifyPropValue("byteOrder", "bigEndian")) // SimpleType - Base
+ assertTrue(gs1.term.verifyPropValue("occursCountKind", "implicit")) // Default Format
+ assertTrue(gs1.term.verifyPropValue("representation", "text")) // Define Format - def1
+ assertTrue(gs1.term.verifyPropValue("encoding", "UTF-8")) // Define Format - def1
+ assertTrue(gs1.term.verifyPropValue("textStandardBase", "10")) // Define Format - def2
+ assertTrue(gs1.term.verifyPropValue("escapeSchemeRef", "tns:quotingScheme")) // Define Format - def2
val gs3 = gs3f.forElement(e1) // Global SimpleType - aTypeError - overlapping base props
@@ -453,7 +461,7 @@ class TestDsomCompiler extends Logging {
val sset = new SchemaSet(testSchema)
val Seq(sch) = sset.schemas
- val Seq(sd) = sch.schemaDocuments
+ val Seq(sd, _) = sch.schemaDocuments
// No annotations
val Seq(g) = sd.globalComplexTypeDefs;
@@ -467,13 +475,11 @@ class TestDsomCompiler extends Logging {
val e4ct = e4.complexType
- val e4ctgref = e4ct.modelGroup.asInstanceOf[GroupRef] // groupRefTests' local group decl
+ val e4ctgref = e4ct.modelGroup.asInstanceOf[GroupRef]
- val myGlobal1 = e4ctgref.groupDef
+ val myGlobal1Seq = e4ctgref.asInstanceOf[SequenceTermBase]
- val myGlobal1Seq = myGlobal1.modelGroup.asInstanceOf[Sequence]
-
- val myGlobal2Seq = myGlobal1Seq.groupRefChildren(0).group.asInstanceOf[Sequence]
+ val myGlobal2Seq = myGlobal1Seq.groupMembers(0).asInstanceOf[SequenceGroupRef]
// myGlobal1 Properties
assertTrue(myGlobal1Seq.verifyPropValue("separator", ","))
@@ -488,11 +494,10 @@ class TestDsomCompiler extends Logging {
val e5ct = e5.complexType
- val e5ctgref = e5ct.modelGroup.asInstanceOf[GroupRef] // groupRefTestOverlap's local group decl
-
+ val e5ctgref = e5ct.modelGroup.asInstanceOf[SequenceGroupRef]
val myGlobal3 = e5ctgref.groupDef
// val myGlobal3Seq =
- myGlobal3.modelGroup.asInstanceOf[Sequence]
+ myGlobal3.asInstanceOf[GlobalSequenceGroupDef]
// Tests overlapping properties
assertTrue(e5ctgref.isError)
@@ -552,7 +557,7 @@ class TestDsomCompiler extends Logging {
@Test def testGetQName = {
val testSchema = SchemaUtils.dfdlTestSchema(
<dfdl:defineFormat name="ref1">
- <dfdl:format initiator=":"/>
+ <dfdl:format initiator=":" alignmentUnits="bits"/>
</dfdl:defineFormat>,
<xs:element name="e1" dfdl:lengthKind="implicit" dfdl:ref="tns:ref1" type="xs:string">
</xs:element>)
@@ -561,7 +566,7 @@ class TestDsomCompiler extends Logging {
val Seq(sd, _) = sch.schemaDocuments
val Seq(ge1f) = sd.globalElementDecls // Obtain global element nodes
- val ge1 = ge1f.forRoot()
+ val ge1 = ge1f.forRoot().referencedElement
val qn = ge1.formatAnnotation.resolveQName("tns:ref1")
val nsURI = qn.namespace
@@ -602,7 +607,7 @@ class TestDsomCompiler extends Logging {
val Seq(sd, _) = sch.schemaDocuments
val Seq(ge1f) = sd.globalElementDecls // Obtain global element nodes
- val ge1 = ge1f.forRoot()
+ val ge1 = ge1f.forRoot().referencedElement
val seq = ge1.sequence
@@ -627,25 +632,23 @@ class TestDsomCompiler extends Logging {
val sset = new SchemaSet(testSchema)
val Seq(sch) = sset.schemas
- val Seq(sd) = sch.schemaDocuments
+ val Seq(sd, _) = sch.schemaDocuments
- // No annotations
- // val Seq(ct) = sd.globalComplexTypeDefs
+ val Seq(_, gedf, _*) = sd.globalElementDecls
+ val root = gedf.forRoot()
+ val sgr = root.complexType.modelGroup.asInstanceOf[SequenceGroupRef]
- // g1.name == "gr"
- val Seq(g1: GlobalGroupDefFactory, _, _, _, _) = sd.globalGroupDefs
+ val Seq(e1r: ElementRef, cgr: ChoiceGroupRef) = sgr.groupMembers
- val seq1 = g1.forGroupRef(dummyGroupRef, 1).modelGroup.asInstanceOf[Sequence]
+ assertEquals("hiddenGroup", cgr.groupDef.namedQName.local)
+ assertEquals(AlignmentType.Implicit, cgr.alignment)
- // e1.ref == "ex:a"
- val Seq(e1r: ElementRef, _: Sequence) = seq1.groupMembers
- val e1 = e1r.referencedElement
assertEquals(2, e1r.maxOccurs)
assertEquals(1, e1r.minOccurs)
- assertEquals(AlignmentUnits.Bytes, e1.alignmentUnits)
+ assertEquals(AlignmentUnits.Bytes, e1r.alignmentUnits)
//assertEquals(true, e1.nillable) // TODO: e1.nillable doesn't exist?
//assertEquals("%ES; %% %#0; %NUL;%ACK; foo%#rF2;%#rF7;bar %WSP*; %#2024;%#xAABB; &ߧ쳝 -1", e1.nilValue) // TODO: Do not equal each other!
- assertEquals(NilKind.LiteralValue, e1.nilKind)
+ assertEquals(NilKind.LiteralValue, e1r.nilKind)
}
@Test def testPathWithIndexes() {
@@ -666,7 +669,7 @@ class TestDsomCompiler extends Logging {
val Seq(sd, _) = sch.schemaDocuments
val Seq(ge1f) = sd.globalElementDecls // Obtain global element nodes
- val ge1 = ge1f.forRoot()
+ val ge1 = ge1f.forRoot().referencedElement
val seq = ge1.sequence
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestMiddleEndAttributes.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestMiddleEndAttributes.scala b/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestMiddleEndAttributes.scala
index 75ec28b..02a747a 100644
--- a/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestMiddleEndAttributes.scala
+++ b/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/dsom/TestMiddleEndAttributes.scala
@@ -264,9 +264,6 @@ class TestMiddleEndAttributes {
val e3seqImmediatelyEnclosingModelGroup = e3seq.immediatelyEnclosingModelGroup
// Sequence inside an element doesn't have an immediately enclosing model group
assertEquals(None, e3seqImmediatelyEnclosingModelGroup)
- // Global element instance appears inside the group that immediately contains the
- // element reference.
- assertEquals(Some(eMsgChoice), e3.immediatelyEnclosingModelGroup)
// element reference also contained inside same
assertEquals(Some(eMsgChoice), e2ref.immediatelyEnclosingModelGroup)
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/TestPropertyRuntime.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/TestPropertyRuntime.scala b/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/TestPropertyRuntime.scala
index 4e2d0fc..f4ca667 100644
--- a/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/TestPropertyRuntime.scala
+++ b/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/TestPropertyRuntime.scala
@@ -35,7 +35,7 @@ package edu.illinois.ncsa.daffodil.schema.annotation.props
import junit.framework.Assert._
import edu.illinois.ncsa.daffodil.exceptions.ThrowsSDE
import org.junit.Test
-import edu.illinois.ncsa.daffodil.dsom.SchemaComponent
+import edu.illinois.ncsa.daffodil.dsom.SchemaComponentImpl
import edu.illinois.ncsa.daffodil.util.Fakes
import edu.illinois.ncsa.daffodil.dsom.NestingLexicalMixin
@@ -88,7 +88,7 @@ class TestPropertyRuntime {
}
-class HasMixin extends SchemaComponent(<foo/>, null)
+class HasMixin extends SchemaComponentImpl(<foo/>, null)
with TheExamplePropMixin
with NestingLexicalMixin {
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/util/TestUtils.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/util/TestUtils.scala b/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/util/TestUtils.scala
index b7c1fc0..33b68b0 100644
--- a/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/util/TestUtils.scala
+++ b/daffodil-core/src/test/scala/edu/illinois/ncsa/daffodil/util/TestUtils.scala
@@ -227,6 +227,9 @@ object Fakes {
def fakeElem = new Fakes().fakeElem
def fakeSD = new Fakes().fakeSD
def fakeGroupRef = new Fakes().fakeGroupRef
+ def fakeChoiceGroupRef = new Fakes().fakeChoiceGroupRef
+ def fakeSequenceGroupRef = new Fakes().fakeSequenceGroupRef
+ def fakeGroupRefFactory = new Fakes().fakeGroupRefFactory
}
class Fakes private () {
@@ -236,14 +239,20 @@ class Fakes private () {
<xs:element name="fake2" type="tns:fakeCT"/>
<xs:complexType name="fakeCT">
<xs:sequence>
- <xs:group ref="tns:fakeGroup"/>
+ <xs:group ref="tns:fakeChoiceGroup"/>
<xs:element ref="tns:fake"/>
+ <xs:group ref="tns:fakeSequenceGroup"/>
</xs:sequence>
</xs:complexType>
- <xs:group name="fakeGroup">
+ <xs:group name="fakeChoiceGroup">
<xs:choice>
<xs:sequence/>
</xs:choice>
+ </xs:group>
+ <xs:group name="fakeSequenceGroup">
+ <xs:sequence>
+ <xs:sequence/>
+ </xs:sequence>
</xs:group>)
val DummyPrimitiveFactory = null
val tunable = DaffodilTunables()
@@ -253,8 +262,11 @@ class Fakes private () {
lazy val fakeElem = fakeSD.getGlobalElementDecl("fake").get.forRoot()
lazy val fakeCT = fakeSD.getGlobalElementDecl("fake2").get.forRoot().typeDef.asInstanceOf[GlobalComplexTypeDef]
lazy val fakeSequence = fakeCT.sequence
- lazy val Seq(fs1, fs2) = fakeSequence.groupMembers
- lazy val fakeGroupRef = fs1.asInstanceOf[GroupRef]
+ lazy val Seq(fs1, fs2, fs3) = fakeSequence.groupMembers
+ lazy val fakeChoiceGroupRef = fs1.asInstanceOf[ChoiceGroupRef]
+ lazy val fakeGroupRef = fakeChoiceGroupRef
+ lazy val fakeSequenceGroupRef = fs3.asInstanceOf[SequenceGroupRef]
+ lazy val fakeGroupRefFactory = new GroupRefFactory(fs1.xml, fs1, 1, false)
class FakeDataProcessor extends DFDL.DataProcessor {
protected var tunablesObj = DaffodilTunables()
@@ -273,9 +285,9 @@ class Fakes private () {
def isError: Boolean = false
def setTunables(tunables: DaffodilTunables): Unit = {}
def setTunable(tunable: String, value: String): Unit = {}
- def setTunables(tunables: Map[String,String]): Unit = {}
+ def setTunables(tunables: Map[String, String]): Unit = {}
def getTunables(): DaffodilTunables = { tunablesObj }
-
+
}
lazy val fakeDP = new FakeDataProcessor
[6/6] incubator-daffodil git commit: Property Resolution - part of
fixing schema compilation
Posted by mb...@apache.org.
Property Resolution - part of fixing schema compilation
Refactors property resolving onto elementrefs and grouprefs so
as to eliminate use of backrefs when accessing properties.
Reorganized DSOM for model groups and references to them.
Converted OOLAGHost, SchemaComponent etc. down to LocalElementBase
into traits so that I can mix them the way I need to so that
Global elements aren't terms, etc.
Group references are allowed to carry annotations like dfdl:assert. It
is global group definitions that cannot. (They can't have annotations
period. Annotations go on the model group within the global group
definition)
SequenceBase is a ModelGroup is a Term, and is
the base of Sequence and SequenceGroupRef.
SequenceGroupDef is not a SequenceBase. It is GroupDefLike in that
it has children. It is not a Term, because the SequenceGroupRef that
refers to it is the Term.
Groups work exactly analogously to Elements now. For Elements, the Terms
are
LocalElementDecl and ElementRef. A GlobalElementDecl is *not* a Term.
Added package scaladoc for dsom and grammar packages.
Decided not to rename ModelGroup, nor ElementBase this go-round.
Decided not to try to fix precision of diagnostic messages - most will
have the location of the element ref/group ref not that of the
referenced definition now.
DFDL-1855
Project: http://git-wip-us.apache.org/repos/asf/incubator-daffodil/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-daffodil/commit/89517717
Tree: http://git-wip-us.apache.org/repos/asf/incubator-daffodil/tree/89517717
Diff: http://git-wip-us.apache.org/repos/asf/incubator-daffodil/diff/89517717
Branch: refs/heads/master
Commit: 895177173781c57fc17ef2c9e957302a82bbf164
Parents: f761e4d
Author: mbeckerle <mb...@tresys.com>
Authored: Mon Oct 23 17:50:21 2017 -0400
Committer: mbeckerle <mb...@tresys.com>
Committed: Thu Nov 16 17:21:06 2017 -0500
----------------------------------------------------------------------
.../ncsa/daffodil/compiler/Compiler.scala | 5 +-
.../ncsa/daffodil/dpath/Expression.scala | 8 +-
.../dsom/AnnotatedSchemaComponent.scala | 243 ++-
.../ncsa/daffodil/dsom/ChoiceGroup.scala | 67 +-
.../ncsa/daffodil/dsom/ComplexTypes.scala | 22 +-
.../ncsa/daffodil/dsom/DFDLAnnotation.scala | 17 +-
.../ncsa/daffodil/dsom/DFDLAssertion.scala | 21 +-
.../ncsa/daffodil/dsom/DFDLFormat.scala | 10 +-
.../daffodil/dsom/DFDLFormatAnnotation.scala | 2 +-
.../ncsa/daffodil/dsom/DFDLSchemaFile.scala | 2 +-
.../ncsa/daffodil/dsom/DFDLStatementMixin.scala | 191 ++-
.../ncsa/daffodil/dsom/ElementBase.scala | 257 +--
.../ncsa/daffodil/dsom/ElementDeclMixin.scala | 140 +-
.../ncsa/daffodil/dsom/ElementRef.scala | 87 +-
.../daffodil/dsom/EscapeSchemeRefMixin.scala | 2 +-
.../ncsa/daffodil/dsom/GlobalElementDecl.scala | 63 +-
.../dsom/GlobalElementDeclFactory.scala | 11 +-
.../illinois/ncsa/daffodil/dsom/GroupBase.scala | 92 -
.../illinois/ncsa/daffodil/dsom/GroupDef.scala | 136 +-
.../illinois/ncsa/daffodil/dsom/GroupRef.scala | 127 +-
.../illinois/ncsa/daffodil/dsom/IIBase.scala | 5 +-
.../dsom/InitiatedTerminatedMixin.scala | 5 +-
.../ncsa/daffodil/dsom/LocalElementBase.scala | 80 -
.../ncsa/daffodil/dsom/LocalElementDecl.scala | 22 +-
.../ncsa/daffodil/dsom/LocalElementMixin.scala | 4 +-
.../ncsa/daffodil/dsom/ModelGroup.scala | 264 +--
.../illinois/ncsa/daffodil/dsom/Nesting.scala | 15 +-
.../ncsa/daffodil/dsom/ParticleMixin.scala | 4 +-
.../ncsa/daffodil/dsom/PropProviders.scala | 2 +
.../ncsa/daffodil/dsom/RealTermMixin.scala | 227 ---
.../ncsa/daffodil/dsom/RestrictionUnion.scala | 8 +-
.../edu/illinois/ncsa/daffodil/dsom/Root.scala | 31 +
.../daffodil/dsom/RuntimePropertyMixins.scala | 7 +-
.../ncsa/daffodil/dsom/SchemaComponent.scala | 79 +-
.../daffodil/dsom/SchemaComponentFactory.scala | 28 +-
.../ncsa/daffodil/dsom/SchemaDocument.scala | 26 +-
.../illinois/ncsa/daffodil/dsom/SchemaSet.scala | 29 +-
.../ncsa/daffodil/dsom/SequenceGroup.scala | 143 +-
.../ncsa/daffodil/dsom/SimpleTypes.scala | 107 +-
.../edu/illinois/ncsa/daffodil/dsom/Term.scala | 391 +++--
.../ncsa/daffodil/dsom/TermEncodingMixin.scala | 8 +-
.../illinois/ncsa/daffodil/dsom/package.scala | 101 ++
.../ncsa/daffodil/grammar/AlignedMixin.scala | 27 +-
.../daffodil/grammar/ChoiceGrammarMixin.scala | 4 +-
.../grammar/ElementBaseGrammarMixin.scala | 11 +-
.../grammar/ElementDeclGrammarMixin.scala | 7 +-
.../grammar/ElementReferenceGrammarMixin.scala | 6 +-
.../ncsa/daffodil/grammar/Grammar.scala | 12 +-
.../ncsa/daffodil/grammar/GrammarMixins.scala | 4 +-
.../ncsa/daffodil/grammar/GrammarTerm.scala | 4 +-
.../grammar/HasStatementsGrammarMixin.scala | 3 +-
.../grammar/LocalElementGrammarMixin.scala | 7 +-
.../grammar/ModelGroupGrammarMixin.scala | 8 +-
.../daffodil/grammar/SequenceGrammarMixin.scala | 4 +-
.../ncsa/daffodil/grammar/package.scala | 104 ++
.../grammar/primitives/Primitives.scala | 10 +-
.../primitives/PrimitivesDelimiters.scala | 2 +-
.../primitives/PrimitivesElementKinds.scala | 27 +-
.../primitives/PrimitivesExpressions.scala | 14 +-
.../PrimitivesUnorderedSequence.scala | 10 +-
.../daffodil/grammar/primitives/RepPrims.scala | 22 +-
.../example-of-most-dfdl-constructs.dfdl.xml | 5 +-
.../daffodil/dsom/TestDsomCompilerNew.scala | 228 +--
.../dsom/TestMiddleEndAttributes3.scala | 2 +-
.../daffodil/dsom/TestCouldBeNextElement.scala | 62 +-
.../ncsa/daffodil/dsom/TestDsomCompiler.scala | 125 +-
.../daffodil/dsom/TestMiddleEndAttributes.scala | 3 -
.../annotation/props/TestPropertyRuntime.scala | 4 +-
.../illinois/ncsa/daffodil/util/TestUtils.scala | 24 +-
.../ncsa/daffodil/example/TestJavaAPI.java | 1589 +++++++++---------
.../illinois/ncsa/daffodil/oolag/OOLAG.scala | 57 +-
.../annotation/props/PropertyScoping.scala | 7 +-
.../illinois/ncsa/daffodil/xml/QNameBase.scala | 4 +-
.../illinois/ncsa/daffodil/xml/XMLUtils.scala | 21 +
.../ncsa/daffodil/oolag/TestOOLAG.scala | 2 +-
.../props/TestGeneratedProperties.scala | 4 +-
.../daffodil/dsom/CompiledExpression1.scala | 11 +-
.../ncsa/daffodil/example/TestScalaAPI.scala | 7 +-
.../ncsa/daffodil/tdml/TDMLRunner.scala | 7 +-
.../daffodil/section06/entities/Entities.tdml | 2 +-
.../section06/namespaces/namespaces.tdml | 7 +-
.../daffodil/section07/assertions/assert.tdml | 7 +-
.../external_variables/external_variables.tdml | 25 +
.../SequenceGroupDelimiters.tdml | 3 +-
.../dfdl_expressions/expressions2.tdml | 1 -
.../TestExternalVariablesDebug.scala | 57 +
.../TestExternalVariablesNew.scala | 1 -
.../sequence_groups/TestSequenceGroups3.scala | 2 +-
88 files changed, 2957 insertions(+), 2685 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/compiler/Compiler.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/compiler/Compiler.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/compiler/Compiler.scala
index 030f26c..708e6e3 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/compiler/Compiler.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/compiler/Compiler.scala
@@ -67,6 +67,7 @@ import edu.illinois.ncsa.daffodil.processors.parsers.NotParsableParser
import edu.illinois.ncsa.daffodil.processors.unparsers.NotUnparsableUnparser
import edu.illinois.ncsa.daffodil.schema.annotation.props.gen.ParseUnparsePolicy
import edu.illinois.ncsa.daffodil.dsom.SchemaComponent
+import edu.illinois.ncsa.daffodil.dsom.SchemaComponentImpl
import edu.illinois.ncsa.daffodil.api.DaffodilTunables
/**
@@ -85,8 +86,8 @@ object ForParser extends ParserOrUnparser
object ForUnparser extends ParserOrUnparser
object BothParserAndUnparser extends ParserOrUnparser
-class ProcessorFactory(val sset: SchemaSet)
- extends SchemaComponent(<pf/>, sset)
+final class ProcessorFactory(val sset: SchemaSet)
+ extends SchemaComponentImpl(<pf/>, sset)
with DFDL.ProcessorFactory
with HavingRootSpec {
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dpath/Expression.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dpath/Expression.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dpath/Expression.scala
index e5963fb..a1398b6 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dpath/Expression.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dpath/Expression.scala
@@ -32,7 +32,7 @@
package edu.illinois.ncsa.daffodil.dpath
-import edu.illinois.ncsa.daffodil.oolag.OOLAG.OOLAGHost
+import edu.illinois.ncsa.daffodil.oolag.OOLAG._
import edu.illinois.ncsa.daffodil.exceptions._
import edu.illinois.ncsa.daffodil.dsom._
import scala.xml.NamespaceBinding
@@ -54,7 +54,7 @@ import edu.illinois.ncsa.daffodil.util.Numbers
*
* This is the OOLAG pattern again.
*/
-abstract class Expression extends OOLAGHost
+abstract class Expression extends OOLAGHostImpl()
with ImplementsThrowsOrSavesSDE {
/**
@@ -294,8 +294,8 @@ case class ComparisonExpression(op: String, adds: List[Expression])
case ("=", _) => subsetError("Unsupported operation '%s'. Use 'eq' instead.", op)
case ("!=", _) => subsetError("Unsupported operation '%s'. Use 'ne' instead.", op)
- case("eq", HexBinary) => EQ_CompareByteArray
- case("ne", HexBinary) => NE_CompareByteArray
+ case ("eq", HexBinary) => EQ_CompareByteArray
+ case ("ne", HexBinary) => NE_CompareByteArray
case ("eq", _) => EQ_Compare
case ("ne", _) => NE_Compare
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/AnnotatedSchemaComponent.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/AnnotatedSchemaComponent.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/AnnotatedSchemaComponent.scala
index 8d25ca4..af3787c 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/AnnotatedSchemaComponent.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/AnnotatedSchemaComponent.scala
@@ -41,36 +41,128 @@ import edu.illinois.ncsa.daffodil.equality._
import edu.illinois.ncsa.daffodil.schema.annotation.props.PropertyLookupResult
import edu.illinois.ncsa.daffodil.schema.annotation.props.NotFound
import edu.illinois.ncsa.daffodil.schema.annotation.props.Found
+import edu.illinois.ncsa.daffodil.schema.annotation.props.FindPropertyMixin
+
+/**
+ * Only objects from which we generate processors (parsers/unparsers)
+ * can lookup property values.
+ *
+ * This avoids the possibility of a property being resolved incorrectly by
+ * not looking at the complete chain of schema components contributing to the
+ * property resolution.
+ *
+ * The only objects that should resolve properties are
+ * ElementRef, Root, LocalElementDecl, Sequence, Choice, SequenceRef, ChoiceRef
+ *
+ * These are all the "real" terms. Everything else is just contributing
+ * properties to the mix, but they are not points where properties are
+ * used to generate processors.
+ */
+trait ResolvesProperties
+ extends FindPropertyMixin { self: AnnotatedSchemaComponent =>
+
+ /** Returns Term corresponding to this object. */
+ def term: Term
+
+ private def findNonDefaultProperty(pname: String): PropertyLookupResult = {
+ val result = findDefaultOrNonDefaultProperty(pname, nonDefaultPropertySources)
+ result match {
+ case f: Found => f
+ case NotFound(nd, d, _) =>
+ Assert.invariant(d.isEmpty)
+ }
+ result
+ }
+
+ private def findDefaultProperty(pname: String): PropertyLookupResult = {
+ val result = findDefaultOrNonDefaultProperty(pname, defaultPropertySources)
+ val fixup = result match {
+ case Found(value, loc, pname, _) =>
+ // found as a default property.
+ // supply constructor's last arg is boolean indicating it's a default property
+ Found(value, loc, pname, true)
+ case NotFound(nd, d, pn) =>
+ Assert.invariant(d.isEmpty)
+ NotFound(Seq(), nd, pn) // we want the places we searched shown as default locations searched
+ }
+ fixup
+ }
+
+ /**
+ * Does lookup of property using DFDL scoping rules, checking first non-default
+ * properties, then default property locations.
+ */
+ override def findPropertyOption(pname: String): PropertyLookupResult = {
+ ExecutionMode.requireCompilerMode
+ // first try in regular properties
+ val regularResult = resolver.findNonDefaultProperty(pname)
+ regularResult match {
+ case f: Found => f
+ case NotFound(nonDefaultLocsTried1, defaultLocsTried1, _) => {
+ Assert.invariant(defaultLocsTried1.isEmpty)
+ val defaultResult = resolver.findDefaultProperty(pname)
+ defaultResult match {
+ case f: Found => f
+ case NotFound(nonDefaultLocsTried2, defaultLocsTried2, _) => {
+ Assert.invariant(nonDefaultLocsTried2.isEmpty)
+ // did not find it at all. Return a NotFound with all the places we
+ // looked non-default and default.
+ val nonDefaultPlaces = nonDefaultLocsTried1
+ val defaultPlaces = defaultLocsTried2
+ NotFound(nonDefaultPlaces, defaultPlaces, pname)
+ }
+ }
+ }
+ }
+ }
+}
+
+/** Convenience class for implemening AnnotatedSchemaComponent trait */
+abstract class AnnotatedSchemaComponentImpl( final override val xml: Node,
+ final override val parent: SchemaComponent)
+ extends AnnotatedSchemaComponent
/**
* Shared characteristics of any annotated schema component.
+ *
* Not all components can carry DFDL annotations.
*/
-
-abstract class AnnotatedSchemaComponent(xml: Node, sc: SchemaComponent)
- extends SchemaComponent(xml, sc)
- with AnnotatedMixin {
+trait AnnotatedSchemaComponent
+ extends SchemaComponent
+ with AnnotatedMixin
+ with OverlapCheckMixin {
requiredEvaluations(annotationObjs)
- requiredEvaluations(shortFormPropertiesCorrect)
requiredEvaluations(nonDefaultPropertySources)
requiredEvaluations(defaultPropertySources)
- def term: Term
-
- // /**
- // * only used for debugging
- // */
- // override lazy val properties: PropMap =
- // (nonDefaultPropertySources.flatMap { _.properties.toSeq } ++
- // defaultPropertySources.flatMap { _.properties.toSeq }).toMap
+ /** Returns the Term corresponding to this component. */
+ final lazy val term: Term = this match {
+ case gr: GroupRef => gr.asModelGroup
+ // case mg: ModelGroup => mg.parent match {
+ // case ggd: GlobalGroupDef => {
+ // // this is the model group that is the definition of
+ // // a global group, so our term is the group reference referring to this.
+ // ggd.groupRef.asModelGroup
+ // }
+ // case _ => mg
+ // }
+ case t: Term => t
+ case ged: GlobalElementDecl => ged.elementRef
+ case ty: SimpleTypeDefBase => ty.elementBase
+ case ty: ComplexTypeBase => ty.elementBase
+ case ggd: GlobalGroupDef => ggd.groupRef.asModelGroup
+ case sd: SchemaDocument =>
+ Assert.usageError("not to be called for schema documents")
+ }
- final lazy val shortFormPropertiesCorrect: Boolean = {
- // Check that any unprefixed properties are disjoint with ALL DFDL property names.
- // Warning otherwise
- // Insure that some prefix is bound to the dfdl namespace. Warn otherwise.
- // Warn if dfdl: is bound to something else than the DFDL namespace.
- shortFormAnnotationsAreValid
+ /** Returns the property resolver for this component. */
+ final lazy val resolver: ResolvesProperties = {
+ val res = this match {
+ case sd: SchemaDocument => sd
+ case _ => term
+ }
+ res
}
/**
@@ -84,26 +176,71 @@ abstract class AnnotatedSchemaComponent(xml: Node, sc: SchemaComponent)
* properties that we have to check against. (Might already be there...?)
*
*/
- def shortFormAnnotationsAreValid: Boolean = true
+ // TODO: Implement this - DFDL-598, DFDL-1512
+ // private def areShortFormAnnotationsValid: Boolean = true
- def nonDefaultPropertySources: Seq[ChainPropProvider]
+ /**
+ * For property combining only. E.g., doesn't refer from an element
+ * to its complex type because we don't combine properties with that
+ * in DFDL v1.0. (I consider that a language design bug in DFDL v1.0, but
+ * that is the way it's defined.)
+ */
+ final protected def refersToForPropertyCombining: Option[AnnotatedSchemaComponent] = optReferredToComponent
- def defaultPropertySources: Seq[ChainPropProvider]
+ protected def optReferredToComponent: Option[AnnotatedSchemaComponent] // override in ref objects
- lazy val nonDefaultFormatChain: ChainPropProvider = formatAnnotation.formatChain
- lazy val defaultFormatChain: ChainPropProvider = {
+ final protected lazy val nonDefaultPropertySources: Seq[ChainPropProvider] = LV('nonDefaultPropertySources) {
+ this match {
+ case sd: SchemaDocument => Nil
+ case _ => {
+ val refTo = refersToForPropertyCombining
+ val chainFromReferredTo = refTo.map { c =>
+ val ndps = c.nonDefaultPropertySources
+ ndps
+ }.toSeq.flatten
+ val myNDFC = nonDefaultFormatChain
+ val completeNonDefaultFormatChain =
+ myNDFC +: chainFromReferredTo
+ val seq = completeNonDefaultFormatChain.distinct
+ checkNonOverlap(seq)
+ seq
+ }
+ }
+ }.value
+
+ final protected lazy val defaultPropertySources: Seq[ChainPropProvider] = LV('defaultPropertySources) {
+ val refTo = refersToForPropertyCombining
+ val chainFromReferredTo = refTo.toSeq.map { _.defaultPropertySources }.distinct.flatten
+ val completeDefaultFormatChain =
+ defaultFormatChain +: chainFromReferredTo
+ val seq = completeDefaultFormatChain.distinct
+ seq
+ }.value
+
+ final protected lazy val nonDefaultFormatChain: ChainPropProvider = {
+ val fa = formatAnnotation
+ val fc = fa.formatChain
+ fc
+ }
+
+ final protected lazy val defaultFormatChain: ChainPropProvider = {
val res = schemaDocument.formatAnnotation.formatChain
res
}
- private def findDefaultOrNonDefaultProperty(
+ protected final def findDefaultOrNonDefaultProperty(
pname: String,
sources: Seq[ChainPropProvider]): PropertyLookupResult = {
- val seq = sources.map { _.chainFindProperty(pname) }
- val optFound = seq.collectFirst { case found: Found => found }
+ //
+ // Important - use of stream here insures we don't lookup
+ // properties down the chain once we have them here.
+ //
+ val str = sources.toStream.map { _.chainFindProperty(pname) }
+ val optFound = str.collectFirst { case found: Found => found }
val result = optFound match {
case Some(f: Found) => f
case None => {
+ val seq = str.toSeq
// merge all the NotFound stuff.
val nonDefaults = seq.flatMap {
case NotFound(nd, d, _) => nd
@@ -121,30 +258,6 @@ abstract class AnnotatedSchemaComponent(xml: Node, sc: SchemaComponent)
result
}
- private def findNonDefaultProperty(pname: String): PropertyLookupResult = {
- val result = findDefaultOrNonDefaultProperty(pname, nonDefaultPropertySources)
- result match {
- case f: Found => f
- case NotFound(nd, d, _) =>
- Assert.invariant(d.isEmpty)
- }
- result
- }
-
- private def findDefaultProperty(pname: String): PropertyLookupResult = {
- val result = findDefaultOrNonDefaultProperty(pname, defaultPropertySources)
- val fixup = result match {
- case Found(value, loc, pname, _) =>
- // found as a default property.
- // supply constructor's last arg is boolean indicating it's a default property
- Found(value, loc, pname, true)
- case NotFound(nd, d, pn) =>
- Assert.invariant(d.isEmpty)
- NotFound(Seq(), nd, pn) // we want the places we searched shown as default locations searched
- }
- fixup
- }
-
/**
* Use this when you want to know if a property is defined exactly on a
* component. This ignores any default properties or properties defined on
@@ -152,34 +265,10 @@ abstract class AnnotatedSchemaComponent(xml: Node, sc: SchemaComponent)
* defined on a global element decl rather than an element reference to that
* decl.
*/
- def findPropertyOptionThisComponentOnly(pname: String): PropertyLookupResult = {
+ final def findPropertyOptionThisComponentOnly(pname: String): PropertyLookupResult = {
val result = findDefaultOrNonDefaultProperty(pname, Seq(nonDefaultFormatChain))
result
}
-
- override def findPropertyOption(pname: String): PropertyLookupResult = {
- ExecutionMode.requireCompilerMode
- // first try in regular properties
- val regularResult = findNonDefaultProperty(pname)
- regularResult match {
- case f: Found => f
- case NotFound(nonDefaultLocsTried1, defaultLocsTried1, _) => {
- Assert.invariant(defaultLocsTried1.isEmpty)
- val defaultResult = findDefaultProperty(pname)
- defaultResult match {
- case f: Found => f
- case NotFound(nonDefaultLocsTried2, defaultLocsTried2, _) => {
- Assert.invariant(nonDefaultLocsTried2.isEmpty)
- // did not find it at all. Return a NotFound with all the places we
- // looked non-default and default.
- val nonDefaultPlaces = nonDefaultLocsTried1
- val defaultPlaces = defaultLocsTried2
- NotFound(nonDefaultPlaces, defaultPlaces, pname)
- }
- }
- }
- }
- }
}
/**
@@ -280,7 +369,7 @@ trait AnnotatedMixin
protected def emptyFormatFactory: DFDLFormatAnnotation
protected def isMyFormatAnnotation(a: DFDLAnnotation): Boolean
- lazy val formatAnnotation = LV('formatAnnotation) {
+ final lazy val formatAnnotation = LV('formatAnnotation) {
val format = annotationObjs.collect { case fa: DFDLFormatAnnotation if isMyFormatAnnotation(fa) => fa }
val res = format match {
case Seq() => emptyFormatFactory // does make things with the right namespace scopes attached!
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ChoiceGroup.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ChoiceGroup.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ChoiceGroup.scala
index 2085f57..ec774c7 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ChoiceGroup.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ChoiceGroup.scala
@@ -47,8 +47,11 @@ import edu.illinois.ncsa.daffodil.processors.ChoiceDispatchKeyEv
import edu.illinois.ncsa.daffodil.schema.annotation.props.gen.YesNo
import edu.illinois.ncsa.daffodil.api.WarnID
-
/**
+ *
+ * Captures concepts common to all choice definitions, which includes both
+ * local and global choice definitions, but not choice group references.
+ *
* Choices are a bit complicated.
*
* They can have initiators and terminators. This is most easily thought of as wrapping each choice
@@ -78,29 +81,46 @@ import edu.illinois.ncsa.daffodil.api.WarnID
*
*/
-final class Choice(xmlArg: Node, parent: SchemaComponent, position: Int)
- extends ModelGroup(xmlArg, parent, position)
- with Choice_AnnotationMixin
- with RawDelimitedRuntimeValuedPropertiesMixin // initiator and terminator (not separator)
- with ChoiceGrammarMixin {
-
- requiredEvaluations(branchesAreNonOptional)
- requiredEvaluations(branchesAreNotIVCElements)
- requiredEvaluations(modelGroupRuntimeData.preSerialization)
+trait ChoiceDefMixin
+ extends AnnotatedSchemaComponent
+ with GroupDefLike {
- protected final override lazy val myPeers = choicePeers
+ protected def isMyFormatAnnotation(a: DFDLAnnotation) = a.isInstanceOf[DFDLChoice]
- protected final override def annotationFactory(node: Node): Option[DFDLAnnotation] = {
+ protected override def annotationFactory(node: Node): Option[DFDLAnnotation] = {
node match {
case <dfdl:choice>{ contents @ _* }</dfdl:choice> => Some(new DFDLChoice(node, this))
case _ => annotationFactoryForDFDLStatement(node, this)
}
}
- protected final def emptyFormatFactory = new DFDLChoice(newDFDLAnnotationXML("choice"), this)
- protected final def isMyFormatAnnotation(a: DFDLAnnotation) = a.isInstanceOf[DFDLChoice]
+ protected def emptyFormatFactory: DFDLFormatAnnotation = new DFDLChoice(newDFDLAnnotationXML("choice"), this)
+
+ lazy val xmlChildren = xml match {
+ case <choice>{ c @ _* }</choice> => c
+ case <group>{ _* }</group> => {
+ val ch = this match {
+ case cgd: GlobalChoiceGroupDef => cgd.xml \ "choice"
+ }
+ val <choice>{ c @ _* }</choice> = ch(0)
+ c
+ }
+ }
+}
+
+abstract class ChoiceTermBase( final override val xml: Node,
+ final override val parent: SchemaComponent,
+ final override val position: Int)
+ extends ModelGroup
+ with Choice_AnnotationMixin
+ with RawDelimitedRuntimeValuedPropertiesMixin // initiator and terminator (not separator)
+ with ChoiceGrammarMixin {
+
+ requiredEvaluations(branchesAreNonOptional)
+ requiredEvaluations(branchesAreNotIVCElements)
+ requiredEvaluations(modelGroupRuntimeData.preSerialization)
- protected final override lazy val <choice>{ xmlChildren @ _* }</choice> = xml
+ protected final override lazy val myPeers = choicePeers
final lazy val hasStaticallyRequiredInstances = {
// true if the choice has syntactic features (initiator, terminator)
@@ -161,7 +181,7 @@ final class Choice(xmlArg: Node, parent: SchemaComponent, position: Int)
* they are still considered to be represented. (all sequence and choice groups are isRepresented == true).
*/
final def branchesAreNonOptional = LV('branchesAreNonOptional) {
- val branchesOk = groupMembersNoRefs map { branch =>
+ val branchesOk = groupMembers map { branch =>
if (branch.isOptional) {
schemaDefinitionErrorButContinue("Branch of choice %s must be non-optional.".format(branch.path))
false
@@ -171,7 +191,7 @@ final class Choice(xmlArg: Node, parent: SchemaComponent, position: Int)
}.value
final def branchesAreNotIVCElements = LV('branchesAreNotIVCElements) {
- val branchesOk = groupMembersNoRefs map { branch =>
+ val branchesOk = groupMembers map { branch =>
if (!branch.isRepresented) {
schemaDefinitionErrorButContinue("Branch of choice %s cannot have the dfdl:inputValueCalc property.".format(branch.path))
false
@@ -181,7 +201,7 @@ final class Choice(xmlArg: Node, parent: SchemaComponent, position: Int)
}.value
final def choiceBranchMap: Map[ChoiceBranchEvent, RuntimeData] = LV('choiceBranchMap) {
- val eventTuples = groupMembersNoRefs.flatMap {
+ val eventTuples = groupMembers.flatMap {
case e: ElementBase => Seq((ChoiceBranchStartEvent(e.namedQName), e))
case mg: ModelGroup => {
val idEvents = mg.identifyingEventsForChoiceBranch
@@ -199,7 +219,7 @@ final class Choice(xmlArg: Node, parent: SchemaComponent, position: Int)
if (event.isInstanceOf[ChoiceBranchStartEvent] && trds.exists {
// any element children in any of the trds?
// because if so, we have a true ambiguity here.
- case sg: Sequence => {
+ case sg: SequenceTermBase => {
val nonOVCEltChildren = sg.elementChildren.filterNot { _.isOutputValueCalc }
nonOVCEltChildren.length > 0
}
@@ -257,3 +277,12 @@ final class Choice(xmlArg: Node, parent: SchemaComponent, position: Int)
optIgnoreCase)
}
}
+
+final class Choice(xmlArg: Node, parent: SchemaComponent, position: Int)
+ extends ChoiceTermBase(xmlArg, parent, position)
+ with ChoiceDefMixin {
+
+ override lazy val optReferredToComponent = None
+
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ComplexTypes.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ComplexTypes.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ComplexTypes.scala
index 08a04e5..e69dd42 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ComplexTypes.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ComplexTypes.scala
@@ -37,9 +37,10 @@ import edu.illinois.ncsa.daffodil.grammar.ComplexTypeBaseGrammarMixin
import edu.illinois.ncsa.daffodil.dpath.NodeInfo
import edu.illinois.ncsa.daffodil.xml.QName
-abstract class ComplexTypeBase(xmlArg: Node, parent: SchemaComponent)
- extends SchemaComponent(xmlArg, parent)
+abstract class ComplexTypeBase(xmlArg: Node, parentArg: SchemaComponent)
+ extends SchemaComponentImpl(xmlArg, parentArg)
with TypeBase
+ with NonPrimTypeMixin
with ComplexTypeBaseGrammarMixin {
final override def optRestriction = None
@@ -48,11 +49,11 @@ abstract class ComplexTypeBase(xmlArg: Node, parent: SchemaComponent)
requiredEvaluations(modelGroup)
- def element: ElementBase
+ override def elementDecl: ElementDeclMixin
protected final lazy val <complexType>{ xmlChildren @ _* }</complexType> = xml
- final def group = modelGroup.group
+ final def group = modelGroup
/**
* Convenience methods for unit testing. Just makes tests a bit more compact and clearer.
@@ -62,7 +63,6 @@ abstract class ComplexTypeBase(xmlArg: Node, parent: SchemaComponent)
final lazy val Seq(modelGroup) = {
val s = smg
- // TODO: why check this? Schema validation will enforce this for us. (I think).
schemaDefinitionUnless(s.length == 1, "A complex type must have exactly one model-group element child which is a sequence, choice, or group reference.")
s
}
@@ -71,7 +71,7 @@ abstract class ComplexTypeBase(xmlArg: Node, parent: SchemaComponent)
xmlChildren.flatMap {
xmlChild =>
{
- val g = ModelGroupFactory(xmlChild, this, 1) // discards unwanted text nodes also.
+ val g = ModelGroupFactory(xmlChild, this, 1, false) // discards unwanted text nodes also.
g
}
}
@@ -101,7 +101,7 @@ final class GlobalComplexTypeDefFactory(xmlArg: Node, schemaDocumentArg: SchemaD
extends SchemaComponentFactory(xmlArg, schemaDocumentArg)
with GlobalNonElementComponentMixin {
- def forElement(element: ElementBase) = new GlobalComplexTypeDef(xml, schemaDocument, element)
+ def forElement(elementDecl: ElementDeclMixin) = new GlobalComplexTypeDef(xml, schemaDocument, elementDecl)
override lazy val namedQName = QName.createGlobal(name, targetNamespace, xml.scope)
}
@@ -109,17 +109,17 @@ final class GlobalComplexTypeDefFactory(xmlArg: Node, schemaDocumentArg: SchemaD
/**
* For unit testing purposes, the element argument might be supplied as null.
*/
-final class GlobalComplexTypeDef(xmlArg: Node, schemaDocumentArg: SchemaDocument, val element: ElementBase)
+final class GlobalComplexTypeDef(xmlArg: Node, schemaDocumentArg: SchemaDocument, override val elementDecl: ElementDeclMixin)
extends ComplexTypeBase(xmlArg, schemaDocumentArg)
with GlobalNonElementComponentMixin
with NestingTraversesToReferenceMixin {
- lazy val referringComponent = Option(element)
+ override lazy val referringComponent = Option(elementDecl)
}
-final class LocalComplexTypeDef(xmlArg: Node, val element: ElementBase)
- extends ComplexTypeBase(xmlArg, element)
+final class LocalComplexTypeDef(xmlArg: Node, override val elementDecl: ElementDeclMixin)
+ extends ComplexTypeBase(xmlArg, elementDecl)
with LocalNonElementComponentMixin
with NestingLexicalMixin {
// nothing
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLAnnotation.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLAnnotation.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLAnnotation.scala
index ebe9ccc..bc107bc 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLAnnotation.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLAnnotation.scala
@@ -35,6 +35,7 @@ package edu.illinois.ncsa.daffodil.dsom
import scala.xml.Node
import edu.illinois.ncsa.daffodil.util.Misc
import edu.illinois.ncsa.daffodil.schema.annotation.props.PropertyLookupResult
+import edu.illinois.ncsa.daffodil.schema.annotation.props.FindPropertyMixin
/**
* Base class for any DFDL annotation
@@ -56,30 +57,34 @@ import edu.illinois.ncsa.daffodil.schema.annotation.props.PropertyLookupResult
* bit more tightly to the OOLAG library there.
*/
abstract class DFDLAnnotation(xmlArg: Node, annotatedSCArg: AnnotatedSchemaComponent)
- extends SchemaComponent(xmlArg, annotatedSCArg)
- with NestingLexicalMixin {
+ extends SchemaComponent
+ with NestingLexicalMixin
+ with FindPropertyMixin // only needed because unit tests look at properties on annotations
+ {
+ final override val xml = xmlArg
+ final override def parent = annotatedSCArg
final override val context: AnnotatedSchemaComponent = annotatedSCArg
// delegate to the annotated component.
override def findPropertyOption(pname: String): PropertyLookupResult = {
- val res = annotatedSC.findPropertyOption(pname)
+ val res = annotatedSC.resolver.findPropertyOption(pname)
res
}
final lazy val annotatedSC = annotatedSCArg
- override def toString = path
+ override def toString = diagnosticDebugName
override lazy val diagnosticDebugName: String = {
val cn = Misc.getNameFromClass(this)
val n =
if (cn.startsWith("DFDL")) {
val nn = cn.replaceFirst("DFDL", "")
- Misc.initialLowerCase(nn)
+ "dfdl:" + Misc.initialLowerCase(nn)
} else {
cn
}
- n
+ n // + "(" + annotatedSC.path + ")"
}
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLAssertion.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLAssertion.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLAssertion.scala
index 85a3107..4348e90 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLAssertion.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLAssertion.scala
@@ -80,13 +80,16 @@ abstract class DFDLAssertionBase(node: Node, decl: AnnotatedSchemaComponent)
} catch { case e: PatternSyntaxException => SDE("The pattern contained invalid syntax: %s", e.getMessage()) }
val hasWord = thePattern.contains("\\w")
-
- if (decl.term.termRuntimeData.encodingInfo.knownEncodingIsUnicode && hasWord) {
- SDW("The encoding is '%s' and \\w was detected in the pattern '%s'. This is not recommended with Unicode encodings.",
- decl.term.termRuntimeData.encodingInfo.knownEncodingName, thePattern)
+ decl match {
+ case term: Term => {
+ val encInfo = term.termRuntimeData.encodingInfo
+ if (encInfo.knownEncodingIsUnicode && hasWord)
+ SDW("The encoding is '%s' and \\w was detected in the pattern '%s'. This is not recommended with Unicode encodings.",
+ encInfo.knownEncodingName, thePattern)
+ }
+ case _ => // ok
}
}
-
optPattern
}
@@ -131,8 +134,8 @@ final class DFDLAssert(node: Node, decl: AnnotatedSchemaComponent)
final def gram = LV('gram) {
testKind match {
- case TestKind.Pattern => AssertPatternPrim(decl, this)
- case TestKind.Expression => AssertBooleanPrim(decl, this)
+ case TestKind.Pattern => AssertPatternPrim(decl.term, this)
+ case TestKind.Expression => AssertBooleanPrim(decl.term, this)
}
}.value
}
@@ -142,8 +145,8 @@ final class DFDLDiscriminator(node: Node, decl: AnnotatedSchemaComponent)
final def gram = LV('gram) {
testKind match {
- case TestKind.Pattern => DiscriminatorPatternPrim(decl, this)
- case TestKind.Expression => DiscriminatorBooleanPrim(decl, this)
+ case TestKind.Pattern => DiscriminatorPatternPrim(decl.term, this)
+ case TestKind.Expression => DiscriminatorBooleanPrim(decl.term, this)
}
}.value
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLFormat.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLFormat.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLFormat.scala
index 332de7a..e7ab278 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLFormat.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLFormat.scala
@@ -47,19 +47,19 @@ final class DFDLFormat(node: Node, sd: SchemaDocument)
abstract class DFDLNonDefaultFormatAnnotation(node: Node, sc: AnnotatedSchemaComponent)
extends DFDLFormatAnnotation(node, sc)
-final class DFDLElement(node: Node, decl: ElementBase)
+final class DFDLElement(node: Node, decl: ElementLikeMixin)
extends DFDLNonDefaultFormatAnnotation(node, decl)
-final class DFDLGroup(node: Node, decl: GroupBase)
+final class DFDLGroup(node: Node, decl: ModelGroup)
extends DFDLNonDefaultFormatAnnotation(node, decl)
-abstract class DFDLModelGroup(node: Node, decl: ModelGroup)
+abstract class DFDLModelGroup(node: Node, decl: AnnotatedSchemaComponent)
extends DFDLNonDefaultFormatAnnotation(node, decl)
-final class DFDLSequence(node: Node, decl: Sequence)
+final class DFDLSequence(node: Node, decl: SequenceDefMixin)
extends DFDLModelGroup(node, decl)
-final class DFDLChoice(node: Node, decl: Choice)
+final class DFDLChoice(node: Node, decl: ChoiceDefMixin)
extends DFDLModelGroup(node, decl)
final class DFDLSimpleType(node: Node, decl: SimpleTypeDefBase)
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLFormatAnnotation.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLFormatAnnotation.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLFormatAnnotation.scala
index 3c66bbe..491040e 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLFormatAnnotation.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLFormatAnnotation.scala
@@ -249,7 +249,7 @@ abstract class DFDLFormatAnnotation(nodeArg: Node, annotatedSCArg: AnnotatedSche
* Needed for certain warnings, and also is the primitive from which the
* ChainPropProvider is built up. That one DOES follow ref chains.
*/
- final override def justThisOneProperties: PropMap = LV('justThisOneProperties) {
+ final lazy val justThisOneProperties: PropMap = LV('justThisOneProperties) {
val res = combinedJustThisOneProperties
log(LogLevel.Debug, "%s::%s justThisOneProperties are: %s", annotatedSC.diagnosticDebugName, diagnosticDebugName, res)
res
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLSchemaFile.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLSchemaFile.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLSchemaFile.scala
index b813aae..fe0c67d 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLSchemaFile.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLSchemaFile.scala
@@ -53,7 +53,7 @@ final class DFDLSchemaFile(val sset: SchemaSet,
schemaSourceArg: => DaffodilSchemaSource, // fileName, URL, or a scala.xml.Node
val iiParent: IIBase,
seenBeforeArg: IIMap)
- extends SchemaComponent(<file/>, sset)
+ extends SchemaComponentImpl(<file/>, sset)
with org.xml.sax.ErrorHandler {
requiredEvaluations(isValid)
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLStatementMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLStatementMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLStatementMixin.scala
index 0101457..b38fc45 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLStatementMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/DFDLStatementMixin.scala
@@ -38,93 +38,25 @@ import edu.illinois.ncsa.daffodil.exceptions.ThrowsSDE
import edu.illinois.ncsa.daffodil.schema.annotation.props.gen.TestKind
import edu.illinois.ncsa.daffodil.grammar.primitives.AssertBase
-/**
- * The other kind of DFDL annotations are DFDL 'statements'.
- * This trait is everything shared by schema components that can have
- * statements.
- *
- * Factory for creating the corresponding DFDLAnnotation objects.
- */
-trait DFDLStatementMixin extends ThrowsSDE { self: AnnotatedSchemaComponent =>
+trait ResolvesDFDLStatementMixin
+ extends ThrowsSDE
+ with ProvidesDFDLStatementMixin { self: Term =>
requiredEvaluations(statements)
- protected final def annotationFactoryForDFDLStatement(node: Node, self: AnnotatedSchemaComponent): Option[DFDLAnnotation] = {
- node match {
- case <dfdl:assert>{ content @ _* }</dfdl:assert> => Some(new DFDLAssert(node, self))
- case <dfdl:discriminator>{ content @ _* }</dfdl:discriminator> => Some(new DFDLDiscriminator(node, self))
- case <dfdl:setVariable>{ content @ _* }</dfdl:setVariable> => Some(new DFDLSetVariable(node, self))
- case <dfdl:newVariableInstance>{ content @ _* }</dfdl:newVariableInstance> => Some(new DFDLNewVariableInstance(node, self))
- //
- // property element annotations aren't "statements" so we don't want them back from this
- // and in fact can't construct them here without causing trouble (circular definitions)
- //
- case <dfdl:property>{ _* }</dfdl:property> =>
- SDE("A dfdl:property annotation element is not allowed without a surrounding dfdl:format, dfdl:element, etc. ")
- case _ => SDE("Invalid DFDL annotation found: %s", node)
- }
- }
-
- /**
- * Validation won't check whether these are validly in place on a DFDL schema, so
- * we allow any annotated object to have them, and then we can do checking on this list
- * to enforce rules about which kinds of statements are allowed and where.
- *
- * Implement these abstract methods to do the right thing w.r.t. combining
- * statements from group refs and their referenced groups, element refs and their elements,
- * element decls and their simple types, simpleTypes and their base simpleTypes.
- *
- * The local ingredients are here for doing the needed combining and also for checking.
- * E.g., dfdl:newVariableInstance isn't allowed on simpleType, can only have one discriminator per
- * annotation point, and per combined annotation point, discriminators and assertions exclude each other, etc.
- */
- def statements: Seq[DFDLStatement]
- def newVariableInstanceStatements: Seq[DFDLNewVariableInstance]
- final lazy val notNewVariableInstanceStatements = setVariableStatements ++ discriminatorStatements ++ assertStatements
- def assertStatements: Seq[DFDLAssert]
- def discriminatorStatements: Seq[DFDLDiscriminator]
- def setVariableStatements: Seq[DFDLSetVariable]
-
- final lazy val localStatements = this.annotationObjs.collect { case st: DFDLStatement => st }
- final lazy val localNewVariableInstanceStatements = localStatements.collect { case nve: DFDLNewVariableInstance => nve }
- final lazy val localNotNewVariableInstanceStatements = localStatements.diff(localNewVariableInstanceStatements)
- final lazy val (localDiscriminatorStatements,
- localAssertStatements) = {
- val discrims = localStatements.collect { case disc: DFDLDiscriminator => disc }
- val asserts = localStatements.collect { case asrt: DFDLAssert => asrt }
- checkDiscriminatorsAssertsDisjoint(discrims, asserts)
- }
-
- final def checkDiscriminatorsAssertsDisjoint(discrims: Seq[DFDLDiscriminator], asserts: Seq[DFDLAssert]): (Seq[DFDLDiscriminator], Seq[DFDLAssert]) = {
- schemaDefinitionUnless(discrims.size <= 1, "At most one discriminator allowed at same location: %s", discrims)
- schemaDefinitionUnless(asserts == Nil || discrims == Nil,
- "Cannot have both dfdl:discriminator annotations and dfdl:assert annotations at the same location.")
- (discrims, asserts)
- }
-
- final def checkDistinctVariableNames(svs: Seq[DFDLSetVariable]) = {
- val names = svs.map { _.defv.globalQName }
- val areAllDistinct = names.distinct.size == names.size
- schemaDefinitionUnless(areAllDistinct, "Variable names must all be distinct at the same location: %s", names)
- svs
- }
-
- final lazy val localSetVariableStatements = {
- val svs = localStatements.collect { case sv: DFDLSetVariable => sv }
- checkDistinctVariableNames(svs)
- }
+ final lazy val statements: Seq[DFDLStatement] =
+ optReferencedStatementSource.toSeq.flatMap { _.resolvedStatements } ++
+ localStatements
private def getParserExprReferencedElements(s: DFDLStatement,
f: ContentValueReferencedElementInfoMixin => Set[DPathElementCompileInfo]) = {
s match {
-
case a: DFDLAssertionBase if (a.testKind eq TestKind.Expression) => {
a.gram match {
case ab: AssertBase => f(ab.expr)
case _ => ReferencedElementInfos.None
}
}
-
case _ => getUnparserExprReferencedElements(s, f)
}
}
@@ -147,13 +79,13 @@ trait DFDLStatementMixin extends ThrowsSDE { self: AnnotatedSchemaComponent =>
}
}
- private def creis(rei: ContentValueReferencedElementInfoMixin) = rei.contentReferencedElementInfos
- private def vreis(rei: ContentValueReferencedElementInfoMixin) = rei.valueReferencedElementInfos
+ final protected def creis(rei: ContentValueReferencedElementInfoMixin) = rei.contentReferencedElementInfos
- private def statementReferencedElementInfos(f: DFDLStatement => Set[DPathElementCompileInfo]) = {
+ final protected def vreis(rei: ContentValueReferencedElementInfoMixin) = rei.valueReferencedElementInfos
+ private def statementReferencedElementInfos(f: DFDLStatement => Set[DPathElementCompileInfo]) = {
val stmtSets: Seq[DPathElementCompileInfo] = {
- val s = statements
+ val s = resolvedStatements
val sets = s.flatMap(f)
sets
}
@@ -172,3 +104,106 @@ trait DFDLStatementMixin extends ThrowsSDE { self: AnnotatedSchemaComponent =>
final protected lazy val statementValueUnparserReferencedElementInfos =
statementReferencedElementInfos(x => getUnparserExprReferencedElements(x, vreis(_)))
}
+
+/**
+ * The other kind of DFDL annotations are DFDL 'statements'.
+ * This trait is everything shared by schema components that can carry
+ * statements.
+ *
+ * Factory for creating the corresponding DFDLAnnotation objects.
+ */
+trait ProvidesDFDLStatementMixin extends ThrowsSDE { self: AnnotatedSchemaComponent =>
+
+ final def annotationFactoryForDFDLStatement(node: Node, self: AnnotatedSchemaComponent): Option[DFDLAnnotation] = {
+ val term = self.term
+ node match {
+ case <dfdl:assert>{ content @ _* }</dfdl:assert> => Some(new DFDLAssert(node, term))
+ case <dfdl:discriminator>{ content @ _* }</dfdl:discriminator> => Some(new DFDLDiscriminator(node, term))
+ case <dfdl:setVariable>{ content @ _* }</dfdl:setVariable> => Some(new DFDLSetVariable(node, term))
+ case <dfdl:newVariableInstance>{ content @ _* }</dfdl:newVariableInstance> => Some(new DFDLNewVariableInstance(node, term))
+ //
+ // property element annotations aren't "statements" so we don't want them back from this
+ // and in fact can't construct them here without causing trouble (circular definitions)
+ //
+ case <dfdl:property>{ _* }</dfdl:property> =>
+ SDE("A dfdl:property annotation element is not allowed without a surrounding dfdl:format, dfdl:element, etc. ")
+ case _ => SDE("Invalid DFDL annotation found: %s", node)
+ }
+ }
+
+ /**
+ * Validation won't check whether these are validly in place on a DFDL schema, so
+ * we allow any annotated object to have them, and then we can do checking on this list
+ * to enforce rules about which kinds of statements are allowed and where.
+ *
+ * Implement these abstract methods to do the right thing w.r.t. combining
+ * statements from group refs and their referenced groups, element refs and their elements,
+ * element decls and their simple types, simpleTypes and their base simpleTypes.
+ *
+ * The local ingredients are here for doing the needed combining and also for checking.
+ * E.g., dfdl:newVariableInstance isn't allowed on simpleType, can only have one discriminator per
+ * annotation point, and per combined annotation point, discriminators and assertions exclude each other, etc.
+ */
+
+ /**
+ * Combine our statements with those of what we reference.
+ * Elements reference types
+ * ElementRefs reference elements, etc.
+ *
+ * The order here is important. The statements from type come first, then from declaration, then from
+ * reference.
+ */
+
+ final def optReferencedStatementSource: Option[ProvidesDFDLStatementMixin] =
+ self.optReferredToComponent.asInstanceOf[Option[ProvidesDFDLStatementMixin]]
+
+ final lazy val resolvedStatements: Seq[DFDLStatement] =
+ optReferencedStatementSource.toSeq.flatMap { _.resolvedStatements } ++ localStatements
+
+ final lazy val newVariableInstanceStatements: Seq[DFDLNewVariableInstance] =
+ optReferencedStatementSource.toSeq.flatMap { _.newVariableInstanceStatements } ++
+ localNewVariableInstanceStatements
+
+ final lazy val (discriminatorStatements, assertStatements) =
+ checkDiscriminatorsAssertsDisjoint(combinedDiscrims, combinedAsserts)
+
+ private lazy val combinedAsserts: Seq[DFDLAssert] =
+ optReferencedStatementSource.toSeq.flatMap { _.assertStatements } ++ localAssertStatements
+
+ private lazy val combinedDiscrims: Seq[DFDLDiscriminator] =
+ optReferencedStatementSource.toSeq.flatMap { _.discriminatorStatements } ++ localDiscriminatorStatements
+
+ final lazy val setVariableStatements: Seq[DFDLSetVariable] = {
+ val combinedSvs = optReferencedStatementSource.toSeq.flatMap { _.setVariableStatements } ++ localSetVariableStatements
+ checkDistinctVariableNames(combinedSvs)
+ }
+
+ final protected lazy val localStatements = this.annotationObjs.collect { case st: DFDLStatement => st }
+
+ private lazy val localNewVariableInstanceStatements = localStatements.collect { case nve: DFDLNewVariableInstance => nve }
+
+ final protected lazy val (localDiscriminatorStatements, localAssertStatements) = {
+ val discrims = localStatements.collect { case disc: DFDLDiscriminator => disc }
+ val asserts = localStatements.collect { case asrt: DFDLAssert => asrt }
+ checkDiscriminatorsAssertsDisjoint(discrims, asserts)
+ }
+
+ private def checkDiscriminatorsAssertsDisjoint(discrims: Seq[DFDLDiscriminator], asserts: Seq[DFDLAssert]): (Seq[DFDLDiscriminator], Seq[DFDLAssert]) = {
+ schemaDefinitionUnless(discrims.size <= 1, "At most one discriminator allowed at same location: %s", discrims)
+ schemaDefinitionUnless(asserts == Nil || discrims == Nil,
+ "Cannot have both dfdl:discriminator annotations and dfdl:assert annotations at the same location.")
+ (discrims, asserts)
+ }
+
+ private def checkDistinctVariableNames(svs: Seq[DFDLSetVariable]) = {
+ val names = svs.map { _.defv.globalQName }
+ val areAllDistinct = names.distinct.size == names.size
+ schemaDefinitionUnless(areAllDistinct, "Variable names must all be distinct at the same location: %s", names)
+ svs
+ }
+
+ final protected lazy val localSetVariableStatements = {
+ val svs = localStatements.collect { case sv: DFDLSetVariable => sv }
+ checkDistinctVariableNames(svs)
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementBase.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementBase.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementBase.scala
index 9164d2f..a55dbbc 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementBase.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementBase.scala
@@ -32,7 +32,6 @@
package edu.illinois.ncsa.daffodil.dsom
-import scala.xml.Node
import scala.xml.NamespaceBinding
import edu.illinois.ncsa.daffodil.exceptions.Assert
import edu.illinois.ncsa.daffodil.grammar._
@@ -47,8 +46,6 @@ import edu.illinois.ncsa.daffodil.grammar.ElementBaseGrammarMixin
import edu.illinois.ncsa.daffodil.equality._
import edu.illinois.ncsa.daffodil.processors.UseNilForDefault
-import edu.illinois.ncsa.daffodil.util.Maybe
-import edu.illinois.ncsa.daffodil.util.Maybe._
import edu.illinois.ncsa.daffodil.util.MaybeULong
import java.lang.{ Integer => JInt }
import edu.illinois.ncsa.daffodil.processors._
@@ -77,11 +74,12 @@ object ElementBase {
/**
* Shared by all forms of elements, local or global or element reference.
*/
-abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
- extends Term(xmlArg, parent, position)
+trait ElementBase
+ extends Term
+ with ElementLikeMixin
+ with LocalElementMixin
with Element_AnnotationMixin
with NillableMixin
- with DFDLStatementMixin
with ElementBaseGrammarMixin
with ElementRuntimeValuedPropertiesMixin
with StringTextMixin
@@ -89,7 +87,7 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
with CalendarTextMixin
with BooleanTextMixin
with TextNumberFormatMixin
- with RealTermMixin {
+ with OverlapCheckMixin {
override final def eBase = this
@@ -108,22 +106,29 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
requiredEvaluations(if (hasTotalDigits) totalDigits)
requiredEvaluations(if (hasFractionDigits) fractionDigits)
requiredEvaluations(erd.preSerialization)
+ requiredEvaluations(checkForAlignmentAmbiguity)
def name: String
- def inputValueCalcOption: PropertyLookupResult
- def outputValueCalcOption: PropertyLookupResult
+ final lazy val inputValueCalcOption = findPropertyOption("inputValueCalc")
+
+ final lazy val outputValueCalcOption = {
+ val optOVC = findPropertyOption("outputValueCalc")
+ schemaDefinitionWhen(optOVC.isDefined && isOptional, "dfdl:outputValueCalc cannot be defined on optional elements.")
+ schemaDefinitionWhen(optOVC.isDefined && isArray, "dfdl:outputValueCalc cannot be defined on array elements.")
+ // This should be an SDE, but is very useful for unit tests to be able to specify OVC on a single global element
+ // self.schemaDefinitionWhen(optOVC.isDefined && self.isInstanceOf[GlobalElementDecl], "dfdl:outputValueCalc cannot be defined on global elements.")
+
+ optOVC
+ }
+
def isNillable: Boolean
def isSimpleType: Boolean
def isComplexType: Boolean
- final def simpleType = typeDef match {
- case st: SimpleTypeBase => st
- case ct: ComplexTypeBase =>
- Assert.invariantFailed("Must be simple type: " + ct.element.namedQName)
- }
+ def simpleType: SimpleTypeBase
- final def complexType = typeDef.asInstanceOf[ComplexTypeBase]
+ def complexType: ComplexTypeBase
/**
* Irrespective of whether the type of this element is immediate or
@@ -132,9 +137,6 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
*/
def typeDef: TypeBase
- override def isRequired = true // overridden in particle mixin.
- override def isArray = false // overridden in local elements
-
/**
* The DPathElementInfo objects referenced within an IVC
* that calls dfdl:contentLength( thingy )
@@ -182,21 +184,24 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
* at parse runtime, or we can ignore that.
*/
final lazy val isReferencedByContentLengthParserExpressions: Boolean =
- rootElement.get.contentLengthParserReferencedElementInfos.contains(this.dpathElementCompileInfo)
+ // TODO: should be for all root elements that are compiled in this
+ // schema compilation, such time as we allow more than one root element.
+ // Applies to all code that references the rootElementRef in this trait.
+ rootElementRef.get.contentLengthParserReferencedElementInfos.contains(this.dpathElementCompileInfo)
/**
* Tells us if, for this element, we need to capture its content length
* at unparse runtime, or we can ignore that.
*/
final lazy val isReferencedByContentLengthUnparserExpressions: Boolean =
- rootElement.get.contentLengthUnparserReferencedElementInfos.contains(this.dpathElementCompileInfo)
+ rootElementRef.get.contentLengthUnparserReferencedElementInfos.contains(this.dpathElementCompileInfo)
/**
* Tells us if, for this element, we need to capture its value length
* at parse runtime, or we can ignore that.
*/
final lazy val isReferencedByValueLengthParserExpressions: Boolean = {
- val setElems = rootElement.get.valueLengthParserReferencedElementInfos
+ val setElems = rootElementRef.get.valueLengthParserReferencedElementInfos
// if (this eq rootElement.get)
// println("PARSER these are referenced by valueCalc: " + setElems.toString)
val res = setElems.contains(this.dpathElementCompileInfo)
@@ -207,7 +212,7 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
* at unparse runtime, or we can ignore that.
*/
final lazy val isReferencedByValueLengthUnparserExpressions: Boolean = {
- val setElems = rootElement.get.valueLengthUnparserReferencedElementInfos
+ val setElems = rootElementRef.get.valueLengthUnparserReferencedElementInfos
// if (this eq rootElement.get)
// println("UNPARSER these are referenced by valueCalc: " + setElems.toString)
val isInExprs = setElems.contains(this.dpathElementCompileInfo)
@@ -248,18 +253,21 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
*/
def isRequiredArrayElement: Boolean
- // override in Particle
- lazy val optMinOccurs: Option[Int] = None
- lazy val optMaxOccurs: Option[Int] = None
-
- def elementRef: Option[ElementRef]
-
final override lazy val dpathCompileInfo = dpathElementCompileInfo
+ /**
+ * This is the compile info for this element. Since this might be an
+ * element ref, we optionally carry the compile info for the referenced
+ * element in that case.
+ */
lazy val dpathElementCompileInfo: DPathElementCompileInfo = {
+ val ee = enclosingElement
val eci = new DPathElementCompileInfo(
- enclosingElement.map { _.dpathElementCompileInfo },
+ ee.map {
+ _.dpathElementCompileInfo
+ },
variableMap,
+ elementChildrenCompileInfo,
namespaces,
slashPath,
name,
@@ -267,7 +275,6 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
namedQName,
optPrimType,
schemaFileLocation,
- elementChildrenCompileInfo,
tunable)
eci
}
@@ -284,18 +291,6 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
}
}
- // private lazy val containsNoNamespaceElement: Boolean = {
- // thisElementsNamespace.isNoNamespace ||
- // elementChildren.exists { _.containsNoNamespaceElement }
- // }
- //
- // private def bindingsHaveDefaultNamespaceBinding(pairs: Set[(String, NS)]) = {
- // val map = pairs.toMap
- // val optDefaultNS = map.get(null)
- // val res = optDefaultNS.isDefined
- // res
- // }
-
private lazy val thisElementsRequiredNamespaceBindings: Set[(String, NS)] = {
val childrenRequiredNSBindings =
this.elementChildren.flatMap { _.thisElementsRequiredNamespaceBindings }.toSet
@@ -386,13 +381,19 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
*/
private lazy val minimizedScope: NamespaceBinding = {
val uniquePairs =
- if (enclosingComponent.isEmpty) {
+ if (this.isInstanceOf[Root]) {
// If this is the root element and it contains xmlns="", then remove
// it. xmlns="" is implied at the root. Note that we only do this for
// the root because if a child has xmlns="", that implies the parent
// had set the default namespace to something else, so we need to keep
// the child xmlns="" to override that.
- myUniquePairs.filterNot { case (prefix, ns) => prefix == null && ns.isNoNamespace }
+ myUniquePairs.filterNot {
+ case (prefix, ns) =>
+ val res =
+ prefix == null &&
+ ns.isNoNamespace
+ res
+ }
} else {
myUniquePairs
}
@@ -484,7 +485,13 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
final lazy val childElementResolver: NextElementResolver =
computeNextElementResolver(possibleFirstChildElementsInInfoset, ChildResolver)
- lazy val elementRuntimeData: ElementRuntimeData = LV('elementRuntimeData) {
+ final def erd = elementRuntimeData // just an abbreviation
+
+ final lazy val elementRuntimeData: ElementRuntimeData = LV('elementRuntimeData) {
+ computeElementRuntimeData
+ }.value
+
+ protected def computeElementRuntimeData(): ElementRuntimeData = {
val ee = enclosingElement
//
// Must be lazy below, because we are defining the elementRuntimeData in terms of
@@ -492,26 +499,14 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
// constructed lazily so that we first connect up all the erds to their children,
// and only subsequently ask for these parents to be elaborated.
//
- lazy val optERD = ee.map { enc =>
+ lazy val parent = ee.map { enc =>
Assert.invariant(this != enc)
enc.elementRuntimeData
}
- lazy val maybeTRD = this.enclosingTerm.map { enc =>
+ lazy val parentTerm = this.enclosingTerm.map { enc =>
Assert.invariant(this != enc)
enc.termRuntimeData
}
- createElementRuntimeData(optERD, maybeTRD)
- }.value
-
- def erd = elementRuntimeData // just an abbreviation
-
- /**
- * Everything needed at runtime about the element
- * in order to compile expressions using it, (for debug)
- * and issue proper diagnostics in error situations.
- */
- private def createElementRuntimeData(parent: => Option[ElementRuntimeData],
- parentTerm: => Maybe[TermRuntimeData]): ElementRuntimeData = {
//
// I got sick of initialization time problems, so this mutual recursion
@@ -590,13 +585,16 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
final lazy val elementChildren: Seq[ElementBase] = {
this.typeDef match {
case ct: ComplexTypeBase => {
- ct.group.elementChildren.asInstanceOf[Seq[ElementBase]]
+ ct.group.elementChildren
}
case _ => Nil
}
}
- final lazy val elementChildrenCompileInfo = elementChildren.map { _.dpathElementCompileInfo }
+ final lazy val elementChildrenCompileInfo =
+ elementChildren.map {
+ _.dpathElementCompileInfo
+ }
final override lazy val isRepresented = {
val isRep = inputValueCalcOption.isInstanceOf[NotFound]
@@ -639,22 +637,11 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
final lazy val isParentUnorderedSequence: Boolean = {
parent match {
- case s: Sequence if !s.isOrdered => true
+ case s: SequenceTermBase if !s.isOrdered => true
case _ => false
}
}
- protected final def annotationFactory(node: Node): Option[DFDLAnnotation] = {
- node match {
- case <dfdl:element>{ contents @ _* }</dfdl:element> => Some(new DFDLElement(node, this))
- case _ => annotationFactoryForDFDLStatement(node, this)
- }
- }
-
- protected final def emptyFormatFactory = new DFDLElement(newDFDLAnnotationXML("element"), this)
-
- protected final def isMyFormatAnnotation(a: DFDLAnnotation) = a.isInstanceOf[DFDLElement]
-
private def getImplicitAlignmentInBits(thePrimType: PrimType, theRepresentation: Representation): Int = {
theRepresentation match {
case Representation.Text =>
@@ -685,7 +672,7 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
final lazy val alignmentValueInBits: JInt = {
alignment match {
case AlignmentType.Implicit => {
- if (this.isComplexType) this.complexType.modelGroup.group.alignmentValueInBits
+ if (this.isComplexType) this.complexType.modelGroup.alignmentValueInBits
else implicitAlignmentInBits
}
case align: JInt => {
@@ -1072,58 +1059,63 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
/**
* Does the element have a default value?
*/
- def isDefaultable: Boolean
def defaultValueAsString: String
+ def hasDefaultValue: Boolean
/**
- * Combine our statements with those of the ref that is referencing us (if there is one), and
- * those of our simpleType (if we're a simple type element)
+ * We require that there be a concept of empty if we're going to be able to default something
+ * and we are going to require that we can tell this statically. I.e., we're not going to defer this to runtime
+ * just in case the delimiters are being determined at runtime.
*
- * The order here is important. The statements from type come first, then from declaration, then from
- * reference.
+ * That is to say, if a delimiter is an expression, then we're assuming that means
+ * at runtime it will not evaluate to empty string (so you can specify the delimiter
+ * at runtime, but you cannot turn on/off the whole delimited format at runtime.)
*/
- lazy val statements: Seq[DFDLStatement] =
- stForStatements.map { _.statements }.getOrElse(Nil) ++
- localStatements ++
- elementRef.map { _.statements }.getOrElse(Nil)
-
- lazy val newVariableInstanceStatements: Seq[DFDLNewVariableInstance] =
- stForStatements.map { _.newVariableInstanceStatements }.getOrElse(Nil) ++
- localNewVariableInstanceStatements ++
- elementRef.map { _.newVariableInstanceStatements }.getOrElse(Nil)
-
- lazy val (discriminatorStatements, assertStatements) =
- checkDiscriminatorsAssertsDisjoint(combinedDiscrims, combinedAsserts)
-
- private lazy val combinedAsserts: Seq[DFDLAssert] =
- stForStatements.map { _.assertStatements }.getOrElse(Nil) ++
- localAssertStatements ++
- elementRef.map { _.assertStatements }.getOrElse(Nil)
-
- private lazy val combinedDiscrims: Seq[DFDLDiscriminator] =
- stForStatements.map { _.discriminatorStatements }.getOrElse(Nil) ++
- localDiscriminatorStatements ++
- elementRef.map { _.discriminatorStatements }.getOrElse(Nil)
-
- lazy val setVariableStatements: Seq[DFDLSetVariable] = {
- val combinedSvs =
- stForStatements.map { _.setVariableStatements }.getOrElse(Nil) ++
- localSetVariableStatements ++
- elementRef.map { _.setVariableStatements }.getOrElse(Nil)
- checkDistinctVariableNames(combinedSvs)
- }
-
- private lazy val stForStatements = typeDef match {
- case st: SimpleTypeDefBase => Some(st)
- case _ => None
- }
+ final lazy val isDefaultable: Boolean = LV('isDefaultable) {
+ if (isSimpleType) {
+ if (!isRepresented) false
+ else if (!hasDefaultValue) false
+ else {
+ if (!emptyIsAnObservableConcept)
+ SDW("Element has no empty representation so cannot have XSD default='%s' as a default value.", defaultValueAsString)
+ schemaDefinitionWhen(isOptional, "Optional elements cannot have default values but default='%s' was found.", defaultValueAsString)
+ if (isArray && !isRequiredArrayElement) {
+ (optMinOccurs, occursCountKind) match {
+ case (_, OccursCountKind.Parsed) |
+ (_, OccursCountKind.StopValue) =>
+ SDE("XSD default='%s' can never be used since an element with dfdl:occursCountKind='%s' has no required occurrences.",
+ defaultValueAsString, occursCountKind)
+ case (Some(0), _) => SDE("XSD default='%s' can never be used since an element with XSD minOccurs='0' has no required occurrences.",
+ defaultValueAsString)
+ case _ => // ok
+ }
+ }
+ Assert.invariant(hasDefaultValue)
+ !isOptional &&
+ (isScalar ||
+ isRequiredArrayElement)
+ }
+ } else {
+ // TODO: Implement complex element defaulting
+ // JIRA issue DFDL-1277
+ //
+ // a complex element is defaultable
+ // recursively if everything in it is defaultable
+ // and everything in it has no required representation
+ // (e.g., no required delimiters, no alignment, no skip, etc.)
+ // furthermore, even the defaultable things inside must satisfy
+ // a stricter criterion. They must have emptyValueDelimiterPolicy='none'
+ // if delimiters are defined and they could be empty (which is implied if they are defaultable)
+ false
+ }
+ }.value
protected final def possibleFirstChildTerms: Seq[Term] = termChildren
protected final def couldBeLastElementInModelGroup: Boolean = LV('couldBeLastElementInModelGroup) {
val couldBeLast = enclosingTerm match {
case None => true
- case Some(s: Sequence) if s.isOrdered => {
+ case Some(s: SequenceTermBase) if s.isOrdered => {
!possibleNextSiblingTerms.exists {
case e: ElementBase => !e.isOptional || e.isRequiredArrayElement
case mg: ModelGroup => mg.mustHaveRequiredElement
@@ -1136,13 +1128,13 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
final lazy val nextParentElements: Seq[ElementBase] = {
if (enclosingTerm.isDefined && couldBeLastElementInModelGroup) {
- enclosingTerm.get.asInstanceOf[ModelGroup].possibleNextChildElementsInInfoset
+ enclosingTerm.get.possibleNextChildElementsInInfoset
} else {
Nil
}
}
- protected final lazy val defaultParseUnparsePolicy = optionParseUnparsePolicy.getOrElse(ParseUnparsePolicy.Both)
+ final lazy val defaultParseUnparsePolicy = optionParseUnparsePolicy.getOrElse(ParseUnparsePolicy.Both)
// This function ensures that all children have a compatable
// parseUnparsePolicy with the root. In other words, if the root policy is
@@ -1170,4 +1162,35 @@ abstract class ElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
}
}
+ private def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
+
+ /**
+ * Changed to a warning - DFDL WG decided to make this check optional, but it
+ * is still useful as a warning.
+ *
+ * Turns out that MIL STD 2045 header format needs to pad out to a byte boundary
+ * at the end of the structure. An optional, non-byte aligned field precedes
+ * the end of the structure; hence, putting a zero-length byte-aligned field
+ * at the end was crashing into this error. I couldn't think of a work-around,
+ * so changed this into a warning.
+ *
+ * The old requirement was:
+ * To avoid ambiguity when parsing, optional elements and variable-occurrence arrays
+ * where the minimum number of occurrences is zero cannot have alignment properties
+ * different from the items that follow them. It is a schema definition error otherwise.
+ *
+ * Part of the required evaluations for ElementBase.
+ */
+ private def checkForAlignmentAmbiguity: Unit = {
+ if (isOptional) {
+ this.possibleNextTerms.filterNot(m => m == this).foreach { that =>
+ val isSame = this.alignmentValueInBits == that.alignmentValueInBits
+ if (!isSame) {
+ this.SDW("%s is an optional element or a variable-occurrence array and its alignment (%s) is not the same as %s's alignment (%s).",
+ this.toString, this.alignmentValueInBits, that.toString, that.alignmentValueInBits)
+ }
+ }
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementDeclMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementDeclMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementDeclMixin.scala
index 11ed327..5824d6b 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementDeclMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementDeclMixin.scala
@@ -33,64 +33,54 @@
package edu.illinois.ncsa.daffodil.dsom
import edu.illinois.ncsa.daffodil.exceptions.Assert
-import edu.illinois.ncsa.daffodil.schema.annotation.props.gen._
import edu.illinois.ncsa.daffodil.xml._
import edu.illinois.ncsa.daffodil.dpath.NodeInfo.PrimType
import edu.illinois.ncsa.daffodil.equality._
+import scala.xml.Node
+trait ElementLikeMixin
+ extends AnnotatedSchemaComponent
+ with ProvidesDFDLStatementMixin {
+
+ private lazy val elementBase = this match {
+ case ged: GlobalElementDecl => ged.elementRef
+ case eb: ElementBase => eb
+ }
+
+ protected final def annotationFactory(node: Node): Option[DFDLAnnotation] = {
+ node match {
+ case <dfdl:element>{ contents @ _* }</dfdl:element> => Some(new DFDLElement(node, this))
+ case _ => elementBase.annotationFactoryForDFDLStatement(node, this)
+ }
+ }
+
+ protected final lazy val emptyFormatFactory = new DFDLElement(newDFDLAnnotationXML("element"), this)
+
+ protected final def isMyFormatAnnotation(a: DFDLAnnotation) = a.isInstanceOf[DFDLElement]
+}
/**
* Shared by all element declarations local or global
*/
trait ElementDeclMixin
- extends OverlapCheckMixin { self: ElementBase =>
-
- private def eRefNonDefault: Option[ChainPropProvider] = LV('eRefNonDefault) {
- elementRef.map {
- _.nonDefaultFormatChain
- }
- }.value
+ extends ElementLikeMixin {
- private def eRefDefault: Option[ChainPropProvider] = LV('eRefDefault) {
- elementRef.map {
- _.defaultFormatChain
- }
- }.value
+ def namedQName: NamedQName
- private lazy val sTypeNonDefault: Seq[ChainPropProvider] = self.typeDef match {
- case st: SimpleTypeDefBase => st.nonDefaultPropertySources
- case _ => Seq()
- }
- private lazy val sTypeDefault: Seq[ChainPropProvider] = self.typeDef match {
- case st: SimpleTypeDefBase => st.defaultPropertySources
- case _ => Seq()
+ final override protected def optReferredToComponent = typeDef match {
+ case std: SimpleTypeDefBase => Some(std)
+ case ctd: ComplexTypeBase => None // in DFDL v1.0 complex types are not annotated, so can't carry properties nor statements.
+ case _ => None
}
- /**
- * This and the partner defaultPropertySources are what ElementBase reaches back to get from
- * the ElementRef in order to have the complete picture of all the properties in effect for
- * that ElementBase.
- */
- final def nonDefaultPropertySources = LV('nonDefaultPropertySources) {
- val seq = (eRefNonDefault.toSeq ++ Seq(this.nonDefaultFormatChain) ++ sTypeNonDefault).distinct
- checkNonOverlap(seq)
- seq
- }.value
-
- final def defaultPropertySources = LV('defaultPropertySources) {
- val seq = (eRefDefault.toSeq ++ Seq(this.defaultFormatChain) ++ sTypeDefault).distinct
- seq
- }.value
-
final def immediateType: Option[TypeBase] = LV('immediateType) {
val st = xml \ "simpleType"
val ct = xml \ "complexType"
val nt = typeName
if (st.length == 1) {
- val factory = schemaSet.LocalSimpleTypeDefFactory(st(0), schemaDocument)
- val lstd = factory.forElement(self)
+ val lstd = new LocalSimpleTypeDef(st(0), this)
Some(lstd)
} else if (ct.length == 1)
- Some(new LocalComplexTypeDef(ct(0), self))
+ Some(new LocalComplexTypeDef(ct(0), this))
else {
Assert.invariant(nt != "")
None
@@ -164,6 +154,12 @@ trait ElementDeclMixin
dv
}
+ // shorthand
+ final lazy val primType = {
+ val res = typeDef.asInstanceOf[SimpleTypeBase].primType
+ res
+ }
+
final lazy val hasDefaultValue: Boolean = {
Assert.usage(isSimpleType)
defaultAttr.isDefined
@@ -171,69 +167,17 @@ trait ElementDeclMixin
final lazy val isNillable = (xml \ "@nillable").text == "true"
+ final def simpleType = typeDef match {
+ case st: SimpleTypeBase => st
+ case ct: ComplexTypeBase =>
+ Assert.invariantFailed("Must be simple type: " + namedQName)
+ }
+
+ final def complexType = typeDef.asInstanceOf[ComplexTypeBase]
/**
* Convenience methods for unit testing purposes.
*/
final def sequence = complexType.sequence
final def choice = complexType.choice
- /**
- * We require that there be a concept of empty if we're going to be able to default something
- * and we are going to require that we can tell this statically. I.e., we're not going to defer this to runtime
- * just in case the delimiters are being determined at runtime.
- *
- * That is to say, if a delimiter is an expression, then we're assuming that means
- * at runtime it will not evaluate to empty string (so you can specify the delimiter
- * at runtime, but you cannot turn on/off the whole delimited format at runtime.)
- */
- final lazy val isDefaultable: Boolean = LV('isDefaultable) {
- if (isSimpleType) {
- if (!isRepresented) false
- else if (!hasDefaultValue) false
- else {
- if (!emptyIsAnObservableConcept)
- SDW("Element has no empty representation so cannot have XSD default='%s' as a default value.", defaultValueAsString)
- schemaDefinitionWhen(isOptional, "Optional elements cannot have default values but default='%s' was found.", defaultValueAsString)
- if (isArray && !isRequiredArrayElement) {
- (optMinOccurs, occursCountKind) match {
- case (_, OccursCountKind.Parsed) |
- (_, OccursCountKind.StopValue) =>
- SDE("XSD default='%s' can never be used since an element with dfdl:occursCountKind='%s' has no required occurrences.",
- defaultValueAsString, occursCountKind)
- case (Some(0), _) => SDE("XSD default='%s' can never be used since an element with XSD minOccurs='0' has no required occurrences.",
- defaultValueAsString)
- case _ => // ok
- }
- }
- Assert.invariant(hasDefaultValue)
- !isOptional &&
- (isScalar ||
- isRequiredArrayElement)
- }
- } else {
- // TODO: Implement complex element defaulting
- // JIRA issue DFDL-1277
- //
- // a complex element is defaultable
- // recursively if everything in it is defaultable
- // and everything in it has no required representation
- // (e.g., no required delimiters, no alignment, no skip, etc.)
- // furthermore, even the defaultable things inside must satisfy
- // a stricter criterion. They must have emptyValueDelimiterPolicy='none'
- // if delimiters are defined and they could be empty (which is implied if they are defaultable)
- false
- }
- }.value
-
- final override lazy val inputValueCalcOption = findPropertyOption("inputValueCalc")
- final override lazy val outputValueCalcOption = {
- val optOVC = findPropertyOption("outputValueCalc")
- self.schemaDefinitionWhen(optOVC.isDefined && self.isOptional, "dfdl:outputValueCalc cannot be defined on optional elements.")
- self.schemaDefinitionWhen(optOVC.isDefined && self.isArray, "dfdl:outputValueCalc cannot be defined on array elements.")
- // This should be an SDE, but is very useful for unit tests to be able to specify OVC on a single global element
- // self.schemaDefinitionWhen(optOVC.isDefined && self.isInstanceOf[GlobalElementDecl], "dfdl:outputValueCalc cannot be defined on global elements.")
-
- optOVC
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementRef.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementRef.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementRef.scala
index d840880..6d4b928 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementRef.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ElementRef.scala
@@ -35,43 +35,41 @@ package edu.illinois.ncsa.daffodil.dsom
import scala.xml.Node
import edu.illinois.ncsa.daffodil.grammar._
import edu.illinois.ncsa.daffodil.xml._
-import edu.illinois.ncsa.daffodil.processors._
import edu.illinois.ncsa.daffodil.grammar.ElementReferenceGrammarMixin
-import edu.illinois.ncsa.daffodil.schema.annotation.props.PropertyLookupResult
+import edu.illinois.ncsa.daffodil.dpath.NodeInfo
/**
- * Note ElementRef isn't a first class citizen with the other schema components.
- * It gets bypassed in that most things here just delegate to the GlobalElementDecl
- * that this references.
- *
- * Most of the framework expects to be handling elements via the ElementBase abstract
- * class. That class is responsible for testing and reaching back over to an ElementRef.
- *
- * So for example, to find out if an element has a property, an Element has to consider
- * that the property might be expressed on an element ref (if there is one), the element
- * itself, or a simpleType def or a base simple type def. Element does this. ElementRef
- * doesn't.
+ * There are 3 first-class concrete children of ElementBase.
+ * Root, LocalElementDecl, and ElementRef
*/
-final class ElementRef(xmlArg: Node, parent: ModelGroup, position: Int)
- extends LocalElementBase(xmlArg, parent, position)
+final class ElementRef(xmlArg: Node, parent: GroupDefLike, position: Int)
+ extends AbstractElementRef(xmlArg, parent, position)
+
+abstract class AbstractElementRef(xmlArg: Node,
+ parentArg: SchemaComponent,
+ positionArg: Int)
+ extends ElementBase
with ElementReferenceGrammarMixin
with HasRefMixin
with NamedMixin
with NestingLexicalMixin {
- requiredEvaluations(referencedElement)
-
- override def findPropertyOption(pname: String): PropertyLookupResult = {
- val res = referencedElement.findPropertyOption(pname)
- res
- }
+ override lazy val xml = xmlArg
+ final override lazy val parent = parentArg
+ final override lazy val position = positionArg
- lazy val nonDefaultPropertySources = referencedElement.nonDefaultPropertySources
- lazy val defaultPropertySources = referencedElement.defaultPropertySources
+ requiredEvaluations(referencedElement)
- lazy val elementRef = None
+ def complexType: ComplexTypeBase = this.referencedElement.complexType
+ def defaultValueAsString: String = this.referencedElement.defaultValueAsString
+ def hasDefaultValue: Boolean = this.referencedElement.hasDefaultValue
+ def isComplexType: Boolean = this.referencedElement.isComplexType
+ def isNillable: Boolean = this.referencedElement.isNillable
+ def isSimpleType: Boolean = this.referencedElement.isSimpleType
+ def simpleType: SimpleTypeBase = this.referencedElement.simpleType
+ def primType: NodeInfo.PrimType = this.referencedElement.primType
- override lazy val referredToComponent = referencedElement
+ override lazy val optReferredToComponent = Some(referencedElement)
/**
* Note: since the namedQName might not exist, we cannot use
@@ -83,10 +81,12 @@ final class ElementRef(xmlArg: Node, parent: ModelGroup, position: Int)
referencedElement.namedQName
}.value
- override lazy val prefix = referencedElement.prefix
+ override lazy val name = refQName.local
+
+ override lazy val prefix = refQName.prefix.getOrElse(null)
// Need to go get the Element we are referencing
- final lazy val referencedElement: GlobalElementDecl = LV('referencedElement) {
+ lazy val referencedElement: GlobalElementDecl = LV('referencedElement) {
val ged = this.schemaSet.getGlobalElementDecl(refQName)
val res = ged match {
case None => {
@@ -106,43 +106,10 @@ final class ElementRef(xmlArg: Node, parent: ModelGroup, position: Int)
res
}.value
- override lazy val runtimeData = referencedElement.runtimeData
- override lazy val termRuntimeData = referencedElement.termRuntimeData
- override def erd = referencedElement.erd
- override lazy val elementRuntimeData: ElementRuntimeData = LV('elementRuntimeData) {
- referencedElement.elementRuntimeData
- }.value
- override lazy val dpathElementCompileInfo = referencedElement.dpathElementCompileInfo
-
- // These will just delegate to the referenced element declaration
- def isNillable = referencedElement.isNillable
- def isSimpleType = referencedElement.isSimpleType
- def isComplexType = referencedElement.isComplexType
-
- def isDefaultable: Boolean = referencedElement.isDefaultable
- def defaultValueAsString = referencedElement.defaultValueAsString
-
override lazy val namespace = refQName.namespace
override lazy val diagnosticDebugName = "element reference " + refQName
- override lazy val name = this.ref
-
- // TODO: perhaps many members of ElementRef are unused.
- // Consider removing some. Although consider that
- // some have to be here because of abstract bases or traits requiring them
- // even if they aren't called.
override def typeDef = referencedElement.typeDef
- // Element references can have minOccurs and maxOccurs, and annotations, but nothing else.
- override def inputValueCalcOption = referencedElement.inputValueCalcOption // can't have ivc on element reference
- override def outputValueCalcOption = referencedElement.outputValueCalcOption // can't have ivc on element reference
-
- //TODO: refactor and use shared code for creating resolved set of annotations for an annotation point.
- override lazy val statements = localStatements
- override lazy val newVariableInstanceStatements = localNewVariableInstanceStatements
- override lazy val assertStatements = localAssertStatements
- override lazy val discriminatorStatements = localDiscriminatorStatements
- override lazy val setVariableStatements = localSetVariableStatements
-
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/EscapeSchemeRefMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/EscapeSchemeRefMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/EscapeSchemeRefMixin.scala
index 67f92eb..e565fee 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/EscapeSchemeRefMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/EscapeSchemeRefMixin.scala
@@ -58,7 +58,7 @@ trait EscapeSchemeRefMixin { self: AnnotatedSchemaComponent =>
* issue DFDL-77)
*/
final lazy val optionEscapeScheme: Option[DFDLEscapeScheme] = {
- val er = findPropertyOption("escapeSchemeRef")
+ val er = self.resolver.findPropertyOption("escapeSchemeRef")
er match {
case _: NotFound => {
SDW(WarnID.EscapeSchemeRefUndefined,
[5/6] incubator-daffodil git commit: Property Resolution - part of
fixing schema compilation
Posted by mb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GlobalElementDecl.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GlobalElementDecl.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GlobalElementDecl.scala
index 347233d..7221cd9 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GlobalElementDecl.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GlobalElementDecl.scala
@@ -32,63 +32,26 @@
package edu.illinois.ncsa.daffodil.dsom
-import edu.illinois.ncsa.daffodil.grammar._
+import scala.xml.Node
-/**
- * A global element decl uses LocalElementBase because it behaves like a local
- * element when you consider that except for the root case, it has to be combined
- * with an ElementRef that references it. The ElementRef can carry the things
- * like min/maxOccurs and such that aren't allowed on a GlobalElementDecl. The
- * combination of an ElementRef plus its GlobalElementDecl behaves like a LocalElementDecl.
- */
final class GlobalElementDecl(
- val factory: GlobalElementDeclFactory,
- override val elementRef: Option[ElementRef])
- extends LocalElementBase(factory.xml, factory.schemaDocument, 0)
+ xmlArg: Node,
+ schemaDocument: SchemaDocument,
+ elementRefArg: => AbstractElementRef)
+ extends AnnotatedSchemaComponentImpl(xmlArg, schemaDocument)
with GlobalElementComponentMixin
with ElementDeclMixin
- with GlobalElementDeclGrammarMixin
- with NestingTraversesToReferenceMixin
- /*
- * global elements combined with element references referring to them can
- * be multiple occurring (aka arrays) hence, we have to have things
- * that take root and referenced situation into account.
- */
- with RequiredOptionalMixin {
-
- requiredEvaluations(validateChoiceBranchKey)
-
- override lazy val maxOccurs = elementRef match {
- case Some(er) => er.maxOccurs
- case None => 1
- }
-
- override lazy val minOccurs = elementRef match {
- case Some(er) => er.minOccurs
- case None => 1
- }
-
- lazy val isRoot = elementRef == None
-
- override lazy val isHidden = if (isRoot) false else elementRef.get.isHidden
+ with NestingTraversesToReferenceMixin {
+ // global elements combined with element references referring to them can
+ // be multiple occurring (aka arrays) hence, we have to have things
+ // that take root and referenced situation into account.
- // final override protected def enclosingComponentDef = elementRef.flatMap { _.enclosingComponent }
+ lazy val elementRef = elementRefArg
+ override lazy val dpathCompileInfo = elementRef.dpathElementCompileInfo
- override lazy val referringComponent: Option[SchemaComponent] = elementRef
-
- // GlobalElementDecls need to have access to elementRef's local properties.
-
- // We inherit the requirement for these attributes from Term. It all gets
- // too complicated in DSOM if you try to make GlobalElementDecl share with the other
- // element structures but not be a Term.
- //
- // But a GlobalElementDecl isn't really a Term except in a degenerate sense
- // that the root element is sort of a Term.
- //
- // In other words, we shouldn't be treating this as a term.
- //
+ requiredEvaluations(validateChoiceBranchKey)
- lazy val rootParseUnparsePolicy = defaultParseUnparsePolicy
+ override lazy val referringComponent: Option[SchemaComponent] = Some(elementRef) // optElementRef
def validateChoiceBranchKey(): Unit = {
// Ensure that the global element decl does not have choiceBranchKey set.
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GlobalElementDeclFactory.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GlobalElementDeclFactory.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GlobalElementDeclFactory.scala
index 114200b..f698012 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GlobalElementDeclFactory.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GlobalElementDeclFactory.scala
@@ -50,10 +50,15 @@ class GlobalElementDeclFactory(xmlArg: Node, schemaDocumentArg: SchemaDocument)
with GlobalElementComponentMixin {
def forRoot() = asRoot // cache. Not a new one every time.
- lazy val asRoot = new GlobalElementDecl(this, None)
- def forElementRef(eRef: ElementRef) = {
- new GlobalElementDecl(this, Some(eRef))
+ private lazy val asRoot = {
+ lazy val ged = new GlobalElementDecl(xml, parent, root)
+ lazy val root: Root = new Root(xml, schemaDocument, namedQName, ged)
+ root
+ }
+
+ def forElementRef(eRef: AbstractElementRef) = {
+ new GlobalElementDecl(xml, schemaDocument, eRef)
}
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GroupBase.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GroupBase.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GroupBase.scala
deleted file mode 100644
index 6b39c36..0000000
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GroupBase.scala
+++ /dev/null
@@ -1,92 +0,0 @@
-/* Copyright (c) 2012-2015 Tresys Technology, LLC. All rights reserved.
- *
- * Developed by: Tresys Technology, LLC
- * http://www.tresys.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal with
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimers.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimers in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the names of Tresys Technology, nor the names of its contributors
- * may be used to endorse or promote products derived from this Software
- * without specific prior written permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
- * SOFTWARE.
- */
-
-package edu.illinois.ncsa.daffodil.dsom
-
-import scala.xml.Node
-import scala.xml._
-import edu.illinois.ncsa.daffodil.schema.annotation.props.AlignmentType
-import edu.illinois.ncsa.daffodil.schema.annotation.props.gen.AlignmentUnits
-import java.lang.{ Integer => JInt }
-
-abstract class GroupBase(xmlArg: Node, parentArg: SchemaComponent, position: Int)
- extends Term(xmlArg, parentArg, position) {
-
- final override def isScalar = true
- final override def isOptional = false
- final override def isRequired = true
- final override def isArray = false
-
- private def prettyIndex = {
- myPeers.map { peers =>
- {
- if (peers.length == 1) "" // no index expression if we are the only one
- else "[" + (peers.indexOf(this) + 1) + "]" // 1-based indexing in XML/XSD
- }
- }.getOrElse("")
- }
-
- override lazy val diagnosticDebugName = prettyBaseName + prettyIndex
- protected def prettyBaseName: String
-
- /**
- * This is only the immediately enclosing model group. It doesn't walk outward.
- */
- final lazy val enclosingComponentModelGroup = enclosingComponent.collect { case mg: ModelGroup => mg }
- final lazy val sequencePeers = enclosingComponentModelGroup.map { _.sequenceChildren }
- final lazy val choicePeers = enclosingComponentModelGroup.map { _.choiceChildren }
- final lazy val groupRefPeers = enclosingComponentModelGroup.map { _.groupRefChildren }
-
- protected def myPeers: Option[Seq[GroupBase]]
-
- def group: ModelGroup
-
- final lazy val immediateGroup: Option[ModelGroup] = {
- val res: Option[ModelGroup] = this.group match {
- case (s: Sequence) => Some(s)
- case (c: Choice) => Some(c)
- case _ => None
- }
- res
- }
-
- final lazy val alignmentValueInBits: JInt = {
- this.alignment match {
- case AlignmentType.Implicit => 1
- case align: JInt => this.alignmentUnits match {
- case AlignmentUnits.Bits => align
- case AlignmentUnits.Bytes => 8 * align
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GroupDef.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GroupDef.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GroupDef.scala
index 0bd984a..5992095 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GroupDef.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GroupDef.scala
@@ -34,70 +34,128 @@ package edu.illinois.ncsa.daffodil.dsom
import scala.xml.Node
import edu.illinois.ncsa.daffodil.exceptions.Assert
-import edu.illinois.ncsa.daffodil.xml.QName
+import scala.xml.Text
+import scala.xml.Comment
-class GlobalGroupDefFactory(xmlArg: Node, schemaDocumentArg: SchemaDocument)
- extends SchemaComponentFactory(xmlArg, schemaDocumentArg)
+final class GlobalGroupDefFactory(defXML: Node, schemaDocument: SchemaDocument)
+ extends SchemaComponentFactory(defXML, schemaDocument)
with GlobalNonElementComponentMixin {
- private lazy val trimmedXml = scala.xml.Utility.trim(xmlArg)
-
- def forGroupRef(gref: GroupRef, position: Int) = {
+ def forGroupRef(refXML: Node, refLexicalParent: SchemaComponent, position: Int,
+ isHidden: Boolean): (GroupRef, GlobalGroupDef) = {
+ val trimmedXml = scala.xml.Utility.trim(defXML)
trimmedXml match {
case <group>{ contents @ _* }</group> => {
- val ggd = contents.collect {
- case <sequence>{ _* }</sequence> => new GlobalSequenceGroupDef(xml, schemaDocument, gref, position)
- case <choice>{ _* }</choice> => new GlobalChoiceGroupDef(xml, schemaDocument, gref, position)
+ val list = contents.collect {
+ case groupXML @ <sequence>{ _* }</sequence> => {
+ lazy val gref: SequenceGroupRef = new SequenceGroupRef(gdef, refXML, refLexicalParent, position, isHidden)
+ lazy val gdef: GlobalSequenceGroupDef = new GlobalSequenceGroupDef(defXML, groupXML, schemaDocument, gref)
+ gref.groupDef
+ gdef.groupRef
+ (gref, gdef)
+ }
+ case groupXML @ <choice>{ _* }</choice> =>
+ lazy val gref: ChoiceGroupRef = new ChoiceGroupRef(gdef, refXML, refLexicalParent, position, isHidden)
+ lazy val gdef: GlobalChoiceGroupDef = new GlobalChoiceGroupDef(defXML, groupXML, schemaDocument, gref)
+ gref.groupDef
+ gdef.groupRef
+ (gref, gdef)
}
- Assert.invariant(ggd.length == 1)
- ggd(0)
+ val res = list(0)
+ res
}
case _ => Assert.invariantFailed("not a group")
}
}
+}
+
+/**
+ * Common concepts for components that define groups.
+ *
+ * This includes both global group definitions, and local sequence
+ * and choice groups.
+ */
+trait GroupDefLike
+ extends AnnotatedSchemaComponent
+ with ProvidesDFDLStatementMixin {
- override lazy val namedQName = QName.createGlobal(name, targetNamespace, xml.scope)
+ def xmlChildren: Seq[Node]
+ /** Returns the group members that are elements or model groups. */
+ final lazy val groupMembers: Seq[Term] = LV('groupMembers) {
+ //
+ // So we have to flatMap, so that we can tolerate annotation objects (like documentation objects).
+ // and our ModelGroup factory has to return Nil for annotations and Text nodes.
+ //
+ val goodXmlChildren = LV('goodXMLChildren) { xmlChildren.flatMap { removeNonInteresting(_) } }.value
+ val positions = List.range(1, goodXmlChildren.length + 1) // range is exclusive on 2nd arg. So +1.
+ val pairs = goodXmlChildren zip positions
+ pairs.flatMap {
+ case (n, i) =>
+ TermFactory(n, this, i)
+ }
+ }.value
+
+ /**
+ * XML is full of uninteresting text nodes. We just want the element children, not all children.
+ */
+ private def removeNonInteresting(child: Node) = {
+ val childList: List[Node] = child match {
+ case _: Text => Nil
+ case _: Comment => Nil
+ case <annotation>{ _* }</annotation> => Nil
+ case _ => List(child)
+ }
+ childList
+ }
}
-sealed abstract class GlobalGroupDef(xmlArg: Node, schemaDocumentArg: SchemaDocument, val groupRef: GroupRef, position: Int)
- extends SchemaComponent(xmlArg, schemaDocumentArg)
- with GlobalNonElementComponentMixin
+/**
+ * Global Group Defs carry annotations that are combined wiht those
+ * of the corresponding group reference that refers to them.
+ *
+ * These are not carried on the xs:group element itself, but the xs:sequence
+ * or xs:choice XML child. When we refer to the annotations on a global group
+ * definition, we are referring to the annotations on the xs:sequence or xs:choice.
+ */
+sealed abstract class GlobalGroupDef(
+ defXML: Node,
+ groupXML: Node,
+ schemaDocumentArg: SchemaDocument,
+ grefArg: => GroupRef)
+ extends AnnotatedSchemaComponentImpl(groupXML, schemaDocumentArg)
+ with GroupDefLike
+ with GlobalNonElementComponentMixin
with NestingTraversesToReferenceMixin {
- requiredEvaluations(modelGroup)
+ requiredEvaluations(groupMembers)
requiredEvaluations(validateChoiceBranchKey)
- final lazy val referringComponent = {
- val res = Some(groupRef)
- res
- }
-
- // final override protected def enclosingComponentDef = groupRef.enclosingComponent
-
- //
- // Note: Dealing with XML can be fragile. It's easy to forget some of these children
- // might be annotations and Text nodes. Even if you trim the text nodes out, there are
- // places where annotations can be.
- //
- final lazy val <group>{ xmlChildren @ _* }</group> = xml
- //
- // So we have to flatMap, so that we can tolerate annotation objects (like documentation objects).
- // and our ModelGroup factory has to return Nil for annotations and Text nodes.
- //
- final lazy val Seq(modelGroup: ModelGroup) = xmlChildren.flatMap { ModelGroupFactory(_, this, position) }
+ lazy val groupRef = grefArg // once only
def validateChoiceBranchKey(): Unit = {
// Ensure the model group of a global group def do not define choiceBranchKey.
- val found = modelGroup.findPropertyOptionThisComponentOnly("choiceBranchKey")
+ val found = findPropertyOptionThisComponentOnly("choiceBranchKey")
if (found.isDefined) {
SDE("dfdl:choiceBranchKey cannot be specified on the choice/sequence child of a global group definition")
}
}
+
+ final override lazy val name = defXML.attribute("name").map { _.text }.getOrElse(
+ Assert.invariantFailed("Global group def without name attribute."))
+
+ final override protected def optReferredToComponent = None
+
+ final override lazy val referringComponent = Some(groupRef.asModelGroup)
}
-final class GlobalSequenceGroupDef(xmlArg: Node, schemaDocument: SchemaDocument, groupRef: GroupRef, position: Int)
- extends GlobalGroupDef(xmlArg, schemaDocument, groupRef, position)
+final class GlobalSequenceGroupDef(defXMLArg: Node, seqXML: Node, schemaDocument: SchemaDocument, gref: => SequenceGroupRef)
+ extends GlobalGroupDef(defXMLArg, seqXML, schemaDocument, gref)
+ with SequenceDefMixin
+
+final class GlobalChoiceGroupDef(defXMLArg: Node, choiceXML: Node, schemaDocument: SchemaDocument, gref: => ChoiceGroupRef)
+ extends GlobalGroupDef(defXMLArg, choiceXML, schemaDocument, gref)
+ with ChoiceDefMixin {
+
+}
-final class GlobalChoiceGroupDef(xmlArg: Node, schemaDocument: SchemaDocument, groupRef: GroupRef, position: Int)
- extends GlobalGroupDef(xmlArg, schemaDocument, groupRef, position)
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GroupRef.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GroupRef.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GroupRef.scala
index 5803c32..9222711 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GroupRef.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/GroupRef.scala
@@ -34,82 +34,99 @@ package edu.illinois.ncsa.daffodil.dsom
import scala.xml.Node
import scala.xml._
-import edu.illinois.ncsa.daffodil.schema.annotation.props.SeparatorSuppressionPolicyMixin
-import edu.illinois.ncsa.daffodil.schema.annotation.props.gen.Group_AnnotationMixin
-import edu.illinois.ncsa.daffodil.grammar.GroupRefGrammarMixin
import edu.illinois.ncsa.daffodil.xml.HasRefMixin
-import edu.illinois.ncsa.daffodil.schema.annotation.props.PropertyLookupResult
+import edu.illinois.ncsa.daffodil.schema.annotation.props.NotFound
-/**
- * A GroupRef (group reference) is a term, but most everything is delgated to the
- * referred-to Global Group Definition object.
- */
-final class GroupRef(xmlArg: Node, parent: SchemaComponent, position: Int)
- extends GroupBase(xmlArg, parent, position)
- with DFDLStatementMixin
- with GroupRefGrammarMixin
- with Group_AnnotationMixin
- with SeparatorSuppressionPolicyMixin
- with SequenceRuntimeValuedPropertiesMixin
- with HasRefMixin
- with NestingLexicalMixin {
+trait GroupRef { self: ModelGroup =>
- requiredEvaluations(groupDef)
+ final def asModelGroup: ModelGroup = self
- override lazy val elementChildren = group.elementChildren
+ def groupDef: GlobalGroupDef
- // delegate to the model group object. It assembles properties from
- // the group ref and the group def
- override def findPropertyOption(pname: String): PropertyLookupResult = {
- val res = group.findPropertyOption(pname)
- res
- }
- lazy val nonDefaultPropertySources = group.nonDefaultPropertySources
- lazy val defaultPropertySources = group.defaultPropertySources
+ final def referredToComponent = groupDef
- protected lazy val prettyBaseName = "group.ref." + refQName.local
+ final override lazy val optReferredToComponent = Some(referredToComponent)
- protected lazy val myPeers = groupRefPeers
+ final override lazy val groupMembers = groupDef.groupMembers
- override lazy val termChildren: Seq[Term] = {
- group.termChildren
+ override protected def annotationFactory(node: Node): Option[DFDLAnnotation] = {
+ node match {
+ case <dfdl:group>{ contents @ _* }</dfdl:group> => Some(new DFDLGroup(node, this))
+ case _ => annotationFactoryForDFDLStatement(node, self)
+ }
}
- final lazy val qname = resolveQName(ref)
+ override protected final def emptyFormatFactory: DFDLFormatAnnotation = new DFDLGroup(newDFDLAnnotationXML("group"), this)
- protected def annotationFactory(node: Node): Option[DFDLAnnotation] = {
- node match {
- case <dfdl:group>{ contents @ _* }</dfdl:group> => Some(new DFDLGroup(node, this))
- case _ => annotationFactoryForDFDLStatement(node, this)
+ override protected final def isMyFormatAnnotation(a: DFDLAnnotation) = a.isInstanceOf[DFDLAnnotation]
+
+}
+
+/**
+ * A GroupRefFactory (group reference) is an indirection to
+ * factories to create a SequenceGroupRef, or ChoiceGroupRef.
+ *
+ * The refXMLArg is the xml for the group reference.
+ *
+ * This factory exists in order to make error messages refer to the
+ * right part of the schema.
+ */
+final class GroupRefFactory(refXMLArg: Node, val refLexicalParent: SchemaComponent, position: Int, isHidden: Boolean)
+ extends SchemaComponentFactory(refXMLArg, refLexicalParent.schemaDocument)
+ with HasRefMixin {
+
+ final def qname = this.refQName
+
+ lazy val groupRef = {
+ val gdefFactory = parent.schemaSet.getGlobalGroupDef(qname).getOrElse {
+ SDE("Referenced group definition not found: %s", this.ref)
}
+ val (gref, _) = gdefFactory.forGroupRef(refXMLArg, refLexicalParent, position, isHidden)
+ gref
}
- protected final def emptyFormatFactory = new DFDLGroup(newDFDLAnnotationXML("group"), this)
- protected final def isMyFormatAnnotation(a: DFDLAnnotation) = a.isInstanceOf[DFDLGroup]
+}
- def hasStaticallyRequiredInstances = group.hasStaticallyRequiredInstances
+final class SequenceGroupRef(globalGroupDef: => GlobalSequenceGroupDef,
+ refXML: Node,
+ refLexicalParent: SchemaComponent,
+ positionArg: Int,
+ isHiddenArg: Boolean)
+ extends SequenceTermBase(refXML, refLexicalParent, positionArg)
+ with GroupRef {
- override lazy val group = groupDef.modelGroup
+ override def isHidden = isHiddenArg
- override lazy val termRuntimeData = group.termRuntimeData
+ private lazy val sgd = groupDef.asInstanceOf[GlobalSequenceGroupDef]
- override lazy val couldHaveText = group.couldHaveText
+ override def xmlChildren = sgd.xmlChildren
- override lazy val referredToComponent = group
+ override def apparentXMLChildren = sgd.apparentXMLChildren
- override lazy val encodingInfo = group.encodingInfo
+ private val nf = NotFound(Nil, Nil, "hiddenGroupRef")
- lazy val groupDef = LV('groupDef) {
- this.schemaSet.getGlobalGroupDef(qname) match {
- case None => SDE("Referenced group definition not found: %s", this.ref)
- case Some(x) => x.forGroupRef(this, position)
- }
- }.value
+ override def hiddenGroupRefOption = nf
+
+ override lazy val groupDef = globalGroupDef
+
+}
+
+final class ChoiceGroupRef(globalGroupDef: => GlobalChoiceGroupDef,
+ refXML: Node,
+ refLexicalParent: SchemaComponent,
+ positionArg: Int,
+ isHiddenArg: Boolean)
+ extends ChoiceTermBase(refXML, refLexicalParent, positionArg)
+ with GroupRef {
+
+ requiredEvaluations(groupDef)
+
+ override def isHidden = isHiddenArg
+
+ override lazy val groupDef = globalGroupDef
+
+ private lazy val cgd = groupDef.asInstanceOf[GlobalChoiceGroupDef]
- lazy val statements = localStatements
- lazy val newVariableInstanceStatements = localNewVariableInstanceStatements
- lazy val assertStatements = localAssertStatements
- lazy val discriminatorStatements = localDiscriminatorStatements
- lazy val setVariableStatements = localSetVariableStatements
+ override lazy val xmlChildren = cgd.xmlChildren
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/IIBase.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/IIBase.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/IIBase.scala
index 8160656..bfba75d 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/IIBase.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/IIBase.scala
@@ -137,9 +137,10 @@ object IIUtils {
/**
* Include/Import = "II" for short
*/
-abstract class IIBase(xml: Node, xsdArg: XMLSchemaDocument, val seenBefore: IIMap)
- extends SchemaComponent(xml, xsdArg)
+abstract class IIBase( final override val xml: Node, xsdArg: XMLSchemaDocument, val seenBefore: IIMap)
+ extends SchemaComponent
with NestingLexicalMixin {
+ final override def parent = xsdArg
/**
* An import/include requires only that we can access the
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/InitiatedTerminatedMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/InitiatedTerminatedMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/InitiatedTerminatedMixin.scala
index 6d76814..e5bad64 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/InitiatedTerminatedMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/InitiatedTerminatedMixin.scala
@@ -60,7 +60,8 @@ trait InitiatedTerminatedMixin
}
final lazy val hasTerminator = {
- terminatorExpr.isKnownNonEmpty
+ val res = terminatorExpr.isKnownNonEmpty
+ res
}
lazy val initiatorDiscriminator = prod("initiatorDiscriminator", parentSaysInitiatedContent) { InitiatedContent(this) }
@@ -75,7 +76,7 @@ trait InitiatedTerminatedMixin
* present, or there is an expression. (Such expressions are not allowed to evaluate to "" - you
* can't turn off a delimiter by providing "" at runtime. Minimum length is 1 for these at runtime.
* <p>
- * Override in Sequence to also check for separator.
+ * Override in SequenceTermBase to also check for separator.
*/
lazy val hasDelimiters = hasInitiator || hasTerminator
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/LocalElementBase.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/LocalElementBase.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/LocalElementBase.scala
deleted file mode 100644
index 910b3d4..0000000
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/LocalElementBase.scala
+++ /dev/null
@@ -1,80 +0,0 @@
-/* Copyright (c) 2012-2015 Tresys Technology, LLC. All rights reserved.
- *
- * Developed by: Tresys Technology, LLC
- * http://www.tresys.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal with
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimers.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimers in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the names of Tresys Technology, nor the names of its contributors
- * may be used to endorse or promote products derived from this Software
- * without specific prior written permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
- * SOFTWARE.
- */
-
-package edu.illinois.ncsa.daffodil.dsom
-
-import scala.xml.Node
-
-abstract class LocalElementBase(xmlArg: Node, parent: SchemaComponent, position: Int)
- extends ElementBase(xmlArg, parent, position)
- with LocalElementMixin {
-
- requiredEvaluations(checkForAlignmentAmbiguity)
-
- private def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
- // private def lcm(a: Int, b: Int): Int = math.abs(a * b) / gcd(a, b)
- // private def isXAMultipleOfY(x: Int, y: Int): Boolean = (x % y) == 0
-
- // private def isAlignmentCompatible(current: Int, next: Int): Boolean = {
- // isXAMultipleOfY(current, next)
- // }
-
- /**
- * Changed to a warning - DFDL WG decided to make this check optional, but it
- * is still useful as a warning.
- *
- * Turns out that MIL STD 2045 header format needs to pad out to a byte boundary
- * at the end of the structure. An optional, non-byte aligned field precedes
- * the end of the structure; hence, putting a zero-length byte-aligned field
- * at the end was crashing into this error. I couldn't think of a work-around,
- * so changed this into a warning.
- *
- * The old requirement was:
- * To avoid ambiguity when parsing, optional elements and variable-occurrence arrays
- * where the minimum number of occurrences is zero cannot have alignment properties
- * different from the items that follow them. It is a schema definition error otherwise.
- *
- * Part of the required evaluations for LocalElementBase.
- */
- final def checkForAlignmentAmbiguity: Unit = {
- if (isOptional) {
- this.possibleNextTerms.filterNot(m => m == thisTermNoRefs).foreach { that =>
- val isSame = this.alignmentValueInBits == that.alignmentValueInBits
- if (!isSame) {
- this.SDW("%s is an optional element or a variable-occurrence array and its alignment (%s) is not the same as %s's alignment (%s).",
- this.toString, this.alignmentValueInBits, that.toString, that.alignmentValueInBits)
- }
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/LocalElementDecl.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/LocalElementDecl.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/LocalElementDecl.scala
index 1b12568..abd9868 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/LocalElementDecl.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/LocalElementDecl.scala
@@ -34,27 +34,15 @@ package edu.illinois.ncsa.daffodil.dsom
import scala.xml.Node
-final class LocalElementDeclFactory(override val xml: Node, sd: SchemaDocument)
- extends SchemaComponentFactory(xml, sd)
- with LocalElementComponentMixin {
-
- def forModelGroup(parent: ModelGroup, position: Int) =
- new LocalElementDecl(this, parent, position)
-
-}
-
-final class LocalElementDecl(factory: LocalElementDeclFactory,
- override val parent: ModelGroup,
- override val position: Int)
- extends LocalElementBase(factory.xml, parent, position)
+final class LocalElementDecl(
+ final override val xml: Node,
+ final override val parent: GroupDefLike,
+ final override val position: Int)
+ extends ElementBase
with LocalElementComponentMixin
with ElementDeclMixin
with NestingLexicalMixin {
- override lazy val elementRef = None
-
requiredEvaluations(minOccurs, maxOccurs)
- final override lazy val namedQName = factory.namedQName
-
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/LocalElementMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/LocalElementMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/LocalElementMixin.scala
index e83b78c..ec78d8a 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/LocalElementMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/LocalElementMixin.scala
@@ -45,7 +45,7 @@ import java.math.{ BigInteger => JBigInt }
*/
trait LocalElementMixin
extends ParticleMixin
- with LocalElementGrammarMixin { self: LocalElementBase =>
+ with LocalElementGrammarMixin { self: ElementBase =>
final def hasSep = LV('hasSep) {
nearestEnclosingSequence match {
@@ -120,7 +120,7 @@ trait LocalElementMixin
val res = es match {
case None => true
case Some(s) => {
- val allRequired = s.groupMembersNoRefs.filter(_.isRequired)
+ val allRequired = s.groupMembers.filter(_.isRequired)
val lastDeclaredRequired = allRequired.last
if (lastDeclaredRequired _eq_ this) true
else false
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ModelGroup.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ModelGroup.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ModelGroup.scala
index 6f80714..97dc397 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ModelGroup.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ModelGroup.scala
@@ -32,7 +32,6 @@
package edu.illinois.ncsa.daffodil.dsom
-import scala.Option.option2Iterable
import scala.xml.Node
import scala.xml.NodeSeq.seqToNodeSeq
import scala.xml.Text
@@ -45,26 +44,49 @@ import edu.illinois.ncsa.daffodil.grammar.ModelGroupGrammarMixin
import edu.illinois.ncsa.daffodil.infoset.ChoiceBranchEvent
import edu.illinois.ncsa.daffodil.infoset.ChoiceBranchStartEvent
import edu.illinois.ncsa.daffodil.infoset.ChoiceBranchEndEvent
+import java.lang.{ Integer => JInt }
+import edu.illinois.ncsa.daffodil.schema.annotation.props.AlignmentType
+import edu.illinois.ncsa.daffodil.schema.annotation.props.gen.AlignmentUnits
/**
* A factory for model groups.
+ *
+ * Takes care of detecting group references, and constructing the
+ * proper SequenceGroupRef or ChoiceGroupRef object.
*/
-sealed abstract class ModelGroupFactory private () {
+object ModelGroupFactory {
/**
* Because of the contexts where this is used, we return a list. That lets users
* flatmap it to get a collection of model groups. Nil for non-model groups, non-Nil for the model group
* object. There should be only one non-Nil.
*/
- def apply(child: Node, parent: SchemaComponent, position: Int) = {
- val childList: List[GroupBase] = child match {
- case <sequence>{ _* }</sequence> => List(new Sequence(child, parent, position))
+ def apply(child: Node, parent: SchemaComponent, position: Int, isHidden: Boolean): List[ModelGroup] = {
+ val childList: List[ModelGroup] = child match {
+ case <sequence>{ _* }</sequence> => {
+ val seq = new Sequence(child, parent, position)
+ if (seq.hiddenGroupRefOption.isDefined) {
+ //
+ // construct the group ref XML, then recursively process that,
+ // but set flag so it will be hidden.
+ //
+ val hgrXML = seq.hiddenGroupRefXML
+ ModelGroupFactory(hgrXML, parent, position, true)
+ } else {
+ List(seq)
+ }
+ }
case <choice>{ _* }</choice> => List(new Choice(child, parent, position))
case <group>{ _* }</group> => {
- parent match {
- case ct: ComplexTypeBase => List(new GroupRef(child, ct, 1))
- case mg: ModelGroup => List(new GroupRef(child, mg, position))
+ val pos = parent match {
+ case ct: ComplexTypeBase => 1
+ case mg: ModelGroup => position
+ case gd: GlobalGroupDef => position
}
+ val isH = isHidden || parent.isHidden
+ val groupRefFactory = new GroupRefFactory(child, parent, pos, isH)
+ val groupRefInstance = groupRefFactory.groupRef
+ List(groupRefInstance.asModelGroup)
}
case <annotation>{ _* }</annotation> => Nil
case textNode: Text => Nil
@@ -78,25 +100,96 @@ sealed abstract class ModelGroupFactory private () {
}
-object ModelGroupFactory extends ModelGroupFactory()
+/**
+ * Factory for Terms
+ */
+object TermFactory {
+
+ /**
+ * Returns a List of Term. There should be exactly one Term in the list.
+ *
+ * List, not one term, because of the context where this is used, non-Nil for
+ * an actual term. There should be only one non-Nil allows flattening to
+ * remove all the parts of the schema that are not relevant.
+ *
+ */
+ def apply(child: Node, parent: GroupDefLike, position: Int) = {
+ val childList: List[Term] = child match {
+ case <element>{ _* }</element> => {
+ val refProp = child.attribute("ref").map { _.text }
+ // must get an unprefixed attribute name, i.e. ref='foo:bar', and not
+ // be tripped up by dfdl:ref="fmt:fooey" which is a format reference.
+ refProp match {
+ case None => {
+ val eDecl = new LocalElementDecl(child, parent, position)
+ List(eDecl)
+ }
+ case Some(_) => List(new ElementRef(child, parent, position))
+ }
+ }
+ case <annotation>{ _* }</annotation> => Nil
+ case textNode: Text => Nil
+ case _ => ModelGroupFactory(child, parent, position, false)
+ }
+ childList
+ }
+}
/**
* Base class for all model groups, which are term containers.
+ *
+ * There are ultimately 4 concrete classes that implement this:
+ * Sequence, Choice, SequenceGroupRef, and ChoiceGroupRef
*/
-abstract class ModelGroup(xmlArg: Node, parentArg: SchemaComponent, position: Int)
- extends GroupBase(xmlArg, parentArg, position)
- with DFDLStatementMixin
+abstract class ModelGroup
+ extends Term
with ModelGroupGrammarMixin
with OverlapCheckMixin
- with RealTermMixin
with NestingLexicalMixin {
requiredEvaluations(groupMembers)
+ def groupMembers: Seq[Term]
+ def xmlChildren: Seq[Node]
+ protected def myPeers: Option[Seq[ModelGroup]]
+
+ final override def isScalar = true
+ final override def isOptional = false
+ final override def isRequired = true
+ final override def isArray = false
+
+ private def prettyIndex = LV('prettyIndex) {
+ myPeers.map { peers =>
+ {
+ if (peers.length == 1) "" // no index expression if we are the only one
+ else "[" + (peers.indexOf(this) + 1) + "]" // 1-based indexing in XML/XSD
+ }
+ }.getOrElse("")
+ }.value
+
+ override lazy val diagnosticDebugName = prettyBaseName + prettyIndex
+
+ /**
+ * This is only the immediately enclosing model group. It doesn't walk outward.
+ */
+ final lazy val enclosingComponentModelGroup = enclosingComponent.collect { case mg: ModelGroup => mg }
+ final lazy val sequencePeers = enclosingComponentModelGroup.map { _.sequenceChildren }
+ final lazy val choicePeers = enclosingComponentModelGroup.map { _.choiceChildren }
+
+ override lazy val alignmentValueInBits: JInt = {
+ this.alignment match {
+ case AlignmentType.Implicit => 1
+ case align: JInt => this.alignmentUnits match {
+ case AlignmentUnits.Bits => align
+ case AlignmentUnits.Bytes => 8 * align
+ }
+ }
+ }
+
final lazy val elementChildren: Seq[ElementBase] =
groupMembers.flatMap {
case eb: ElementBase => Seq(eb)
- case gb: GroupBase => gb.group.elementChildren
+ case gb: ModelGroup => gb.elementChildren
}
final override lazy val runtimeData: RuntimeData = modelGroupRuntimeData
@@ -115,118 +208,25 @@ abstract class ModelGroup(xmlArg: Node, parentArg: SchemaComponent, position: In
def modelGroupRuntimeData: ModelGroupRuntimeData
- final lazy val gRefNonDefault: Option[ChainPropProvider] = groupRef.map { _.nonDefaultFormatChain }
- final lazy val gRefDefault: Option[ChainPropProvider] = groupRef.map { _.defaultFormatChain }
-
- final def nonDefaultPropertySources = LV('nonDefaultPropertySources) {
- val seq = (gRefNonDefault.toSeq ++ Seq(this.nonDefaultFormatChain)).distinct
- checkNonOverlap(seq)
- seq
- }.value
-
- final def defaultPropertySources = LV('defaultPropertySources) {
- val seq = (gRefDefault.toSeq ++ Seq(this.defaultFormatChain)).distinct
- seq
- }.value
-
- protected final lazy val prettyBaseName = xmlArg.label
+ protected final lazy val prettyBaseName = xml.label
- protected def xmlChildren: Seq[Node]
-
- private def goodXmlChildren = LV('goodXMLChildren) { xmlChildren.flatMap { removeNonInteresting(_) } }.value
- private lazy val positions = List.range(1, goodXmlChildren.length + 1) // range is exclusive on 2nd arg. So +1.
- private lazy val pairs = goodXmlChildren zip positions
-
- final lazy val sequenceChildren = groupMembers.collect { case s: Sequence => s }
- final lazy val choiceChildren = groupMembers.collect { case s: Choice => s }
+ final lazy val sequenceChildren = groupMembers.collect { case s: SequenceTermBase => s }
+ final lazy val choiceChildren = groupMembers.collect { case s: ChoiceTermBase => s }
final lazy val groupRefChildren = groupMembers.collect { case s: GroupRef => s }
- final def group = this
-
- final lazy val groupMembers = {
- pairs.flatMap {
- case (n, i) =>
- termFactory(n, this, i)
- }
- }
-
final override lazy val termChildren = groupMembers
- final lazy val groupMembersNoRefs = groupMembers.map {
- case eRef: ElementRef => eRef.referencedElement
- case gb: GroupBase => gb.group
- case x => x
- }
-
- /**
- * Factory for Terms
- *
- * Because of the context where this is used, this returns a list. Nil for non-terms, non-Nil for
- * an actual term. There should be only one non-Nil.
- *
- * This could be static code in an object. It doesn't reference any of the state of the ModelGroup,
- * it's here so that type-specific overrides are possible in Sequence or Choice
- */
- private def termFactory(child: Node, parent: ModelGroup, position: Int) = {
- val childList: List[Term] = child match {
- case <element>{ _* }</element> => {
- val refProp = child.attribute("ref").map { _.text }
- // must get an unprefixed attribute name, i.e. ref='foo:bar', and not
- // be tripped up by dfdl:ref="fmt:fooey" which is a format reference.
- refProp match {
- case None => List(schemaSet.LocalElementDeclFactory(child, schemaDocument).forModelGroup(parent, position))
- case Some(_) => List(new ElementRef(child, parent, position))
- }
- }
- case <annotation>{ _* }</annotation> => Nil
- case textNode: Text => Nil
- case _ => ModelGroupFactory(child, parent, position)
- }
- childList
- }
-
/**
- * XML is full of uninteresting text nodes. We just want the element children, not all children.
+ * Returns tuple, where the first is children that could be last, and the
+ * second is a boolean if all children could be optional, and thus this could
+ * be last
*/
- private def removeNonInteresting(child: Node) = {
- val childList: List[Node] = child match {
- case _: Text => Nil
- case _: Comment => Nil
- case <annotation>{ _* }</annotation> => Nil
- case _ => List(child)
- }
- childList
- }
-
- /**
- * Combine our statements with those of the group ref that is referencing us (if there is one)
- */
- final lazy val statements: Seq[DFDLStatement] = localStatements ++ groupRef.map { _.statements }.getOrElse(Nil)
- final lazy val newVariableInstanceStatements: Seq[DFDLNewVariableInstance] =
- localNewVariableInstanceStatements ++ groupRef.map { _.newVariableInstanceStatements }.getOrElse(Nil)
- final lazy val (discriminatorStatements, assertStatements) = checkDiscriminatorsAssertsDisjoint(combinedDiscrims, combinedAsserts)
- private lazy val combinedAsserts: Seq[DFDLAssert] = localAssertStatements ++ groupRef.map { _.assertStatements }.getOrElse(Nil)
- private lazy val combinedDiscrims: Seq[DFDLDiscriminator] = localDiscriminatorStatements ++ groupRef.map { _.discriminatorStatements }.getOrElse(Nil)
-
- final lazy val setVariableStatements: Seq[DFDLSetVariable] = {
- val combinedSvs = localSetVariableStatements ++ groupRef.map { _.setVariableStatements }.getOrElse(Nil)
- checkDistinctVariableNames(combinedSvs)
- }
-
- final lazy val groupRef = parent match {
- case ggd: GlobalGroupDef => Some(ggd.groupRef)
- case _ => None
- }
-
- // returns tuple, where the first is children that could be last, and the
- // second is a boolean if all children could be optional, and thus this could
- // be last
lazy val potentialLastChildren: (Seq[Term], Boolean) = {
val (potentialLast, allOptional) = this match {
- case ch: Choice => (ch.groupMembersNoRefs, false)
- case sq: Sequence if !sq.isOrdered => (sq.groupMembersNoRefs, true) // TBD: is true correct? Are all children optional in unordered sequence?
- case sq: Sequence => {
- val maybeLast = sq.groupMembersNoRefs.lastOption
+ case ch: ChoiceTermBase => (ch.groupMembers, false)
+ case sq: SequenceTermBase if !sq.isOrdered => (sq.groupMembers, true) // TBD: is true correct? Are all children optional in unordered sequence?
+ case sq: SequenceTermBase => {
+ val maybeLast = sq.groupMembers.lastOption
if (maybeLast.isDefined) {
val last = maybeLast.get
val lastIsOptional = last match {
@@ -255,10 +255,10 @@ abstract class ModelGroup(xmlArg: Node, parentArg: SchemaComponent, position: In
final def allSelfContainedTermsTerminatedByRequiredElement: Seq[Term] =
LV('allSelfContainedTermsTerminatedByRequiredElement) {
- val listOfTerms = groupMembersNoRefs.map(m => {
+ val listOfTerms = groupMembers.map(m => {
m match {
- case e: LocalElementBase if e.isOptional => (Seq(e) ++ e.possibleNextTerms) // A LocalElement or ElementRef
- case e: LocalElementBase => Seq(e)
+ case e: ElementBase if e.isOptional => (Seq(e) ++ e.possibleNextTerms) // A LocalElement or ElementRef
+ case e: ElementBase => Seq(e)
case mg: ModelGroup => Seq(mg)
}
}).flatten
@@ -266,7 +266,7 @@ abstract class ModelGroup(xmlArg: Node, parentArg: SchemaComponent, position: In
}.value
final def identifyingEventsForChoiceBranch: Seq[ChoiceBranchEvent] = LV('identifyingEventsForChoiceBranch) {
- Assert.usage(enclosingTerm.isDefined && enclosingTerm.get.isInstanceOf[Choice], "identifyingElementsForChoiceBranch must only be called on children of choices")
+ Assert.usage(enclosingTerm.isDefined && enclosingTerm.get.isInstanceOf[ChoiceTermBase], "identifyingElementsForChoiceBranch must only be called on children of choices")
val childrenIdentifiers = possibleFirstChildElementsInInfoset
val parentNextIdentifiers =
@@ -314,10 +314,10 @@ abstract class ModelGroup(xmlArg: Node, parentArg: SchemaComponent, position: In
*/
protected final def possibleFirstChildTerms: Seq[Term] = LV('possibleFirstChildTerms) {
val firstTerms = this match {
- case c: Choice => groupMembersNoRefs
- case s: Sequence if !s.isOrdered => groupMembersNoRefs
- case s: Sequence => {
- groupMembersNoRefs.headOption match {
+ case c: ChoiceTermBase => groupMembers
+ case s: SequenceTermBase if !s.isOrdered => groupMembers
+ case s: SequenceTermBase => {
+ groupMembers.headOption match {
case None => Nil
case Some(e: ElementBase) if e.canBeAbsentFromUnparseInfoset => {
// this case covers optional elements, arrrays with minOccurs = 0,
@@ -326,7 +326,7 @@ abstract class ModelGroup(xmlArg: Node, parentArg: SchemaComponent, position: In
// follow it
Seq(e) ++ e.possibleNextSiblingTerms
}
- case Some(s: Sequence) if s.hiddenGroupRefOption.isDefined => s.possibleNextSiblingTerms
+ case Some(s: SequenceTermBase) if s.isHidden => s.possibleNextSiblingTerms
case Some(mg: ModelGroup) if !mg.mustHaveRequiredElement => Seq(mg) ++ mg.possibleNextSiblingTerms
case Some(e: ElementBase) => Seq(e)
case Some(mg: ModelGroup) => Seq(mg)
@@ -351,7 +351,7 @@ abstract class ModelGroup(xmlArg: Node, parentArg: SchemaComponent, position: In
}
}
- // model groups can't be elements.
+ /** Always false as model groups can't be elements.*/
protected final def couldBeLastElementInModelGroup: Boolean = false
/*
@@ -362,7 +362,7 @@ abstract class ModelGroup(xmlArg: Node, parentArg: SchemaComponent, position: In
private def hasRequiredNextSiblingElement: Boolean = LV('hasRequiredNextSiblingElement) {
val hasRequired = enclosingTerm match {
case None => false
- case Some(s: Sequence) if s.isOrdered => {
+ case Some(s: SequenceTermBase) if s.isOrdered => {
// possibleNextSiblingTerms is either all optional/does not have a
// required element, or the last one is required. Thus, this has a
// required next sibling if the last sibling element is required
@@ -386,14 +386,14 @@ abstract class ModelGroup(xmlArg: Node, parentArg: SchemaComponent, position: In
*/
final def mustHaveRequiredElement: Boolean = LV('mustHaveRequiredElement) {
this match {
- case s: Sequence if s.hiddenGroupRefOption.isDefined => false
- case s: Sequence if s.isOrdered =>
- groupMembersNoRefs.exists {
+ case s: SequenceTermBase if s.isHidden => false
+ case s: SequenceTermBase if s.isOrdered =>
+ groupMembers.exists {
case e: ElementBase => !e.canBeAbsentFromUnparseInfoset
case mg: ModelGroup => mg.mustHaveRequiredElement
}
case _ =>
- groupMembersNoRefs.forall {
+ groupMembers.forall {
case e: ElementBase => !e.canBeAbsentFromUnparseInfoset
case mg: ModelGroup => mg.mustHaveRequiredElement
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/Nesting.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/Nesting.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/Nesting.scala
index 1536645..4ad0633 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/Nesting.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/Nesting.scala
@@ -40,12 +40,12 @@ trait NestingMixin {
def parent: SchemaComponent
/**
- * Define this for schema components that have back-references to ref
+ * Define this for schema components that have back-references to ref
* objects.
* So group def to group ref, globalelementdecl to element ref,
* type to element, base type to derived type.
- *
- * Not for format annotations however. We don't backpoint those to
+ *
+ * Not for format annotations however. We don't backpoint those to
* other format annotations that ref them.
*/
protected def enclosingComponentDef: Option[SchemaComponent]
@@ -60,14 +60,7 @@ trait NestingMixin {
* referenced from a element ref or group ref, is NOT the ref object, but the
* component that contains the ref object
*/
- final lazy val enclosingComponent: Option[SchemaComponent] = {
- val optECD = enclosingComponentDef
- optECD match {
- case Some(eref: ElementRef) => eref.enclosingComponent
- case Some(gref: GroupRef) => gref.enclosingComponent
- case _ => optECD
- }
- }
+ final lazy val enclosingComponent: Option[SchemaComponent] = enclosingComponentDef
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ParticleMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ParticleMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ParticleMixin.scala
index 737d07d..066bc0e 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ParticleMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/ParticleMixin.scala
@@ -113,8 +113,8 @@ trait RequiredOptionalMixin { self: ElementBase =>
// A Particle is something that can be repeating.
trait ParticleMixin extends RequiredOptionalMixin { self: ElementBase =>
- final override lazy val optMinOccurs: Option[Int] = Some(minOccurs)
- final override lazy val optMaxOccurs: Option[Int] = Some(maxOccurs)
+ final lazy val optMinOccurs: Option[Int] = Some(minOccurs)
+ final lazy val optMaxOccurs: Option[Int] = Some(maxOccurs)
lazy val minOccurs = {
val min = (self.xml \ "@minOccurs").text.toString
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/PropProviders.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/PropProviders.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/PropProviders.scala
index 9d1da6c..f7a6642 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/PropProviders.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/PropProviders.scala
@@ -120,6 +120,8 @@ trait LeafPropProvider
final class ChainPropProvider(leafProvidersArg: Seq[LeafPropProvider], forAnnotation: String)
extends Logging with PropTypes {
+ override def toString() = Misc.getNameFromClass(this) + "(" + forAnnotation + ")"
+
/**
* for debug/test only
*/
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RealTermMixin.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RealTermMixin.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RealTermMixin.scala
index 4cfbbac..1f7e629 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RealTermMixin.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RealTermMixin.scala
@@ -32,7 +32,6 @@
package edu.illinois.ncsa.daffodil.dsom
-import edu.illinois.ncsa.daffodil.exceptions.Assert
import edu.illinois.ncsa.daffodil.schema.annotation.props.PropertyLookupResult
trait PropertyReferencedElementInfosMixin {
@@ -49,9 +48,6 @@ trait PropertyReferencedElementInfosMixin {
if (rawProp.isDefined) f(ev) else Set()
}
- final protected def creis(rei: ContentValueReferencedElementInfoMixin) = rei.contentReferencedElementInfos
- final protected def vreis(rei: ContentValueReferencedElementInfoMixin) = rei.valueReferencedElementInfos
-
protected def propertyContentReferencedElementInfos: Set[DPathElementCompileInfo]
protected def propertyValueReferencedElementInfos: Set[DPathElementCompileInfo]
@@ -69,226 +65,3 @@ trait PropertyReferencedElementInfosMixin {
}
-/**
- * A RealTerm is an element or a sequence or a choice. Group references
- * are excluded as they go away and really have no realization.
- *
- * Things that apply to real terms, but not group references, go in this trait.
- */
-trait RealTermMixin { self: Term =>
-
- final lazy val possibleNextTerms: Seq[Term] = LV('possibleNextTerms) {
- val es = this.nearestEnclosingSequence
- val eus = this.nearestEnclosingUnorderedSequenceBeforeSequence
- val ec = this.nearestEnclosingChoiceBeforeSequence
-
- val enclosingUnorderedGroup = {
- (ec, eus) match {
- case (None, None) => None
- case (Some(choice), _) => Some(choice)
- case (None, Some(uoSeq)) => Some(uoSeq)
- }
- }
- val listOfNextTerm = (enclosingUnorderedGroup, es) match {
- case (None, None) => Seq.empty
- case (Some(unorderedGroup), _) => {
- // We're in a choice or unordered sequence
- //
- // List must be all of our peers since (as well as our self)
- // we could be followed by any of them plus
- // whatever follows the unordered group.
- val peersCouldBeNext = unorderedGroup.groupMembersNoRefs
-
- // Note: There was a tiny difference here between the possibleNextTerms of LocalElementBase
- // and the possibleNextTerms of model group. This difference appears to be that this
- // version is more correct (from LocalElementBase).
- val termsUntilFirstRequiredTerm = peersCouldBeNext ++ unorderedGroup.possibleNextTerms
- termsUntilFirstRequiredTerm
- }
- case (None, Some(oSeq)) => {
- // We're in an ordered sequence
-
- val termsUntilFirstRequiredTerm =
- isDeclaredLastInSequence match {
- case true => oSeq.possibleNextTerms
- case false => {
-
- val members = oSeq.groupMembersNoRefs
-
- val nextMember =
- members.dropWhile(m => m != thisTermNoRefs).filterNot(m => m == thisTermNoRefs).headOption
-
- val nextMembers =
- nextMember match {
- case Some(e: LocalElementBase) if e.isOptional => Seq(e) ++ e.possibleNextTerms
- case Some(e: LocalElementBase) => Seq(e)
- case Some(gb: GroupBase) => Seq(gb.group)
- case None => Assert.impossibleCase // Difference: model group has Nil here.
- }
- nextMembers
- }
- }
- termsUntilFirstRequiredTerm
- }
- }
- listOfNextTerm
- }.value
-
- final def isDeclaredLastInSequence = LV('isDeclaredLastInSequence) {
- val es = nearestEnclosingSequence
- // how do we determine what child node we are? We search.
- // TODO: better structure for O(1) answer to this.
- es match {
- case None => Assert.invariantFailed("We are not in a sequence therefore isDeclaredLastInSequence is an invalid question.")
- case Some(s) => {
- val members = s.groupMembersNoRefs
- if (members.last eq thisTermNoRefs) true // we want object identity comparison here, not equality.
- else false
- }
- }
- }.value
-
- protected def possibleFirstChildTerms: Seq[Term]
-
- /*
- * Returns list of Elements that could be the first child in the infoset of this model group or element.
- */
- final def possibleFirstChildElementsInInfoset: Seq[ElementBase] = LV('possibleFirstChildElementsInInfoset) {
- val firstChildren = possibleFirstChildTerms.flatMap {
- case e: ElementBase if e.isHidden => Nil
- case e: ElementBase => Seq(e)
- case s: Sequence if s.isHidden || s.hiddenGroupRefOption.isDefined => Nil
- case mg: ModelGroup => mg.possibleFirstChildElementsInInfoset
- }
- firstChildren
- }.value
-
- /*
- * Returns a list of Elements that could follow this Term, including
- * siblings, children of siblings, and siblings of the parent and their children.
- *
- * What stops this is when the end of an enclosing element has to be next.
- */
- final def possibleNextChildElementsInInfoset: Seq[ElementBase] = LV('possibleNextChildElementsInInfoset) {
- val arrayNext = if (isArray) Seq(this.asInstanceOf[ElementBase]) else Nil
-
- val nextSiblingElements = {
- val poss = possibleNextSiblingTerms
- val res = poss.flatMap {
- possible =>
- possible match {
- case e: ElementBase => Seq(e)
- case mg: ModelGroup => mg.possibleFirstChildElementsInInfoset
- }
- }
- res
- }
-
- val nextParentElts = nextParentElements
- val res = arrayNext ++ nextSiblingElements ++ nextParentElts
- res
- }.value
-
- def nextParentElements: Seq[ElementBase]
-
- protected def couldBeLastElementInModelGroup: Boolean
-
- /*
- * Returns a list of sibling Terms that could follow this term. This will not
- * return any children of sibling Terms, or any siblings of the parent.
- */
- final def possibleNextSiblingTerms: Seq[Term] = LV('possibleNextSiblingTerms) {
- val listOfNextTerm = enclosingTerm match {
- case None => Nil // root element, has no siblings
- case Some(e: ElementBase) => Nil // complex element, cannot have another model group other than this one
- case Some(c: Choice) => Nil // in choice, no other siblings could come after this one
- case Some(s: Sequence) if !s.isOrdered => s.groupMembersNoRefs // unorderd sequence, all siblings (and myself) could be next
- case Some(s: Sequence) => {
- // in a sequence, the next term could be any later sibling that is not
- // or does not have a required element, up to and including the first
- // term that is/has a required element
- // def isOutputValueCalc(term: Term) =
- // term match { case eb: ElementBase if eb.isOutputValueCalc => true; case _ => false }
- val allNextSiblings = s.groupMembersNoRefs.dropWhile(_ != thisTermNoRefs).tail
- val nextSiblings = allNextSiblings // .dropWhile(isOutputValueCalc(_))
- val (optional, firstRequiredAndLater) = nextSiblings.span {
- case e: ElementBase => e.canBeAbsentFromUnparseInfoset
- case mg: ModelGroup => !mg.mustHaveRequiredElement
- }
- optional ++ firstRequiredAndLater.take(1)
- }
- }
- listOfNextTerm
- }.value
-
- /**
- * Set of elements referenced from an expression in the scope of this term.
- *
- * Specific to certain function call contexts e.g., only elements referenced
- * by dfdl:valueLength or dfdl:contentLength.
- *
- * Separated by parser/unparser since parsers have to derive from
- * dfdl:inputValueCalc, and must include discriminators and assert test
- * expressions. Unparsers must derive from dfdl:outputValueCalc and exclude
- * discriminators and asserts. Both must include setVariable/newVariableInstance,
- * and property expressions are nearly the same. There are some unparser-specfic
- * properties that take runtime-valued expressions - dfdl:outputNewLine is
- * one example.
- */
- final lazy val contentLengthParserReferencedElementInfos: Set[DPathElementCompileInfo] = {
- val propRefs = propertyContentReferencedElementInfos
- val stmtRefs = statementContentParserReferencedElementInfos
- val calcRefs = calcContentParserReferencedElementInfos
- val locRefs = propRefs ++ stmtRefs ++ calcRefs
- val res = realChildren.foldLeft(locRefs) { (s, i) => s.union(i.contentLengthParserReferencedElementInfos) }
- res
- }
-
- /**
- * Any element referenced from an expression in the scope of this term
- * is in this set.
- */
- final lazy val contentLengthUnparserReferencedElementInfos: Set[DPathElementCompileInfo] = {
- val propRefs = propertyContentReferencedElementInfos
- val stmtRefs = statementContentUnparserReferencedElementInfos
- val calcRefs = calcContentUnparserReferencedElementInfos
- val locRefs = propRefs ++ stmtRefs ++ calcRefs
- val res = realChildren.foldLeft(locRefs) { (s, i) => s.union(i.contentLengthUnparserReferencedElementInfos) }
- res
- }
-
- /**
- * Any element referenced from an expression in the scope of this term
- * is in this set.
- */
- final lazy val valueLengthParserReferencedElementInfos: Set[DPathElementCompileInfo] = {
- val propRefs = propertyValueReferencedElementInfos
- val stmtRefs = statementValueParserReferencedElementInfos
- val calcRefs = calcValueParserReferencedElementInfos
- val locRefs = propRefs ++ stmtRefs ++ calcRefs
- val res = realChildren.foldLeft(locRefs) { (s, i) => s.union(i.valueLengthParserReferencedElementInfos) }
- res
- }
-
- /**
- * Any element referenced from an expression in the scope of this term
- * is in this set.
- */
- final lazy val valueLengthUnparserReferencedElementInfos: Set[DPathElementCompileInfo] = {
- val propRefs = propertyValueReferencedElementInfos
- val stmtRefs = statementValueUnparserReferencedElementInfos
- val calcRefs = calcValueUnparserReferencedElementInfos
- val locRefs = propRefs ++ stmtRefs ++ calcRefs
- val res = realChildren.foldLeft(locRefs) { (s, i) => s.union(i.valueLengthUnparserReferencedElementInfos) }
- res
- }
-
- private lazy val realChildren: Seq[RealTermMixin] = {
- this match {
- case mg: ModelGroup => mg.groupMembersNoRefs.asInstanceOf[Seq[RealTermMixin]]
- case eb: ElementBase if (eb.isComplexType) => Seq(eb.complexType.group)
- case eb: ElementBase => Seq()
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RestrictionUnion.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RestrictionUnion.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RestrictionUnion.scala
index cdb69b9..85a6618 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RestrictionUnion.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RestrictionUnion.scala
@@ -49,7 +49,7 @@ import edu.illinois.ncsa.daffodil.dpath.NodeInfo.PrimType
* A schema component for simple type restrictions
*/
final class Restriction(xmlArg: Node, val simpleType: SimpleTypeDefBase)
- extends SchemaComponent(xmlArg, simpleType.schemaDocument)
+ extends SchemaComponentImpl(xmlArg, simpleType.schemaDocument)
with NestingLexicalMixin
with Facets
with TypeChecks {
@@ -187,7 +187,7 @@ final class Restriction(xmlArg: Node, val simpleType: SimpleTypeDefBase)
* A schema component for simple type unions
*/
final class Union(xmlArg: Node, simpleType: SimpleTypeDefBase)
- extends SchemaComponent(xmlArg, simpleType.schemaDocument)
+ extends SchemaComponentImpl(xmlArg, simpleType.schemaDocument)
with NestingLexicalMixin {
Assert.invariant(xmlArg.asInstanceOf[scala.xml.Elem].label == "union")
@@ -213,7 +213,7 @@ final class Union(xmlArg: Node, simpleType: SimpleTypeDefBase)
private lazy val immediateTypeXMLs = xml \ "simpleType"
private lazy val immediateTypes = immediateTypeXMLs.map { node =>
{
- schemaSet.LocalSimpleTypeDefFactory(node, schemaDocument).forElement(simpleType.element)
+ new LocalSimpleTypeDef(node, simpleType.elementDecl)
}
}
@@ -226,7 +226,7 @@ final class Union(xmlArg: Node, simpleType: SimpleTypeDefBase)
}
private lazy val namedTypeQNames = namedTypeQNameStrings.map { qns => resolveQName(qns) }
private lazy val namedTypes = namedTypeQNames.map {
- qn => schemaSet.getGlobalSimpleTypeDef(qn).get.forElement(simpleType.element)
+ qn => schemaSet.getGlobalSimpleTypeDef(qn).get.forElement(simpleType.elementDecl)
}
private lazy val directMemberTypes: Seq[SimpleTypeDefBase] = namedTypes ++ immediateTypes
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/Root.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/Root.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/Root.scala
new file mode 100644
index 0000000..a385cb0
--- /dev/null
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/Root.scala
@@ -0,0 +1,31 @@
+package edu.illinois.ncsa.daffodil.dsom
+
+import edu.illinois.ncsa.daffodil.grammar.RootGrammarMixin
+import edu.illinois.ncsa.daffodil.xml.NamedQName
+import edu.illinois.ncsa.daffodil.xml.XMLUtils
+import scala.xml.Node
+import scala.xml.UnprefixedAttribute
+
+/**
+ * Root is a special kind of ElementRef that has no enclosing group.
+ *
+ * This is the entity that is compiled by the schema compiler.
+ */
+final class Root(defXML: Node, parentArg: SchemaDocument,
+ namedQNameArg: NamedQName,
+ globalElementDecl: => GlobalElementDecl)
+ extends AbstractElementRef(null, parentArg, 1)
+ with RootGrammarMixin {
+
+ final override lazy val xml = {
+ val elem = XMLUtils.getXSDElement(defXML.scope)
+ val res = elem % new UnprefixedAttribute("ref", refQName.toQNameString, scala.xml.Null)
+ res
+ }
+
+ override lazy val refQName = namedQNameArg.toRefQName
+
+ override lazy val referencedElement = globalElementDecl
+
+ lazy val rootParseUnparsePolicy = defaultParseUnparsePolicy
+}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RuntimePropertyMixins.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RuntimePropertyMixins.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RuntimePropertyMixins.scala
index 4b1a32b..a5104bd 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RuntimePropertyMixins.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/RuntimePropertyMixins.scala
@@ -184,7 +184,7 @@ trait DelimitedRuntimeValuedPropertiesMixin
with RawDelimitedRuntimeValuedPropertiesMixin { decl: Term =>
lazy val isLengthKindDelimited = {
- decl.referredToComponent match {
+ this match {
case mg: ModelGroup => mg.enclosingElement.get.lengthKind == LengthKind.Delimited
case eb: ElementBase => eb.lengthKind == LengthKind.Delimited
}
@@ -214,7 +214,8 @@ trait DelimitedRuntimeValuedPropertiesMixin
val qn = this.qNameForProperty("terminator")
val typeIfStaticallyKnown = NodeInfo.String
val typeIfRuntimeKnown = NodeInfo.NonEmptyString
- ExpressionCompilers.String.compile(qn, typeIfStaticallyKnown, typeIfRuntimeKnown, terminatorRaw)
+ val raw = terminatorRaw
+ ExpressionCompilers.String.compile(qn, typeIfStaticallyKnown, typeIfRuntimeKnown, raw)
}.value
final def terminatorLoc = (this.diagnosticDebugName, this.path)
@@ -525,7 +526,7 @@ trait ElementRuntimeValuedPropertiesMixin
trait SequenceRuntimeValuedPropertiesMixin
extends DelimitedRuntimeValuedPropertiesMixin
with Sequence_AnnotationMixin
- with RawSequenceRuntimeValuedPropertiesMixin { decl: GroupBase =>
+ with RawSequenceRuntimeValuedPropertiesMixin { decl: SequenceTermBase =>
private lazy val separatorExpr = {
val qn = this.qNameForProperty("separator")
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaComponent.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaComponent.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaComponent.scala
index cad3119..663b604 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaComponent.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaComponent.scala
@@ -33,7 +33,6 @@
package edu.illinois.ncsa.daffodil.dsom
import scala.xml.Node
-import edu.illinois.ncsa.daffodil.ExecutionMode
import edu.illinois.ncsa.daffodil.exceptions.Assert
import edu.illinois.ncsa.daffodil.xml.GetAttributesMixin
import edu.illinois.ncsa.daffodil.xml.NS
@@ -45,36 +44,36 @@ import edu.illinois.ncsa.daffodil.processors.VariableMap
import edu.illinois.ncsa.daffodil.processors.NonTermRuntimeData
import edu.illinois.ncsa.daffodil.xml.ResolvesQNames
import edu.illinois.ncsa.daffodil.schema.annotation.props.LookupLocation
-import edu.illinois.ncsa.daffodil.schema.annotation.props.PropertyLookupResult
-import edu.illinois.ncsa.daffodil.schema.annotation.props.FindPropertyMixin
import edu.illinois.ncsa.daffodil.schema.annotation.props.PropTypes
-import edu.illinois.ncsa.daffodil.schema.annotation.props.NotFound
-import edu.illinois.ncsa.daffodil.oolag.OOLAG.OOLAGHost
+import edu.illinois.ncsa.daffodil.oolag.OOLAG._
import edu.illinois.ncsa.daffodil.api.DaffodilTunables
-import edu.illinois.ncsa.daffodil.schema.annotation.props.PropertyLookupResult
-import edu.illinois.ncsa.daffodil.schema.annotation.props.FindPropertyMixin
import edu.illinois.ncsa.daffodil.xml.GetAttributesMixin
import edu.illinois.ncsa.daffodil.schema.annotation.props.PropTypes
+abstract class SchemaComponentImpl( final override val xml: Node,
+ final override val parent: SchemaComponent)
+ extends SchemaComponent
+
/**
* The core root class of the DFDL Schema object model.
*
* Every schema component has a schema document, and a schema, and a namespace.
*/
-abstract class SchemaComponent(xmlArg: Node, val parent: SchemaComponent)
- extends OOLAGHost(parent)
+trait SchemaComponent
+ extends OOLAGHost
with ImplementsThrowsOrSavesSDE
with GetAttributesMixin
with SchemaComponentIncludesAndImportsMixin
with ResolvesQNames
- with FindPropertyMixin
with SchemaFileLocatableImpl
with PropTypes {
-
- def tunable: DaffodilTunables = parent.tunable
- val xml = xmlArg
- val aaa_xml = xml // for debugging, so we don't have to scroll down.
+ def xml: Node
+ def parent: SchemaComponent
+
+ final override def oolagContextViaArgs = Some(parent)
+
+ def tunable: DaffodilTunables = parent.tunable
lazy val dpathCompileInfo: DPathCompileInfo =
new DPathCompileInfo(
@@ -116,28 +115,21 @@ abstract class SchemaComponent(xmlArg: Node, val parent: SchemaComponent)
schemaSet.variableMap
}.value
- /*
- * Anything non-annotated always returns property not found
+ /**
+ * Whether the component is hidden.
*
- * Override in annotated components
+ * Override this in the components that can hide - SequenceGroupRef
+ * and ChoiceGroupRef
*/
- def findPropertyOption(pname: String): PropertyLookupResult = {
- ExecutionMode.requireCompilerMode
- NotFound(Nil, Nil, pname)
- }
- // Q: not sure why non-annotated schema components need to have findProperty
- // on them at all. Who would call it polymorphically, not knowing whether they
- // have an annotated schema component or not?
- // A: DFDLAnnotation - the annotation objects themselves - aren't annotated
- // schema components - they have a relationship to an annotated schema component
- // but clearly they carry properties.
-
- def isHidden: Boolean = LV('isHidden) {
- enclosingComponent match {
- case None => Assert.invariantFailed("Root global element should be overriding this.")
+ def isHidden: Boolean = isHiddenLV
+
+ private lazy val isHiddenLV = {
+ val optEC = enclosingComponent
+ optEC match {
+ case None => false
case Some(ec) => ec.isHidden
}
- }.value
+ }
lazy val schemaComponent: LookupLocation = this
@@ -149,19 +141,23 @@ abstract class SchemaComponent(xmlArg: Node, val parent: SchemaComponent)
val ee = et match {
case None => None
case Some(eb: ElementBase) => Some(eb)
- case Some(sc: SchemaComponent) => sc.enclosingElement
+ case Some(sc: SchemaComponent) => {
+ val scee = sc.enclosingElement
+ scee
+ }
}
ee
}.value
- final lazy val rootElement: Option[GlobalElementDecl] = {
+ final lazy val rootElementRef = rootElementDecl.map { _.elementRef }
+
+ final lazy val rootElementDecl: Option[GlobalElementDecl] = {
enclosingElement match {
- case Some(e) => e.rootElement
- case None => {
- if (this.isInstanceOf[GlobalElementDecl])
- Some(this.asInstanceOf[GlobalElementDecl])
- else
- None
+ case Some(e) => e.rootElementDecl
+ case None => this match {
+ case ged: GlobalElementDecl => Some(ged)
+ case root: Root => root.optReferredToComponent
+ case _ => Assert.invariantFailed("No global element decl")
}
}
}
@@ -254,7 +250,7 @@ abstract class SchemaComponent(xmlArg: Node, val parent: SchemaComponent)
* the 'schema'.
*/
final class Schema(val namespace: NS, schemaDocs: Seq[SchemaDocument], schemaSetArg: SchemaSet)
- extends SchemaComponent(<fake/>, schemaSetArg) {
+ extends SchemaComponentImpl(<fake/>, schemaSetArg) {
requiredEvaluations(schemaDocuments)
@@ -278,7 +274,6 @@ final class Schema(val namespace: NS, schemaDocs: Seq[SchemaDocument], schemaSet
thing match {
case df: DFDLDefiningAnnotation => df.asAnnotation.locationDescription
case sc: SchemaComponent => sc.locationDescription
- case sf: SchemaComponentFactory => sf.locationDescription
case _ => Assert.impossibleCase(thing)
}
}.mkString("\n"))
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaComponentFactory.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaComponentFactory.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaComponentFactory.scala
index 5d36925..343a514 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaComponentFactory.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaComponentFactory.scala
@@ -1,7 +1,7 @@
/* Copyright (c) 2017 Tresys Technology, LLC. All rights reserved.
*
* Developed by: Tresys Technology, LLC
- * http://www.tresys.com
+ * http://www.troverride val esys.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal with
@@ -33,29 +33,33 @@
package edu.illinois.ncsa.daffodil.dsom
import edu.illinois.ncsa.daffodil.exceptions.SchemaFileLocatable
-import edu.illinois.ncsa.daffodil.xml.GetAttributesMixin
import edu.illinois.ncsa.daffodil.xml.XMLUtils
import edu.illinois.ncsa.daffodil.exceptions.ThrowsSDE
import scala.xml.NamespaceBinding
import edu.illinois.ncsa.daffodil.xml.NS
import edu.illinois.ncsa.daffodil.oolag.OOLAG.OOLAGHost
+import scala.xml.Node
/**
* Anything that can be computed without reference to the point of use
* or point of reference can be computed here on these factory objects.
*/
-class SchemaComponentFactory(override val xml: scala.xml.Node,
- override val schemaDocument: SchemaDocument)
- extends OOLAGHost(schemaDocument)
- with SchemaFileLocatableImpl
- with CommonContextMixin
- with GetAttributesMixin
- with ImplementsThrowsSDE
+abstract class SchemaComponentFactory( final override val xml: Node,
+ final override val schemaDocument: SchemaDocument)
+ extends SchemaComponent
with NestingLexicalMixin {
- override def parent = schemaDocument
-
- final override def tunable = schemaDocument.tunable
+ final override def parent = schemaDocument
+
+}
+
+abstract class AnnotatedSchemaComponentFactory( final override val xml: Node,
+ final override val schemaDocument: SchemaDocument)
+ extends AnnotatedSchemaComponent
+ with NestingLexicalMixin {
+
+ final override def parent = schemaDocument
+
}
trait SchemaFileLocatableImpl
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaDocument.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaDocument.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaDocument.scala
index b14e4c8..317a7cf 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaDocument.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaDocument.scala
@@ -89,7 +89,7 @@ final class XMLSchemaDocument(xmlArg: Node,
* even though it does not have a namespace
*/
override val isBootStrapSD: Boolean)
- extends SchemaComponent(xmlArg, sfArg.getOrElse(schemaSetArg))
+ extends SchemaComponentImpl(xmlArg, sfArg.getOrElse(schemaSetArg))
with SchemaDocumentMixin
with SchemaDocIncludesAndImportsMixin {
@@ -147,12 +147,18 @@ final class XMLSchemaDocument(xmlArg: Node,
* I.e., default format properties, named format properties, etc.
*/
final class SchemaDocument(xmlSDoc: XMLSchemaDocument)
- extends AnnotatedSchemaComponent(xmlSDoc.xml, xmlSDoc)
+ extends AnnotatedSchemaComponent
with SchemaDocumentMixin
+ with ResolvesProperties
with Format_AnnotationMixin
with SeparatorSuppressionPolicyMixin {
- override def term = Assert.usageError("not to be called on SchemaDocument")
+ final override val xml = xmlSDoc.xml
+ final override def parent = xmlSDoc
+
+ override lazy val optReferredToComponent = None
+
+ // override def term = Assert.usageError("not to be called on SchemaDocument")
/**
* Implements the selectivity so that if you specify a root element
@@ -196,12 +202,12 @@ final class SchemaDocument(xmlSDoc: XMLSchemaDocument)
// val dfdlAttrs = attrs.filter{ a => a.isPrefixed && a.}
// }
- def nonDefaultPropertySources = Seq()
-
- def defaultPropertySources = LV('defaultPropertySources) {
- val seq = Seq(this.defaultFormatChain)
- seq
- }.value
+ // def nonDefaultPropertySources = Seq()
+ //
+ // def defaultPropertySources = LV('defaultPropertySources) {
+ // val seq = Seq(this.defaultFormatChain)
+ // seq
+ // }.value
protected def annotationFactory(node: Node): Option[DFDLAnnotation] = {
val res = node match {
@@ -251,7 +257,7 @@ final class SchemaDocument(xmlSDoc: XMLSchemaDocument)
*/
lazy val globalElementDecls = {
val xmlelts = (xml \ "element")
- val factories = xmlelts.map { new edu.illinois.ncsa.daffodil.dsom.GlobalElementDeclFactory(_, this) }
+ val factories = xmlelts.map { new GlobalElementDeclFactory(_, this) }
factories
}
lazy val globalSimpleTypeDefs = (xml \ "simpleType").map { new GlobalSimpleTypeDefFactory(_, this) }
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaSet.scala
----------------------------------------------------------------------
diff --git a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaSet.scala b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaSet.scala
index aa7d1cd..23583b4 100644
--- a/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaSet.scala
+++ b/daffodil-core/src/main/scala/edu/illinois/ncsa/daffodil/dsom/SchemaSet.scala
@@ -51,7 +51,6 @@ import edu.illinois.ncsa.daffodil.api.DaffodilSchemaSource
import edu.illinois.ncsa.daffodil.api.UnitTestSchemaSource
import edu.illinois.ncsa.daffodil.util.Misc
import edu.illinois.ncsa.daffodil.schema.annotation.props.LookupLocation
-import edu.illinois.ncsa.daffodil.util.Memoize1
import edu.illinois.ncsa.daffodil.api.DaffodilTunables
/**
@@ -83,7 +82,7 @@ final class SchemaSet(
checkAllTopLevelArg: Boolean,
parent: SchemaComponent,
override val tunable: DaffodilTunables)
- extends SchemaComponent(<schemaSet/>, parent) // a fake schema component
+ extends SchemaComponentImpl(<schemaSet/>, parent) // a fake schema component
with SchemaSetIncludesAndImportsMixin {
requiredEvaluations(isValid)
@@ -333,7 +332,7 @@ final class SchemaSet(
* grabs the first element declaration of the first schema file
* to use as the root.
*/
- def rootElement(rootSpecFromProcessorFactory: Option[RootSpec]): GlobalElementDecl = {
+ def rootElement(rootSpecFromProcessorFactory: Option[RootSpec]): Root = {
val rootSpecFromCompiler = rootSpec
val re =
(rootSpecFromCompiler, rootSpecFromProcessorFactory) match {
@@ -352,8 +351,8 @@ final class SchemaSet(
val gdeclf = firstSchemaDocument.globalElementDecls
val firstElement = {
schemaDefinitionUnless(gdeclf.length >= 1, "No global elements in: " + firstSchemaDocument.uriString)
- val rootElement = gdeclf(0).forRoot()
- rootElement
+ val root = gdeclf(0).forRoot()
+ root
}
firstElement
}
@@ -531,26 +530,6 @@ final class SchemaSet(
finalVMap
}.value
-
- object LocalSimpleTypeDefFactory {
-
- private val f =
- Memoize1((n: Node) =>
- Memoize1((sd: SchemaDocument) =>
- new LocalSimpleTypeDefFactory(n, sd)))
-
- def apply(xml: Node, sd: SchemaDocument) = f(xml)(sd)
- }
-
- object LocalElementDeclFactory {
-
- private val f =
- Memoize1((xml: Node) =>
- Memoize1((sd: SchemaDocument) =>
- new LocalElementDeclFactory(xml, sd)))
-
- def apply(xml: Node, sd: SchemaDocument) = f(xml)(sd)
- }
}
class ValidateSchemasErrorHandler(sset: SchemaSet) extends org.xml.sax.ErrorHandler {
[2/6] incubator-daffodil git commit: Property Resolution - part of
fixing schema compilation
Posted by mb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-japi/src/test/java/edu/illinois/ncsa/daffodil/example/TestJavaAPI.java
----------------------------------------------------------------------
diff --git a/daffodil-japi/src/test/java/edu/illinois/ncsa/daffodil/example/TestJavaAPI.java b/daffodil-japi/src/test/java/edu/illinois/ncsa/daffodil/example/TestJavaAPI.java
index 69d452f..63fb7d7 100644
--- a/daffodil-japi/src/test/java/edu/illinois/ncsa/daffodil/example/TestJavaAPI.java
+++ b/daffodil-japi/src/test/java/edu/illinois/ncsa/daffodil/example/TestJavaAPI.java
@@ -58,803 +58,806 @@ import edu.illinois.ncsa.daffodil.japi.ParseResult;
import edu.illinois.ncsa.daffodil.japi.ProcessorFactory;
import edu.illinois.ncsa.daffodil.japi.UnparseResult;
import edu.illinois.ncsa.daffodil.japi.ValidationMode;
+import edu.illinois.ncsa.daffodil.japi.infoset.JDOMInfosetInputter;
+import edu.illinois.ncsa.daffodil.japi.infoset.JDOMInfosetOutputter;
import edu.illinois.ncsa.daffodil.japi.logger.ConsoleLogWriter;
import edu.illinois.ncsa.daffodil.japi.logger.LogLevel;
-import edu.illinois.ncsa.daffodil.japi.infoset.JDOMInfosetOutputter;
-import edu.illinois.ncsa.daffodil.japi.infoset.JDOMInfosetInputter;
public class TestJavaAPI {
- public java.io.File getResource(String resPath) {
- try {
- return new java.io.File(this.getClass().getResource(resPath).toURI());
- } catch (Exception e) {
- return null;
- }
- }
-
- @Test
- public void testJavaAPI1() throws IOException {
- LogWriterForJAPITest lw = new LogWriterForJAPITest();
- DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
-
- Daffodil.setLogWriter(lw);
- Daffodil.setLoggingLevel(LogLevel.Debug);
-
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
- ProcessorFactory pf = c.compileFile(schemaFile);
- DataProcessor dp = pf.onPath("/");
- dp.setDebugger(debugger);
- dp.setDebugging(true);
- java.io.File file = getResource("/test/japi/myData.dat");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter, 2 << 3);
- boolean err = res.isError();
- assertFalse(err);
- assertTrue(res.location().isAtEnd());
- assertEquals(0, lw.errors.size());
- assertEquals(0, lw.warnings.size());
- assertTrue(lw.others.size() > 0);
- assertTrue(debugger.lines.size() > 0);
- assertTrue(debugger.lines.contains("----------------------------------------------------------------- 1\n"));
- assertTrue(debugger.getCommand().equals("trace"));
-
- java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
- java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
- JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
- UnparseResult res2 = dp.unparse(inputter, wbc);
- err = res2.isError();
- assertFalse(err);
- assertEquals("42", bos.toString());
-
- // reset the global logging and debugger state
- Daffodil.setLogWriter(new ConsoleLogWriter());
- Daffodil.setLoggingLevel(LogLevel.Info);
- }
-
- // This is a duplicate of test testJavaAPI1 that serializes the parser
- // before executing the test.
- @Test
- public void testJavaAPI1_A() throws Exception {
- LogWriterForJAPITest lw = new LogWriterForJAPITest();
- DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
-
- Daffodil.setLogWriter(lw);
- Daffodil.setLoggingLevel(LogLevel.Debug);
-
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
- ProcessorFactory pf = c.compileFile(schemaFile);
- DataProcessor dp = pf.onPath("/");
-
- // Serialize the parser to memory, then deserialize for parsing.
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- WritableByteChannel output = Channels.newChannel(os);
- dp.save(output);
-
- ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
- ReadableByteChannel input = Channels.newChannel(is);
- edu.illinois.ncsa.daffodil.japi.Compiler compiler = Daffodil.compiler();
- DataProcessor parser = compiler.reload(input);
- parser.setDebugger(debugger);
- parser.setDebugging(true);
-
- java.io.File file = getResource("/test/japi/myData.dat");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = parser.parse(rbc, outputter, 2 << 3);
- boolean err = res.isError();
- assertFalse(err);
- assertTrue(res.location().isAtEnd());
- assertEquals(0, lw.errors.size());
- assertEquals(0, lw.warnings.size());
- assertTrue(lw.others.size() > 0);
- assertTrue(debugger.lines.size() > 0);
- assertTrue(debugger.lines.contains("----------------------------------------------------------------- 1\n"));
- assertTrue(debugger.getCommand().equals("trace"));
-
- java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
- java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
- JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
- UnparseResult res2 = dp.unparse(inputter, wbc);
- err = res2.isError();
- assertFalse(err);
- assertEquals("42", bos.toString());
-
- // reset the global logging and debugger state
- Daffodil.setLogWriter(new ConsoleLogWriter());
- Daffodil.setLoggingLevel(LogLevel.Info);
- }
-
- // This is a duplicate of test testJavaAPI1 that serializes the parser
- // before executing the test.
- @Test
- public void testJavaAPI1_A_FullFails() throws Exception {
- LogWriterForJAPITest lw = new LogWriterForJAPITest();
- DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
-
- Daffodil.setLogWriter(lw);
- Daffodil.setLoggingLevel(LogLevel.Debug);
-
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
- ProcessorFactory pf = c.compileFile(schemaFile);
- DataProcessor dp = pf.onPath("/");
- dp.setDebugger(debugger);
- dp.setDebugging(true);
-
- // Serialize the parser to memory, then deserialize for parsing.
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- WritableByteChannel output = Channels.newChannel(os);
- dp.save(output);
-
- ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
- ReadableByteChannel input = Channels.newChannel(is);
- edu.illinois.ncsa.daffodil.japi.Compiler compiler = Daffodil.compiler();
- DataProcessor parser = compiler.reload(input);
-
- try {
- parser.setValidationMode(ValidationMode.Full);
- fail();
- } catch (InvalidUsageException e) {
- assertEquals("'Full' validation not allowed when using a restored parser.", e.getMessage());
- }
-
- // reset the global logging and debugger state
- Daffodil.setLogWriter(new ConsoleLogWriter());
- Daffodil.setLoggingLevel(LogLevel.Info);
- }
-
- @Test
- public void testJavaAPI2() throws IOException {
- LogWriterForJAPITest lw = new LogWriterForJAPITest();
-
- Daffodil.setLogWriter(lw);
- Daffodil.setLoggingLevel(LogLevel.Info);
-
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
- ProcessorFactory pf = c.compileFile(schemaFile);
- DataProcessor dp = pf.onPath("/");
- java.io.File file = getResource("/test/japi/myDataBroken.dat");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter);
-
- // TODO: NEED a java friendly way to get the status of the outputter. Scala enums don't work well
- //assertTrue(outputter.getStatus() != Status.DONE); // This is a hack so that Java doesn't have to know about Nope/Maybe, need to figure out better api that is Java compatible
- assertTrue(res.isError());
- java.util.List<Diagnostic> diags = res.getDiagnostics();
- assertEquals(1, diags.size());
- Diagnostic d = diags.get(0);
- // System.err.println(d.getMessage());
- assertTrue(d.getMessage().contains("int"));
- assertTrue(d.getMessage().contains("Not an int"));
- assertTrue(d.getDataLocations().toString().contains("10"));
- java.util.List<LocationInSchemaFile> locs = d.getLocationsInSchemaFiles();
- assertEquals(1, locs.size());
- LocationInSchemaFile loc = locs.get(0);
- assertTrue(loc.toString().contains("mySchema2.dfdl.xsd"));
-
- assertEquals(0, lw.errors.size());
- assertEquals(0, lw.warnings.size());
- // assertTrue(lw.infos.size() > 0);
- assertEquals(0, lw.others.size());
-
- // reset the global logging state
- Daffodil.setLogWriter(new ConsoleLogWriter());
- Daffodil.setLoggingLevel(LogLevel.Info);
- }
-
- /**
- * Verify that we can detect when the parse did not consume all the data.
- *
- * @throws IOException
- */
- @Test
- public void testJavaAPI3() throws IOException {
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = getResource("/test/japi/mySchema3.dfdl.xsd");
- ProcessorFactory pf = c.compileFile(schemaFile);
- pf.setDistinguishedRootNode("e3", null);
- DataProcessor dp = pf.onPath("/");
- java.io.File file = getResource("/test/japi/myData16.dat");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter, 16 << 3);
- boolean err = res.isError();
- assertFalse(err);
- assertFalse(res.location().isAtEnd());
- assertEquals(2, res.location().bytePos1b());
- assertEquals(9, res.location().bitPos1b());
-
- java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
- java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
- JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
- UnparseResult res2 = dp.unparse(inputter, wbc);
- err = res2.isError();
- assertFalse(err);
- assertEquals("9", bos.toString());
- }
-
- // This is a duplicate of test testJavaAPI3 that serializes the parser
- // before executing the test.
- @Test
- public void testJavaAPI3_A() throws Exception {
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = getResource("/test/japi/mySchema3.dfdl.xsd");
- ProcessorFactory pf = c.compileFile(schemaFile);
- pf.setDistinguishedRootNode("e3", null);
- DataProcessor dp = pf.onPath("/");
-
- // Serialize the parser to memory, then deserialize for parsing.
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- WritableByteChannel output = Channels.newChannel(os);
- dp.save(output);
-
- ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
- ReadableByteChannel input = Channels.newChannel(is);
- edu.illinois.ncsa.daffodil.japi.Compiler compiler = Daffodil.compiler();
- DataProcessor parser = compiler.reload(input);
-
- java.io.File file = getResource("/test/japi/myData16.dat");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = parser.parse(rbc, outputter, 16 << 3);
- boolean err = res.isError();
- assertFalse(err);
- assertFalse(res.location().isAtEnd());
- assertEquals(2, res.location().bytePos1b());
- assertEquals(9, res.location().bitPos1b());
-
- java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
- java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
- JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
- UnparseResult res2 = dp.unparse(inputter, wbc);
- err = res2.isError();
- assertFalse(err);
- assertEquals("9", bos.toString());
- }
-
- @Test
- public void testJavaAPI4b() throws IOException {
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- File schemaFileName = getResource("/test/japi/mySchema3.dfdl.xsd");
- c.setDistinguishedRootNode("e4", null);
- ProcessorFactory pf = c.compileFile(schemaFileName);
- DataProcessor dp = pf.onPath("/");
- java.io.File file = getResource("/test/japi/myData2.dat");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter, 64 << 3);
- boolean err = res.isError();
- assertFalse(err);
- assertFalse(res.location().isAtEnd());
- assertEquals(5, res.location().bytePos1b());
- assertEquals(33, res.location().bitPos1b());
-
- java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
- java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
- JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
- UnparseResult res2 = dp.unparse(inputter, wbc);
- err = res2.isError();
- assertFalse(err);
- assertEquals("data", bos.toString());
- }
-
- @Test
- public void testJavaAPI5() throws IOException {
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- File schemaFileName = getResource("/test/japi/mySchema3.dfdl.xsd");
- c.setDistinguishedRootNode("e4", null); // e4 is a 4-byte long string
- // element
- ProcessorFactory pf = c.compileFile(schemaFileName);
- DataProcessor dp = pf.onPath("/");
- java.io.File file = getResource("/test/japi/myData3.dat"); // contains 5
- // bytes
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter, 4 << 3);
- boolean err = res.isError();
- assertFalse(err);
- assertTrue("Assertion failed: End of data not reached.", res.location().isAtEnd());
- assertEquals(5, res.location().bytePos1b());
- assertEquals(33, res.location().bitPos1b());
-
- java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
- java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
- JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
- UnparseResult res2 = dp.unparse(inputter, wbc);
- err = res2.isError();
- assertFalse(err);
- assertEquals("data", bos.toString());
- }
-
- /***
- * Verify that the compiler throws a FileNotFound exception when fed a list
- * of schema files that do not exist.
- *
- * @throws IOException
- */
- @Test
- public void testJavaAPI6() throws IOException {
- LogWriterForJAPITest lw = new LogWriterForJAPITest();
-
- Daffodil.setLogWriter(lw);
- Daffodil.setLoggingLevel(LogLevel.Debug);
-
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = new java.io.File("/test/japi/notHere1.dfdl.xsd");
- ProcessorFactory pf = c.compileFile(schemaFile);
- assertTrue(pf.isError());
- List<Diagnostic> diags = pf.getDiagnostics();
- boolean found1 = false;
- for (Diagnostic d : diags) {
- if (d.getMessage().contains("notHere1")) {
- found1 = true;
- }
- }
- assertTrue(found1);
-
- // reset the global logging state
- Daffodil.setLogWriter(new ConsoleLogWriter());
- Daffodil.setLoggingLevel(LogLevel.Info);
- }
-
- /**
- * Tests a user submitted case where the XML appears to be serializing odd
- * xml entities into the output.
- *
- * @throws IOException
- */
- @Test
- public void testJavaAPI7() throws IOException {
- // TODO: This is due to the fact that we are doing several conversions
- // back and forth between Scala.xml.Node and JDOM. And the conversions
- // both use XMLOutputter to format the result (which escapes the
- // entities).
- LogWriterForJAPITest lw = new LogWriterForJAPITest();
-
- Daffodil.setLogWriter(lw);
- Daffodil.setLoggingLevel(LogLevel.Debug);
-
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = getResource("/test/japi/TopLevel.xsd");
- c.setDistinguishedRootNode("TopLevel", null);
- ProcessorFactory pf = c.compileFile(schemaFile);
- DataProcessor dp = pf.onPath("/");
- java.io.File file = getResource("/test/japi/01very_simple.txt");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter);
- boolean err = res.isError();
- assertFalse(err);
- assertTrue(res.location().isAtEnd());
-
- java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
- java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
- JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
- UnparseResult res2 = dp.unparse(inputter, wbc);
- err = res2.isError();
- assertFalse(err);
- assertTrue(bos.toString().contains("Return-Path: <bo...@smith.com>"));
-
- // reset the global logging state
- Daffodil.setLogWriter(new ConsoleLogWriter());
- Daffodil.setLoggingLevel(LogLevel.Info);
- }
-
- /**
- * This test is nearly identical to testJavaAPI7. The only difference is
- * that this test uses double newline as a terminator for the first element
- * in the sequence rather than double newline as a separator for the
- * sequence
- *
- * @throws IOException
- */
- @Test
- public void testJavaAPI8() throws IOException {
- LogWriterForJAPITest lw = new LogWriterForJAPITest();
-
- Daffodil.setLogWriter(lw);
- Daffodil.setLoggingLevel(LogLevel.Debug);
-
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = getResource("/test/japi/TopLevel.xsd");
- c.setDistinguishedRootNode("TopLevel2", null);
- ProcessorFactory pf = c.compileFile(schemaFile);
- DataProcessor dp = pf.onPath("/");
- java.io.File file = getResource("/test/japi/01very_simple.txt");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter);
- boolean err = res.isError();
- assertFalse(err);
- assertTrue(res.location().isAtEnd());
-
- java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
- java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
- JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
- UnparseResult res2 = dp.unparse(inputter, wbc);
- err = res2.isError();
- assertFalse(err);
- assertTrue(bos.toString().contains("Return-Path: <bo...@smith.com>"));
-
-
- // reset the global logging state
- Daffodil.setLogWriter(new ConsoleLogWriter());
- Daffodil.setLoggingLevel(LogLevel.Info);
- }
-
- /**
- * Verify that calling result() on the ParseResult multiple times does not
- * error.
- */
- @Test
- public void testJavaAPI9() throws IOException {
- LogWriterForJAPITest lw = new LogWriterForJAPITest();
-
- Daffodil.setLogWriter(lw);
- Daffodil.setLoggingLevel(LogLevel.Debug);
-
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = getResource("/test/japi/TopLevel.xsd");
- c.setDistinguishedRootNode("TopLevel2", null);
- ProcessorFactory pf = c.compileFile(schemaFile);
- DataProcessor dp = pf.onPath("/");
- java.io.File file = getResource("/test/japi/01very_simple.txt");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter);
- boolean err = res.isError();
- assertFalse(err);
- assertTrue(res.location().isAtEnd());
-
- org.jdom2.Document doc1 = outputter.getResult();
-
- java.io.ByteArrayOutputStream bos1 = new java.io.ByteArrayOutputStream();
- java.nio.channels.WritableByteChannel wbc1 = java.nio.channels.Channels.newChannel(bos1);
- JDOMInfosetInputter inputter1 = new JDOMInfosetInputter(doc1);
- UnparseResult res2 = dp.unparse(inputter1, wbc1);
- err = res2.isError();
- assertFalse(err);
- assertTrue(bos1.toString().contains("Return-Path: <bo...@smith.com>"));
-
- org.jdom2.Document doc2 = outputter.getResult();
-
- java.io.ByteArrayOutputStream bos2 = new java.io.ByteArrayOutputStream();
- java.nio.channels.WritableByteChannel wbc2 = java.nio.channels.Channels.newChannel(bos2);
- JDOMInfosetInputter inputter2 = new JDOMInfosetInputter(doc2);
- UnparseResult res3 = dp.unparse(inputter2, wbc2);
- err = res3.isError();
- assertFalse(err);
- assertTrue(bos2.toString().contains("Return-Path: <bo...@smith.com>"));
-
- // reset the global logging state
- Daffodil.setLogWriter(new ConsoleLogWriter());
- Daffodil.setLoggingLevel(LogLevel.Info);
- }
-
- /**
- * Verify that hidden elements do not appear in the resulting infoset
- */
- @Test
- public void testJavaAPI10() throws IOException {
-
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = getResource("/test/japi/mySchema4.dfdl.xsd");
- ProcessorFactory pf = c.compileFile(schemaFile);
- DataProcessor dp = pf.onPath("/");
- java.io.File file = getResource("/test/japi/myData4.dat");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter);
- boolean err = res.isError();
- assertFalse(err);
- org.jdom2.Document doc = outputter.getResult();
- org.jdom2.output.XMLOutputter xo = new org.jdom2.output.XMLOutputter();
- xo.setFormat(Format.getPrettyFormat());
- org.jdom2.Element rootNode = doc.getRootElement();
- org.jdom2.Element hidden = rootNode.getChild("hiddenElement", rootNode.getNamespace());
- assertTrue(null == hidden);
- assertTrue(res.location().isAtEnd());
- }
-
- /**
- * Verify that nested elements do not appear as duplicates
- */
- @Test
- public void testJavaAPI11() throws IOException {
-
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = getResource("/test/japi/mySchema5.dfdl.xsd");
- ProcessorFactory pf = c.compileFile(schemaFile);
- DataProcessor dp = pf.onPath("/");
- java.io.File file = getResource("/test/japi/myData5.dat");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter);
- boolean err = res.isError();
- assertFalse(err);
- org.jdom2.Document doc = outputter.getResult();
- org.jdom2.output.XMLOutputter xo = new org.jdom2.output.XMLOutputter();
- xo.setFormat(Format.getPrettyFormat());
- // xo.output(doc, System.out);
- org.jdom2.Element rootNode = doc.getRootElement();
- org.jdom2.Element elementGroup = rootNode.getChild("elementGroup", null); // local
- // element
- // names
- // are
- // unqualified
- assertTrue(null != elementGroup);
- org.jdom2.Element groupE2 = elementGroup.getChild("e2", null);
- assertTrue(null != groupE2);
- org.jdom2.Element groupE3 = elementGroup.getChild("e3", null);
- assertTrue(null != groupE3);
- org.jdom2.Element rootE2 = rootNode.getChild("e2", null);
- assertTrue(null == rootE2);
- org.jdom2.Element rootE3 = rootNode.getChild("e3", null);
- assertTrue(null == rootE3);
- assertTrue(res.location().isAtEnd());
- }
-
- @Test
- public void testJavaAPI12() throws IOException {
- LogWriterForJAPITest2 lw2 = new LogWriterForJAPITest2();
- DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
-
- Daffodil.setLogWriter(lw2);
- Daffodil.setLoggingLevel(LogLevel.Debug);
-
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
-
- java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
- ProcessorFactory pf = c.compileFile(schemaFile);
- DataProcessor dp = pf.onPath("/");
- dp.setDebugger(debugger);
- dp.setDebugging(true);
-
- java.io.File file = getResource("/test/japi/myData.dat");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter, 2 << 3);
- boolean err = res.isError();
- assertFalse(err);
- assertTrue(res.location().isAtEnd());
-
- assertEquals(0, lw2.errors.size());
- assertEquals(0, lw2.warnings.size());
- assertTrue(lw2.others.size() > 0);
- assertTrue(debugger.lines.size() > 0);
- assertTrue(debugger.lines.contains("----------------------------------------------------------------- 1\n"));
-
- // reset the global logging and debugger state
- Daffodil.setLogWriter(new ConsoleLogWriter());
- Daffodil.setLoggingLevel(LogLevel.Info);
- }
-
- @Test
- public void testJavaAPI13() throws IOException {
- // Demonstrates here that we can set external variables
- // after compilation but before parsing via Compiler.
- LogWriterForJAPITest lw = new LogWriterForJAPITest();
- DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
-
- Daffodil.setLogWriter(lw);
- Daffodil.setLoggingLevel(LogLevel.Debug);
-
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File extVarsFile = getResource("/test/japi/external_vars_1.xml");
- java.io.File schemaFile = getResource("/test/japi/mySchemaWithVars.dfdl.xsd");
- c.setExternalDFDLVariables(extVarsFile);
- ProcessorFactory pf = c.compileFile(schemaFile);
-
- DataProcessor dp = pf.onPath("/");
- dp.setDebugger(debugger);
- dp.setDebugging(true);
-
- java.io.File file = getResource("/test/japi/myData.dat");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter, 2 << 3);
- boolean err = res.isError();
- assertFalse(err);
- org.jdom2.Document doc = outputter.getResult();
- org.jdom2.output.XMLOutputter xo = new org.jdom2.output.XMLOutputter();
- xo.setFormat(Format.getPrettyFormat());
- String docString = xo.outputString(doc);
- boolean containsVar1 = docString.contains("var1Value");
- boolean containsVar1Value = docString.contains("externallySet");
- assertTrue(containsVar1);
- assertTrue(containsVar1Value);
-
- // reset the global logging and debugger state
- Daffodil.setLogWriter(new ConsoleLogWriter());
- Daffodil.setLoggingLevel(LogLevel.Info);
- }
-
- @Test
- public void testJavaAPI14() throws IOException {
- // Demonstrates here that we can set external variables
- // after compilation but before parsing via DataProcessor.
- LogWriterForJAPITest lw = new LogWriterForJAPITest();
- DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
-
- Daffodil.setLogWriter(lw);
- Daffodil.setLoggingLevel(LogLevel.Debug);
-
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File extVarFile = getResource("/test/japi/external_vars_1.xml");
- java.io.File schemaFile = getResource("/test/japi/mySchemaWithVars.dfdl.xsd");
- ProcessorFactory pf = c.compileFile(schemaFile);
- DataProcessor dp = pf.onPath("/");
- dp.setDebugger(debugger);
- dp.setDebugging(true);
- dp.setExternalVariables(extVarFile);
-
- java.io.File file = getResource("/test/japi/myData.dat");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter, 2 << 3);
- boolean err = res.isError();
- assertFalse(err);
- org.jdom2.Document doc = outputter.getResult();
- org.jdom2.output.XMLOutputter xo = new org.jdom2.output.XMLOutputter();
- xo.setFormat(Format.getPrettyFormat());
- String docString = xo.outputString(doc);
- boolean containsVar1 = docString.contains("var1Value");
- boolean containsVar1Value = docString.contains("externallySet");
- assertTrue(containsVar1);
- assertTrue(containsVar1Value);
- assertTrue(res.location().isAtEnd());
-
- assertEquals(0, lw.errors.size());
- assertEquals(0, lw.warnings.size());
- assertTrue(lw.others.size() > 0);
- assertTrue(debugger.lines.size() > 0);
- assertTrue(debugger.lines.contains("----------------------------------------------------------------- 1\n"));
-
- // reset the global logging and debugger state
- Daffodil.setLogWriter(new ConsoleLogWriter());
- Daffodil.setLoggingLevel(LogLevel.Info);
- }
-
- @Test
- public void testJavaAPI15() throws IOException {
- LogWriterForJAPITest lw = new LogWriterForJAPITest();
-
- Daffodil.setLogWriter(lw);
- Daffodil.setLoggingLevel(LogLevel.Info);
-
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
- ProcessorFactory pf = c.compileFile(schemaFile);
- DataProcessor dp = pf.onPath("/");
- java.io.File file = getResource("/test/japi/myInfosetBroken.xml");
- org.jdom2.input.SAXBuilder builder = new org.jdom2.input.SAXBuilder();
-
- org.jdom2.Document doc = null;
- try {
- doc = builder.build(file);
- } catch (Exception e) {
- fail();
- }
-
- java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
- java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
- JDOMInfosetInputter inputter = new JDOMInfosetInputter(doc);
- UnparseResult res = dp.unparse(inputter, wbc);
- boolean err = res.isError();
- assertTrue(err);
-
- java.util.List<Diagnostic> diags = res.getDiagnostics();
- assertEquals(1, diags.size());
- Diagnostic d = diags.get(0);
- assertTrue(d.getMessage().contains("wrong"));
- assertTrue(d.getMessage().contains("e1"));
-
- // reset the global logging state
- Daffodil.setLogWriter(new ConsoleLogWriter());
- Daffodil.setLoggingLevel(LogLevel.Info);
- }
-
-
- @Test
- public void testJavaAPI16() throws IOException, InvalidUsageException {
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
- ProcessorFactory pf = c.compileFile(schemaFile);
- DataProcessor dp = pf.onPath("/");
- dp.setValidationMode(ValidationMode.Limited);
- java.io.File file = getResource("/test/japi/myData.dat");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter, 2 << 3);
- assertTrue(res.isError());
- assertFalse(res.isProcessingError());
- assertTrue(res.isValidationError());
- assertTrue(res.location().isAtEnd());
-
- java.util.List<Diagnostic> diags = res.getDiagnostics();
- assertEquals(1, diags.size());
- Diagnostic d = diags.get(0);
- assertTrue(d.getMessage().contains("maxInclusive"));
- assertTrue(d.getMessage().contains("e2"));
- assertTrue(d.getMessage().contains("20"));
- }
-
- @Test
- public void testJavaAPI17() throws IOException, InvalidUsageException {
- edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
- c.setValidateDFDLSchemas(false);
- java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
- ProcessorFactory pf = c.compileFile(schemaFile);
- DataProcessor dp = pf.onPath("/");
- dp.setValidationMode(ValidationMode.Full);
- java.io.File file = getResource("/test/japi/myData.dat");
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
- JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
- ParseResult res = dp.parse(rbc, outputter, 2 << 3);
- assertTrue(res.isError());
- assertFalse(res.isProcessingError());
- assertTrue(res.isValidationError());
- assertTrue(res.location().isAtEnd());
-
- java.util.List<Diagnostic> diags = res.getDiagnostics();
- assertEquals(3, diags.size());
- Diagnostic d0 = diags.get(0);
- Diagnostic d1 = diags.get(1);
- Diagnostic d2 = diags.get(2);
-
- assertTrue(d0.getMessage().contains("42"));
- assertTrue(d0.getMessage().contains("e2"));
- assertTrue(d0.getMessage().contains("not valid"));
-
- assertTrue(d1.getMessage().contains("42"));
- assertTrue(d1.getMessage().contains("maxInclusive"));
- assertTrue(d1.getMessage().contains("20"));
-
- assertTrue(d2.getMessage().contains("maxInclusive"));
- assertTrue(d2.getMessage().contains("e2"));
- assertTrue(d2.getMessage().contains("20"));
- }
+ public java.io.File getResource(String resPath) {
+ try {
+ return new java.io.File(this.getClass().getResource(resPath).toURI());
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ @Test
+ public void testJavaAPI1() throws IOException {
+ LogWriterForJAPITest lw = new LogWriterForJAPITest();
+ DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
+
+ Daffodil.setLogWriter(lw);
+ Daffodil.setLoggingLevel(LogLevel.Debug);
+
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+ dp.setDebugger(debugger);
+ dp.setDebugging(true);
+ java.io.File file = getResource("/test/japi/myData.dat");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter, 2 << 3);
+ boolean err = res.isError();
+ assertFalse(err);
+ assertTrue(res.location().isAtEnd());
+ assertEquals(0, lw.errors.size());
+ assertEquals(0, lw.warnings.size());
+ assertTrue(lw.others.size() > 0);
+ assertTrue(debugger.lines.size() > 0);
+ assertTrue(debugger.lines.contains("----------------------------------------------------------------- 1\n"));
+ assertTrue(debugger.getCommand().equals("trace"));
+
+ java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
+ java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
+ JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
+ UnparseResult res2 = dp.unparse(inputter, wbc);
+ err = res2.isError();
+ assertFalse(err);
+ assertEquals("42", bos.toString());
+
+ // reset the global logging and debugger state
+ Daffodil.setLogWriter(new ConsoleLogWriter());
+ Daffodil.setLoggingLevel(LogLevel.Info);
+ }
+
+ // This is a duplicate of test testJavaAPI1 that serializes the parser
+ // before executing the test.
+ @Test
+ public void testJavaAPI1_A() throws Exception {
+ LogWriterForJAPITest lw = new LogWriterForJAPITest();
+ DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
+
+ Daffodil.setLogWriter(lw);
+ Daffodil.setLoggingLevel(LogLevel.Debug);
+
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+
+ // Serialize the parser to memory, then deserialize for parsing.
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ WritableByteChannel output = Channels.newChannel(os);
+ dp.save(output);
+
+ ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
+ ReadableByteChannel input = Channels.newChannel(is);
+ edu.illinois.ncsa.daffodil.japi.Compiler compiler = Daffodil.compiler();
+ DataProcessor parser = compiler.reload(input);
+ parser.setDebugger(debugger);
+ parser.setDebugging(true);
+
+ java.io.File file = getResource("/test/japi/myData.dat");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = parser.parse(rbc, outputter, 2 << 3);
+ boolean err = res.isError();
+ assertFalse(err);
+ assertTrue(res.location().isAtEnd());
+ assertEquals(0, lw.errors.size());
+ assertEquals(0, lw.warnings.size());
+ assertTrue(lw.others.size() > 0);
+ assertTrue(debugger.lines.size() > 0);
+ assertTrue(debugger.lines.contains("----------------------------------------------------------------- 1\n"));
+ assertTrue(debugger.getCommand().equals("trace"));
+
+ java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
+ java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
+ JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
+ UnparseResult res2 = dp.unparse(inputter, wbc);
+ err = res2.isError();
+ assertFalse(err);
+ assertEquals("42", bos.toString());
+
+ // reset the global logging and debugger state
+ Daffodil.setLogWriter(new ConsoleLogWriter());
+ Daffodil.setLoggingLevel(LogLevel.Info);
+ }
+
+ // This is a duplicate of test testJavaAPI1 that serializes the parser
+ // before executing the test.
+ @Test
+ public void testJavaAPI1_A_FullFails() throws Exception {
+ LogWriterForJAPITest lw = new LogWriterForJAPITest();
+ DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
+
+ Daffodil.setLogWriter(lw);
+ Daffodil.setLoggingLevel(LogLevel.Debug);
+
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+ dp.setDebugger(debugger);
+ dp.setDebugging(true);
+
+ // Serialize the parser to memory, then deserialize for parsing.
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ WritableByteChannel output = Channels.newChannel(os);
+ dp.save(output);
+
+ ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
+ ReadableByteChannel input = Channels.newChannel(is);
+ edu.illinois.ncsa.daffodil.japi.Compiler compiler = Daffodil.compiler();
+ DataProcessor parser = compiler.reload(input);
+
+ try {
+ parser.setValidationMode(ValidationMode.Full);
+ fail();
+ } catch (InvalidUsageException e) {
+ assertEquals("'Full' validation not allowed when using a restored parser.", e.getMessage());
+ }
+
+ // reset the global logging and debugger state
+ Daffodil.setLogWriter(new ConsoleLogWriter());
+ Daffodil.setLoggingLevel(LogLevel.Info);
+ }
+
+ @Test
+ public void testJavaAPI2() throws IOException {
+ LogWriterForJAPITest lw = new LogWriterForJAPITest();
+
+ Daffodil.setLogWriter(lw);
+ Daffodil.setLoggingLevel(LogLevel.Info);
+
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+ java.io.File file = getResource("/test/japi/myDataBroken.dat");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter);
+
+ // TODO: NEED a java friendly way to get the status of the outputter.
+ // Scala enums don't work well
+ // assertTrue(outputter.getStatus() != Status.DONE); // This is a hack
+ // so that Java doesn't have to know about Nope/Maybe, need to figure
+ // out better api that is Java compatible
+ assertTrue(res.isError());
+ java.util.List<Diagnostic> diags = res.getDiagnostics();
+ assertEquals(1, diags.size());
+ Diagnostic d = diags.get(0);
+ // System.err.println(d.getMessage());
+ assertTrue(d.getMessage().contains("int"));
+ assertTrue(d.getMessage().contains("Not an int"));
+ assertTrue(d.getDataLocations().toString().contains("10"));
+ java.util.List<LocationInSchemaFile> locs = d.getLocationsInSchemaFiles();
+ assertEquals(1, locs.size());
+ LocationInSchemaFile loc = locs.get(0);
+ assertTrue(loc.toString().contains("mySchema1.dfdl.xsd"));
+ // above is mySchema1 as it reports the element ref location,
+ // not element decl.
+
+ assertEquals(0, lw.errors.size());
+ assertEquals(0, lw.warnings.size());
+ // assertTrue(lw.infos.size() > 0);
+ assertEquals(0, lw.others.size());
+
+ // reset the global logging state
+ Daffodil.setLogWriter(new ConsoleLogWriter());
+ Daffodil.setLoggingLevel(LogLevel.Info);
+ }
+
+ /**
+ * Verify that we can detect when the parse did not consume all the data.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testJavaAPI3() throws IOException {
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = getResource("/test/japi/mySchema3.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ pf.setDistinguishedRootNode("e3", null);
+ DataProcessor dp = pf.onPath("/");
+ java.io.File file = getResource("/test/japi/myData16.dat");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter, 16 << 3);
+ boolean err = res.isError();
+ assertFalse(err);
+ assertFalse(res.location().isAtEnd());
+ assertEquals(2, res.location().bytePos1b());
+ assertEquals(9, res.location().bitPos1b());
+
+ java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
+ java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
+ JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
+ UnparseResult res2 = dp.unparse(inputter, wbc);
+ err = res2.isError();
+ assertFalse(err);
+ assertEquals("9", bos.toString());
+ }
+
+ // This is a duplicate of test testJavaAPI3 that serializes the parser
+ // before executing the test.
+ @Test
+ public void testJavaAPI3_A() throws Exception {
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = getResource("/test/japi/mySchema3.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ pf.setDistinguishedRootNode("e3", null);
+ DataProcessor dp = pf.onPath("/");
+
+ // Serialize the parser to memory, then deserialize for parsing.
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ WritableByteChannel output = Channels.newChannel(os);
+ dp.save(output);
+
+ ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
+ ReadableByteChannel input = Channels.newChannel(is);
+ edu.illinois.ncsa.daffodil.japi.Compiler compiler = Daffodil.compiler();
+ DataProcessor parser = compiler.reload(input);
+
+ java.io.File file = getResource("/test/japi/myData16.dat");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = parser.parse(rbc, outputter, 16 << 3);
+ boolean err = res.isError();
+ assertFalse(err);
+ assertFalse(res.location().isAtEnd());
+ assertEquals(2, res.location().bytePos1b());
+ assertEquals(9, res.location().bitPos1b());
+
+ java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
+ java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
+ JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
+ UnparseResult res2 = dp.unparse(inputter, wbc);
+ err = res2.isError();
+ assertFalse(err);
+ assertEquals("9", bos.toString());
+ }
+
+ @Test
+ public void testJavaAPI4b() throws IOException {
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ File schemaFileName = getResource("/test/japi/mySchema3.dfdl.xsd");
+ c.setDistinguishedRootNode("e4", null);
+ ProcessorFactory pf = c.compileFile(schemaFileName);
+ DataProcessor dp = pf.onPath("/");
+ java.io.File file = getResource("/test/japi/myData2.dat");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter, 64 << 3);
+ boolean err = res.isError();
+ assertFalse(err);
+ assertFalse(res.location().isAtEnd());
+ assertEquals(5, res.location().bytePos1b());
+ assertEquals(33, res.location().bitPos1b());
+
+ java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
+ java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
+ JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
+ UnparseResult res2 = dp.unparse(inputter, wbc);
+ err = res2.isError();
+ assertFalse(err);
+ assertEquals("data", bos.toString());
+ }
+
+ @Test
+ public void testJavaAPI5() throws IOException {
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ File schemaFileName = getResource("/test/japi/mySchema3.dfdl.xsd");
+ c.setDistinguishedRootNode("e4", null); // e4 is a 4-byte long string
+ // element
+ ProcessorFactory pf = c.compileFile(schemaFileName);
+ DataProcessor dp = pf.onPath("/");
+ java.io.File file = getResource("/test/japi/myData3.dat"); // contains 5
+ // bytes
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter, 4 << 3);
+ boolean err = res.isError();
+ assertFalse(err);
+ assertTrue("Assertion failed: End of data not reached.", res.location().isAtEnd());
+ assertEquals(5, res.location().bytePos1b());
+ assertEquals(33, res.location().bitPos1b());
+
+ java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
+ java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
+ JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
+ UnparseResult res2 = dp.unparse(inputter, wbc);
+ err = res2.isError();
+ assertFalse(err);
+ assertEquals("data", bos.toString());
+ }
+
+ /***
+ * Verify that the compiler throws a FileNotFound exception when fed a list
+ * of schema files that do not exist.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testJavaAPI6() throws IOException {
+ LogWriterForJAPITest lw = new LogWriterForJAPITest();
+
+ Daffodil.setLogWriter(lw);
+ Daffodil.setLoggingLevel(LogLevel.Debug);
+
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = new java.io.File("/test/japi/notHere1.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ assertTrue(pf.isError());
+ List<Diagnostic> diags = pf.getDiagnostics();
+ boolean found1 = false;
+ for (Diagnostic d : diags) {
+ if (d.getMessage().contains("notHere1")) {
+ found1 = true;
+ }
+ }
+ assertTrue(found1);
+
+ // reset the global logging state
+ Daffodil.setLogWriter(new ConsoleLogWriter());
+ Daffodil.setLoggingLevel(LogLevel.Info);
+ }
+
+ /**
+ * Tests a user submitted case where the XML appears to be serializing odd
+ * xml entities into the output.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testJavaAPI7() throws IOException {
+ // TODO: This is due to the fact that we are doing several conversions
+ // back and forth between Scala.xml.Node and JDOM. And the conversions
+ // both use XMLOutputter to format the result (which escapes the
+ // entities).
+ LogWriterForJAPITest lw = new LogWriterForJAPITest();
+
+ Daffodil.setLogWriter(lw);
+ Daffodil.setLoggingLevel(LogLevel.Debug);
+
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = getResource("/test/japi/TopLevel.xsd");
+ c.setDistinguishedRootNode("TopLevel", null);
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+ java.io.File file = getResource("/test/japi/01very_simple.txt");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter);
+ boolean err = res.isError();
+ assertFalse(err);
+ assertTrue(res.location().isAtEnd());
+
+ java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
+ java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
+ JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
+ UnparseResult res2 = dp.unparse(inputter, wbc);
+ err = res2.isError();
+ assertFalse(err);
+ assertTrue(bos.toString().contains("Return-Path: <bo...@smith.com>"));
+
+ // reset the global logging state
+ Daffodil.setLogWriter(new ConsoleLogWriter());
+ Daffodil.setLoggingLevel(LogLevel.Info);
+ }
+
+ /**
+ * This test is nearly identical to testJavaAPI7. The only difference is
+ * that this test uses double newline as a terminator for the first element
+ * in the sequence rather than double newline as a separator for the
+ * sequence
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testJavaAPI8() throws IOException {
+ LogWriterForJAPITest lw = new LogWriterForJAPITest();
+
+ Daffodil.setLogWriter(lw);
+ Daffodil.setLoggingLevel(LogLevel.Debug);
+
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = getResource("/test/japi/TopLevel.xsd");
+ c.setDistinguishedRootNode("TopLevel2", null);
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+ java.io.File file = getResource("/test/japi/01very_simple.txt");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter);
+ boolean err = res.isError();
+ assertFalse(err);
+ assertTrue(res.location().isAtEnd());
+
+ java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
+ java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
+ JDOMInfosetInputter inputter = new JDOMInfosetInputter(outputter.getResult());
+ UnparseResult res2 = dp.unparse(inputter, wbc);
+ err = res2.isError();
+ assertFalse(err);
+ assertTrue(bos.toString().contains("Return-Path: <bo...@smith.com>"));
+
+ // reset the global logging state
+ Daffodil.setLogWriter(new ConsoleLogWriter());
+ Daffodil.setLoggingLevel(LogLevel.Info);
+ }
+
+ /**
+ * Verify that calling result() on the ParseResult multiple times does not
+ * error.
+ */
+ @Test
+ public void testJavaAPI9() throws IOException {
+ LogWriterForJAPITest lw = new LogWriterForJAPITest();
+
+ Daffodil.setLogWriter(lw);
+ Daffodil.setLoggingLevel(LogLevel.Debug);
+
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = getResource("/test/japi/TopLevel.xsd");
+ c.setDistinguishedRootNode("TopLevel2", null);
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+ java.io.File file = getResource("/test/japi/01very_simple.txt");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter);
+ boolean err = res.isError();
+ assertFalse(err);
+ assertTrue(res.location().isAtEnd());
+
+ org.jdom2.Document doc1 = outputter.getResult();
+
+ java.io.ByteArrayOutputStream bos1 = new java.io.ByteArrayOutputStream();
+ java.nio.channels.WritableByteChannel wbc1 = java.nio.channels.Channels.newChannel(bos1);
+ JDOMInfosetInputter inputter1 = new JDOMInfosetInputter(doc1);
+ UnparseResult res2 = dp.unparse(inputter1, wbc1);
+ err = res2.isError();
+ assertFalse(err);
+ assertTrue(bos1.toString().contains("Return-Path: <bo...@smith.com>"));
+
+ org.jdom2.Document doc2 = outputter.getResult();
+
+ java.io.ByteArrayOutputStream bos2 = new java.io.ByteArrayOutputStream();
+ java.nio.channels.WritableByteChannel wbc2 = java.nio.channels.Channels.newChannel(bos2);
+ JDOMInfosetInputter inputter2 = new JDOMInfosetInputter(doc2);
+ UnparseResult res3 = dp.unparse(inputter2, wbc2);
+ err = res3.isError();
+ assertFalse(err);
+ assertTrue(bos2.toString().contains("Return-Path: <bo...@smith.com>"));
+
+ // reset the global logging state
+ Daffodil.setLogWriter(new ConsoleLogWriter());
+ Daffodil.setLoggingLevel(LogLevel.Info);
+ }
+
+ /**
+ * Verify that hidden elements do not appear in the resulting infoset
+ */
+ @Test
+ public void testJavaAPI10() throws IOException {
+
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = getResource("/test/japi/mySchema4.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+ java.io.File file = getResource("/test/japi/myData4.dat");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter);
+ boolean err = res.isError();
+ assertFalse(err);
+ org.jdom2.Document doc = outputter.getResult();
+ org.jdom2.output.XMLOutputter xo = new org.jdom2.output.XMLOutputter();
+ xo.setFormat(Format.getPrettyFormat());
+ org.jdom2.Element rootNode = doc.getRootElement();
+ org.jdom2.Element hidden = rootNode.getChild("hiddenElement", rootNode.getNamespace());
+ assertTrue(null == hidden);
+ assertTrue(res.location().isAtEnd());
+ }
+
+ /**
+ * Verify that nested elements do not appear as duplicates
+ */
+ @Test
+ public void testJavaAPI11() throws IOException {
+
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = getResource("/test/japi/mySchema5.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+ java.io.File file = getResource("/test/japi/myData5.dat");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter);
+ boolean err = res.isError();
+ assertFalse(err);
+ org.jdom2.Document doc = outputter.getResult();
+ org.jdom2.output.XMLOutputter xo = new org.jdom2.output.XMLOutputter();
+ xo.setFormat(Format.getPrettyFormat());
+ // xo.output(doc, System.out);
+ org.jdom2.Element rootNode = doc.getRootElement();
+ org.jdom2.Element elementGroup = rootNode.getChild("elementGroup", null); // local
+ // element
+ // names
+ // are
+ // unqualified
+ assertTrue(null != elementGroup);
+ org.jdom2.Element groupE2 = elementGroup.getChild("e2", null);
+ assertTrue(null != groupE2);
+ org.jdom2.Element groupE3 = elementGroup.getChild("e3", null);
+ assertTrue(null != groupE3);
+ org.jdom2.Element rootE2 = rootNode.getChild("e2", null);
+ assertTrue(null == rootE2);
+ org.jdom2.Element rootE3 = rootNode.getChild("e3", null);
+ assertTrue(null == rootE3);
+ assertTrue(res.location().isAtEnd());
+ }
+
+ @Test
+ public void testJavaAPI12() throws IOException {
+ LogWriterForJAPITest2 lw2 = new LogWriterForJAPITest2();
+ DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
+
+ Daffodil.setLogWriter(lw2);
+ Daffodil.setLoggingLevel(LogLevel.Debug);
+
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+
+ java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+ dp.setDebugger(debugger);
+ dp.setDebugging(true);
+
+ java.io.File file = getResource("/test/japi/myData.dat");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter, 2 << 3);
+ boolean err = res.isError();
+ assertFalse(err);
+ assertTrue(res.location().isAtEnd());
+
+ assertEquals(0, lw2.errors.size());
+ assertEquals(0, lw2.warnings.size());
+ assertTrue(lw2.others.size() > 0);
+ assertTrue(debugger.lines.size() > 0);
+ assertTrue(debugger.lines.contains("----------------------------------------------------------------- 1\n"));
+
+ // reset the global logging and debugger state
+ Daffodil.setLogWriter(new ConsoleLogWriter());
+ Daffodil.setLoggingLevel(LogLevel.Info);
+ }
+
+ @Test
+ public void testJavaAPI13() throws IOException {
+ // Demonstrates here that we can set external variables
+ // after compilation but before parsing via Compiler.
+ LogWriterForJAPITest lw = new LogWriterForJAPITest();
+ DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
+
+ Daffodil.setLogWriter(lw);
+ Daffodil.setLoggingLevel(LogLevel.Debug);
+
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File extVarsFile = getResource("/test/japi/external_vars_1.xml");
+ java.io.File schemaFile = getResource("/test/japi/mySchemaWithVars.dfdl.xsd");
+ c.setExternalDFDLVariables(extVarsFile);
+ ProcessorFactory pf = c.compileFile(schemaFile);
+
+ DataProcessor dp = pf.onPath("/");
+ dp.setDebugger(debugger);
+ dp.setDebugging(true);
+
+ java.io.File file = getResource("/test/japi/myData.dat");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter, 2 << 3);
+ boolean err = res.isError();
+ assertFalse(err);
+ org.jdom2.Document doc = outputter.getResult();
+ org.jdom2.output.XMLOutputter xo = new org.jdom2.output.XMLOutputter();
+ xo.setFormat(Format.getPrettyFormat());
+ String docString = xo.outputString(doc);
+ boolean containsVar1 = docString.contains("var1Value");
+ boolean containsVar1Value = docString.contains("externallySet");
+ assertTrue(containsVar1);
+ assertTrue(containsVar1Value);
+
+ // reset the global logging and debugger state
+ Daffodil.setLogWriter(new ConsoleLogWriter());
+ Daffodil.setLoggingLevel(LogLevel.Info);
+ }
+
+ @Test
+ public void testJavaAPI14() throws IOException {
+ // Demonstrates here that we can set external variables
+ // after compilation but before parsing via DataProcessor.
+ LogWriterForJAPITest lw = new LogWriterForJAPITest();
+ DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
+
+ Daffodil.setLogWriter(lw);
+ Daffodil.setLoggingLevel(LogLevel.Debug);
+
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File extVarFile = getResource("/test/japi/external_vars_1.xml");
+ java.io.File schemaFile = getResource("/test/japi/mySchemaWithVars.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+ dp.setDebugger(debugger);
+ dp.setDebugging(true);
+ dp.setExternalVariables(extVarFile);
+
+ java.io.File file = getResource("/test/japi/myData.dat");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter, 2 << 3);
+ boolean err = res.isError();
+ assertFalse(err);
+ org.jdom2.Document doc = outputter.getResult();
+ org.jdom2.output.XMLOutputter xo = new org.jdom2.output.XMLOutputter();
+ xo.setFormat(Format.getPrettyFormat());
+ String docString = xo.outputString(doc);
+ boolean containsVar1 = docString.contains("var1Value");
+ boolean containsVar1Value = docString.contains("externallySet");
+ assertTrue(containsVar1);
+ assertTrue(containsVar1Value);
+ assertTrue(res.location().isAtEnd());
+
+ assertEquals(0, lw.errors.size());
+ assertEquals(0, lw.warnings.size());
+ assertTrue(lw.others.size() > 0);
+ assertTrue(debugger.lines.size() > 0);
+ assertTrue(debugger.lines.contains("----------------------------------------------------------------- 1\n"));
+
+ // reset the global logging and debugger state
+ Daffodil.setLogWriter(new ConsoleLogWriter());
+ Daffodil.setLoggingLevel(LogLevel.Info);
+ }
+
+ @Test
+ public void testJavaAPI15() throws IOException {
+ LogWriterForJAPITest lw = new LogWriterForJAPITest();
+
+ Daffodil.setLogWriter(lw);
+ Daffodil.setLoggingLevel(LogLevel.Info);
+
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+ java.io.File file = getResource("/test/japi/myInfosetBroken.xml");
+ org.jdom2.input.SAXBuilder builder = new org.jdom2.input.SAXBuilder();
+
+ org.jdom2.Document doc = null;
+ try {
+ doc = builder.build(file);
+ } catch (Exception e) {
+ fail();
+ }
+
+ java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
+ java.nio.channels.WritableByteChannel wbc = java.nio.channels.Channels.newChannel(bos);
+ JDOMInfosetInputter inputter = new JDOMInfosetInputter(doc);
+ UnparseResult res = dp.unparse(inputter, wbc);
+ boolean err = res.isError();
+ assertTrue(err);
+
+ java.util.List<Diagnostic> diags = res.getDiagnostics();
+ assertEquals(1, diags.size());
+ Diagnostic d = diags.get(0);
+ assertTrue(d.getMessage().contains("wrong"));
+ assertTrue(d.getMessage().contains("e1"));
+
+ // reset the global logging state
+ Daffodil.setLogWriter(new ConsoleLogWriter());
+ Daffodil.setLoggingLevel(LogLevel.Info);
+ }
+
+ @Test
+ public void testJavaAPI16() throws IOException, InvalidUsageException {
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+ dp.setValidationMode(ValidationMode.Limited);
+ java.io.File file = getResource("/test/japi/myData.dat");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter, 2 << 3);
+ assertTrue(res.isError());
+ assertFalse(res.isProcessingError());
+ assertTrue(res.isValidationError());
+ assertTrue(res.location().isAtEnd());
+
+ java.util.List<Diagnostic> diags = res.getDiagnostics();
+ assertEquals(1, diags.size());
+ Diagnostic d = diags.get(0);
+ assertTrue(d.getMessage().contains("maxInclusive"));
+ assertTrue(d.getMessage().contains("e2"));
+ assertTrue(d.getMessage().contains("20"));
+ }
+
+ @Test
+ public void testJavaAPI17() throws IOException, InvalidUsageException {
+ edu.illinois.ncsa.daffodil.japi.Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(false);
+ java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+ dp.setValidationMode(ValidationMode.Full);
+ java.io.File file = getResource("/test/japi/myData.dat");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ java.nio.channels.ReadableByteChannel rbc = java.nio.channels.Channels.newChannel(fis);
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(rbc, outputter, 2 << 3);
+ assertTrue(res.isError());
+ assertFalse(res.isProcessingError());
+ assertTrue(res.isValidationError());
+ assertTrue(res.location().isAtEnd());
+
+ java.util.List<Diagnostic> diags = res.getDiagnostics();
+ assertEquals(3, diags.size());
+ Diagnostic d0 = diags.get(0);
+ Diagnostic d1 = diags.get(1);
+ Diagnostic d2 = diags.get(2);
+
+ assertTrue(d0.getMessage().contains("42"));
+ assertTrue(d0.getMessage().contains("e2"));
+ assertTrue(d0.getMessage().contains("not valid"));
+
+ assertTrue(d1.getMessage().contains("42"));
+ assertTrue(d1.getMessage().contains("maxInclusive"));
+ assertTrue(d1.getMessage().contains("20"));
+
+ assertTrue(d2.getMessage().contains("maxInclusive"));
+ assertTrue(d2.getMessage().contains("e2"));
+ assertTrue(d2.getMessage().contains("20"));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/oolag/OOLAG.scala
----------------------------------------------------------------------
diff --git a/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/oolag/OOLAG.scala b/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/oolag/OOLAG.scala
index 2a81b31..3eab287 100644
--- a/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/oolag/OOLAG.scala
+++ b/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/oolag/OOLAG.scala
@@ -46,7 +46,8 @@ import edu.illinois.ncsa.daffodil.util.Maybe._
* OOLAG = Object-oriented Lazy Attribute Grammars
*
* It's a collection of techniques for compilation/transformation
- * in a functional programming style
+ * in a functional programming style. You can find an article about
+ * Attribute Grammars on Wikipedia.
*/
object OOLAG extends Logging {
@@ -89,28 +90,48 @@ object OOLAG extends Logging {
*/
private val OOLAGRoot: OOLAGHost = null
- private sealed abstract class Args
- private case object OneArg extends Args
- private case object ZeroArgs extends Args
+ sealed abstract class Args
+ case object OneArg extends Args
+ case object ZeroArgs extends Args
+
+ /**
+ * Convenience class for implementing OOLAGHost trait.
+ *
+ * Insures context is set by way of construction. Use the trait and
+ * implement the context yourself if you want to make use of setting the
+ * context after the objects are constructed.
+ */
+ abstract class OOLAGHostImpl private (
+ oolagContextArg: OOLAGHost,
+ final override val nArgs: Args)
+ extends OOLAGHost {
+
+ def this(oolagContext: OOLAGHost) = this(oolagContext, OneArg)
+ def this() = this(null, ZeroArgs)
+
+ final protected override def oolagContextViaArgs = {
+ Some(oolagContextArg)
+ }
+ }
/**
* An OOLAGHost, or OOLAG for short, is a collection of OOLAGValues
* or LVs for short.
*
* The way these are generally used now is like this
- *
+ * {{{
* def foo = LV('foo) {...calculation...}.value
- *
+ * }}}
* or, if you would like a slot to show up in the debugger so you
* can more easily see the value of the LV then you can
- *
+ * {{{
* lazy val foo = LV('foo){...calculation...}.value
- *
+ * }}}
* Why scala needs 'real' Lisp-style macros: Well wouldn't it be
* nicer if I could write:
- *
+ * {{{
* defAttribute foo {... calculation ...}
- *
+ * }}}
* and have that be equivalent the more verbose stuff above it?
* But I digress...
*
@@ -123,18 +144,21 @@ object OOLAG extends Logging {
* we want to say that our particular OOLAGHost-derived class must
* evaluate the 'foo' LV otherwise we don't know if it has errors or not,
* then we write:
- *
+ * {{{
* requiredEvaluations(foo)
- *
+ * }}}
* This goes at the top of the class definition. When isError is invoked
* the value of 'foo' will be computed if it has not been attempted
* already. This insures that the value exists for 'foo', or any errors/warnings
* to be determined by its calculation have been recorded.
*/
- abstract class OOLAGHost private (oolagContextArg: OOLAGHost, nArgs: Args)
+ trait OOLAGHost
extends Logging with WithDiagnostics
with NamedMixinBase {
+ protected def oolagContextViaArgs: Option[OOLAGHost] = None
+ protected def nArgs: Args = OneArg
+
private var oolagContextViaSet: Option[OOLAGHost] = None
final def setOOLAGContext(oolagContextArg: OOLAGHost) {
@@ -142,7 +166,7 @@ object OOLAG extends Logging {
if (oolagContextViaSet != None)
Assert.usageError("Cannot set oolag context more than once.")
oolagContextViaSet = Some(oolagContextArg)
- if (oolagContextArg != OOLAGRoot) {
+ if (oolagContext != OOLAGRoot) {
oolagRoot.requiredEvalFunctions ++= this.requiredEvalFunctions
this.requiredEvalFunctions = Nil
}
@@ -155,9 +179,6 @@ object OOLAG extends Logging {
false
}
- def this(oolagContextArg: OOLAGHost) = this(oolagContextArg, OneArg)
- def this() = this(null, ZeroArgs)
-
/**
* Used to check things that OOLAG doesn't protect against such as
* index out of bounds.
@@ -193,7 +214,7 @@ object OOLAG extends Logging {
Assert.usage(oolagContextViaSet != None, "Must call setOOLAGContext before accessing when OOLAGHost is constructed with no args.")
oolagContextViaSet.get
}
- case OneArg => oolagContextArg
+ case OneArg => oolagContextViaArgs.get
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/PropertyScoping.scala
----------------------------------------------------------------------
diff --git a/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/PropertyScoping.scala b/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/PropertyScoping.scala
index 4a88770..61bdc41 100644
--- a/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/PropertyScoping.scala
+++ b/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/PropertyScoping.scala
@@ -206,11 +206,12 @@ trait FindPropertyMixin extends PropTypes {
}
/**
- * For unit testing convenience
+ * For unit testing convenience, or for use when debugging.
*/
final def verifyPropValue(key: String, value: String): Boolean = {
- findPropertyOption(key) match {
- case Found(`value`, _, _, _) => true
+ val prop = findPropertyOption(key)
+ prop match {
+ case Found(v, _, _, _) if (v == value) => true
case _: Found => false
case _: NotFound => false
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/xml/QNameBase.scala
----------------------------------------------------------------------
diff --git a/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/xml/QNameBase.scala b/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/xml/QNameBase.scala
index c661fbe..d60fc77 100644
--- a/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/xml/QNameBase.scala
+++ b/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/xml/QNameBase.scala
@@ -357,6 +357,8 @@ sealed trait NamedQName
Assert.usage(!namespace.isNoNamespace)
Assert.usage(!namespace.isUnspecified)
}
+
+ def toRefQName = RefQName(prefix, local, namespace)
}
/**
@@ -516,7 +518,7 @@ object StepQNameFactory extends RefQNameFactoryBase[StepQName] {
override def constructor(prefix: Option[String], local: String, namespace: NS) =
StepQName(prefix, local, namespace)
- /* This is what needs Tunables and propagates into Expression */
+ /* This is what needs Tunables and propagates into Expression */
override def resolveDefaultNamespace(scope: scala.xml.NamespaceBinding, tunable: DaffodilTunables) = {
tunable.unqualifiedPathStepPolicy match {
case UnqualifiedPathStepPolicy.NoNamespace => None // don't consider default namespace
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/xml/XMLUtils.scala
----------------------------------------------------------------------
diff --git a/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/xml/XMLUtils.scala b/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/xml/XMLUtils.scala
index d2738c4..c86f959 100644
--- a/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/xml/XMLUtils.scala
+++ b/daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/xml/XMLUtils.scala
@@ -330,6 +330,27 @@ object XMLUtils {
val XHTML_NAMESPACE = NS("http://www.w3.org/1999/xhtml")
/**
+ * Returns an Elem with local name "element", and the scope provided
+ * with the prefix of the Elem setup to match the scope's binding
+ * for the XSD_NAMESPACE.
+ *
+ * If the XSD_NAMESPACE is the default namespace, then the prefix will
+ * be null. If the XSD_NAMESPACE is bound to a prefix, the first such
+ * prefix will be used for the returned Elem.
+ */
+ def getXSDElement(scope: NamespaceBinding): Elem = {
+ val xsdPre = scope.getPrefix(XSD_NAMESPACE.toString)
+ val isXSDTheDefaultNS = XSD_NAMESPACE.toString() == scope.getURI(null)
+ val xsdPrefix =
+ if (xsdPre ne null) xsdPre
+ else if (isXSDTheDefaultNS) null
+ else Assert.usageError("Scope argument must have a binding for the XSD namespace.")
+ val res =
+ Elem(xsdPrefix, "element", Null, scope, true)
+ res
+ }
+
+ /**
* Added to support extensions and proposed future features as part of daffodil.
*
* The DFDL standard requires us to keep these out of the primary DFDL namespace, and
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-lib/src/test/scala/edu/illinois/ncsa/daffodil/oolag/TestOOLAG.scala
----------------------------------------------------------------------
diff --git a/daffodil-lib/src/test/scala/edu/illinois/ncsa/daffodil/oolag/TestOOLAG.scala b/daffodil-lib/src/test/scala/edu/illinois/ncsa/daffodil/oolag/TestOOLAG.scala
index a06bb8e..7332563 100644
--- a/daffodil-lib/src/test/scala/edu/illinois/ncsa/daffodil/oolag/TestOOLAG.scala
+++ b/daffodil-lib/src/test/scala/edu/illinois/ncsa/daffodil/oolag/TestOOLAG.scala
@@ -49,7 +49,7 @@ class MyException(msg: String)
}
abstract class MyBase(parentArg: MyBase)
- extends OOLAGHost(parentArg) {
+ extends OOLAGHostImpl(parentArg) {
def a1 = a1_.value
def a1_ = LV('a1) {
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-lib/src/test/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/TestGeneratedProperties.scala
----------------------------------------------------------------------
diff --git a/daffodil-lib/src/test/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/TestGeneratedProperties.scala b/daffodil-lib/src/test/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/TestGeneratedProperties.scala
index a4a63b8..5e281e8 100644
--- a/daffodil-lib/src/test/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/TestGeneratedProperties.scala
+++ b/daffodil-lib/src/test/scala/edu/illinois/ncsa/daffodil/schema/annotation/props/TestGeneratedProperties.scala
@@ -35,7 +35,7 @@ package edu.illinois.ncsa.daffodil.schema.annotation.props
import edu.illinois.ncsa.daffodil.schema.annotation.props.gen._
import junit.framework.Assert._
import org.junit.Test
-import edu.illinois.ncsa.daffodil.oolag.OOLAG.OOLAGHost
+import edu.illinois.ncsa.daffodil.oolag.OOLAG.OOLAGHostImpl
import edu.illinois.ncsa.daffodil.exceptions.SchemaFileLocation
import edu.illinois.ncsa.daffodil.api.WarnID
import edu.illinois.ncsa.daffodil.api.DaffodilTunables
@@ -54,7 +54,7 @@ class TestGeneratedProperties {
* retrieves the property if it is present.
*/
class HasLotsOfProperties
- extends OOLAGHost(null)
+ extends OOLAGHostImpl(null)
with LookupLocation
with Format_AnnotationMixin
with SeparatorSuppressionPolicyMixin {
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-runtime1/src/main/scala/edu/illinois/ncsa/daffodil/dsom/CompiledExpression1.scala
----------------------------------------------------------------------
diff --git a/daffodil-runtime1/src/main/scala/edu/illinois/ncsa/daffodil/dsom/CompiledExpression1.scala b/daffodil-runtime1/src/main/scala/edu/illinois/ncsa/daffodil/dsom/CompiledExpression1.scala
index 9b48188..cd24bcf 100644
--- a/daffodil-runtime1/src/main/scala/edu/illinois/ncsa/daffodil/dsom/CompiledExpression1.scala
+++ b/daffodil-runtime1/src/main/scala/edu/illinois/ncsa/daffodil/dsom/CompiledExpression1.scala
@@ -221,7 +221,7 @@ class DPathCompileInfo(
lazy val variableMap =
variableMapArg
- override def preSerialization = {
+ override def preSerialization: Any = {
parent
variableMap
}
@@ -314,6 +314,7 @@ class DPathCompileInfo(
class DPathElementCompileInfo(
@TransientParam parentArg: => Option[DPathCompileInfo],
@TransientParam variableMap: => VariableMap,
+ @TransientParam elementChildrenCompileInfoArg: => Seq[DPathElementCompileInfo],
namespaces: scala.xml.NamespaceBinding,
path: String,
val name: String,
@@ -321,11 +322,17 @@ class DPathElementCompileInfo(
val namedQName: NamedQName,
val optPrimType: Option[PrimType],
sfl: SchemaFileLocation,
- val elementChildrenCompileInfo: Seq[DPathElementCompileInfo],
override val tunable: DaffodilTunables)
extends DPathCompileInfo(parentArg, variableMap, namespaces, path, sfl, tunable)
with HasSchemaFileLocation {
+ lazy val elementChildrenCompileInfo = elementChildrenCompileInfoArg
+
+ override def preSerialization: Any = {
+ super.preSerialization
+ elementChildrenCompileInfo
+ }
+
override def toString = "DPathElementCompileInfo(%s)".format(name)
@throws(classOf[java.io.IOException])
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-sapi/src/test/scala/edu/illinois/ncsa/daffodil/example/TestScalaAPI.scala
----------------------------------------------------------------------
diff --git a/daffodil-sapi/src/test/scala/edu/illinois/ncsa/daffodil/example/TestScalaAPI.scala b/daffodil-sapi/src/test/scala/edu/illinois/ncsa/daffodil/example/TestScalaAPI.scala
index 9a05ff9..a16e479 100644
--- a/daffodil-sapi/src/test/scala/edu/illinois/ncsa/daffodil/example/TestScalaAPI.scala
+++ b/daffodil-sapi/src/test/scala/edu/illinois/ncsa/daffodil/example/TestScalaAPI.scala
@@ -196,7 +196,7 @@ class TestScalaAPI {
val locs = d.getLocationsInSchemaFiles
assertEquals(1, locs.size)
val loc = locs(0)
- assertTrue(loc.toString().contains("mySchema2.dfdl.xsd"))
+ assertTrue(loc.toString().contains("mySchema1.dfdl.xsd")) // reports the element ref, not element decl.
assertEquals(0, lw.errors.size)
assertEquals(0, lw.warnings.size)
@@ -786,7 +786,7 @@ class TestScalaAPI {
val res = dp.parse(rbc, outputter, 2 << 3)
assertTrue(res.isError())
assertFalse(res.isProcessingError())
- assertTrue(res.isValidationError() )
+ assertTrue(res.isValidationError())
assertTrue(res.location().isAtEnd())
val diags = res.getDiagnostics
@@ -812,7 +812,7 @@ class TestScalaAPI {
val res = dp.parse(rbc, outputter, 2 << 3)
assertTrue(res.isError())
assertFalse(res.isProcessingError())
- assertTrue(res.isValidationError() )
+ assertTrue(res.isValidationError())
assertTrue(res.location().isAtEnd())
val diags = res.getDiagnostics
@@ -833,5 +833,4 @@ class TestScalaAPI {
assertTrue(d2.getMessage().contains("20"))
}
-
}
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-tdml/src/main/scala/edu/illinois/ncsa/daffodil/tdml/TDMLRunner.scala
----------------------------------------------------------------------
diff --git a/daffodil-tdml/src/main/scala/edu/illinois/ncsa/daffodil/tdml/TDMLRunner.scala b/daffodil-tdml/src/main/scala/edu/illinois/ncsa/daffodil/tdml/TDMLRunner.scala
index d8aec66..47e3c11 100644
--- a/daffodil-tdml/src/main/scala/edu/illinois/ncsa/daffodil/tdml/TDMLRunner.scala
+++ b/daffodil-tdml/src/main/scala/edu/illinois/ncsa/daffodil/tdml/TDMLRunner.scala
@@ -1108,7 +1108,12 @@ object VerifyTestCase {
if (expectedDiags.isDefined && actualDiags.length == 0) {
throw new TDMLException(""""Diagnostic message(s) were expected but not found."""" +
- "\n" + """Expected: """ + expectedDiagMsgs.mkString("\n"))
+ "\n" + """Expected: """ + expectedDiagMsgs.mkString("\n") +
+ ( if (actualDiagMsgs.length == 0)
+ "\n No diagnostic messages were issued."
+ else
+ "\n The actual diagnostics messages were: " + actualDiagMsgs.mkString("\n")
+ ))
}
// must find each expected warning message within some actual warning message.
http://git-wip-us.apache.org/repos/asf/incubator-daffodil/blob/89517717/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section06/entities/Entities.tdml
----------------------------------------------------------------------
diff --git a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section06/entities/Entities.tdml b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section06/entities/Entities.tdml
index 4bff868..b8afcaf 100644
--- a/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section06/entities/Entities.tdml
+++ b/daffodil-test/src/test/resources/edu/illinois/ncsa/daffodil/section06/entities/Entities.tdml
@@ -1141,7 +1141,7 @@ is multiple bytes in UTF-8 encoding that is used"
dfdl:lengthPattern="[^END]{0,49}(?=END)|.{50}" dfdl:representation="text" />
<xs:sequence
dfdl:terminator="{if (fn:string-length(./ex:value) eq 50) then '%ES; %DEL;' else 'END'}" />
- <!-- can replace %ES with WSP* if ES doesn't work, %ES cannot be alone in list. -->
+ <!-- %DEL is there because %ES cannot be alone in list. -->
</xs:sequence>
</xs:group>