olabusayoT commented on a change in pull request #436:
URL: https://github.com/apache/incubator-daffodil/pull/436#discussion_r506557676



##########
File path: 
daffodil-runtime1/src/main/scala/org/apache/daffodil/infoset/SAXInfosetInputter.scala
##########
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.daffodil.infoset
+
+import java.net.URI
+import java.net.URISyntaxException
+
+import scala.util.Try
+
+import org.apache.daffodil.api.DFDL
+import org.apache.daffodil.api.DFDL.DaffodilInputContentHandler
+import org.apache.daffodil.api.DFDL.DaffodilUnhandledSAXException
+import org.apache.daffodil.api.DFDL.DaffodilUnparseErrorSAXException
+import org.apache.daffodil.dpath.NodeInfo
+import org.apache.daffodil.infoset.InfosetInputterEventType.EndDocument
+import org.apache.daffodil.util.Maybe.One
+import org.apache.daffodil.util.MaybeBoolean
+import org.apache.daffodil.util.Misc
+import org.apache.daffodil.xml.XMLUtils
+
+class SAXInfosetInputter(ch: DaffodilInputContentHandler, dp: 
DFDL.DataProcessor, output: DFDL
+.Output) extends InfosetInputter with DFDL.ConsumerCoroutine {
+
+  var isDone = false
+  var currentEvent: DFDL.SaxInfosetEvent = _
+  var nextEvent: DFDL.SaxInfosetEvent = _
+  val contentHandlerEvent: DFDL.SaxInfosetEvent = new DFDL.SaxInfosetEvent
+
+  override def getEventType(): InfosetInputterEventType = 
currentEvent.eventType.orNull
+
+  override def getLocalName(): String = currentEvent.localName.orNull
+
+  override def getNamespaceURI(): String = currentEvent.namespaceURI.orNull
+
+  override def getSimpleText(primType: NodeInfo.Kind): String = {
+    val res = if (currentEvent.simpleText.isDefined) {
+      currentEvent.simpleText.get
+    } else (
+      throw new NonTextFoundInSimpleContentException(getLocalName())
+    )
+    if (primType.isInstanceOf[NodeInfo.AnyURI.Kind] && res.nonEmpty) {
+      try {
+        val uri = new URI(res)
+        if (!uri.getPath.startsWith("/")) {
+          // TDML files must allow blob URI's to be relative, but Daffodil
+          // requires them to be absolute with a scheme. So search for the file
+          // using TDML semantics and convert to an absolute URI
+          val abs = Misc.searchResourceOption(uri.getPath, None)
+          abs.get.toString
+        } else {
+          res
+        }
+      } catch {
+        case _: URISyntaxException => res
+      }
+    } else {
+      if (primType.isInstanceOf[NodeInfo.String.Kind]) {
+        val remapped = XMLUtils.remapPUAToXMLIllegalCharacters(res)
+        remapped
+      } else {
+        res
+      }
+    }
+  }
+
+  override def isNilled(): MaybeBoolean = {
+    val _isNilled = if (currentEvent.nilValue.isDefined) {
+      val nilValue = currentEvent.nilValue.get
+      if (nilValue == "true" || nilValue == "1") {
+        MaybeBoolean(true)
+      } else if (nilValue == "false" || nilValue == "0") {
+        MaybeBoolean(false)
+      } else {
+        throw new InvalidInfosetException("xsi:nil property is not a valid 
boolean: '" + nilValue +
+          "' for element " + getLocalName())
+      }
+    } else {
+      MaybeBoolean.Nope
+    }
+    _isNilled
+  }
+
+  //called without changing any state
+  override def hasNext(): Boolean = {
+    if (isDone) {
+      false
+    } else {
+      val event = this.resume(ch, Try(currentEvent))
+      nextEvent = copyEvent(event.getOrElse(null))
+      nextEvent != null
+    }
+  }
+
+  // done with this current event, move on to the next event
+  override def next(): Unit = {
+    currentEvent = copyEvent(nextEvent)
+    if (currentEvent.eventType.contains(EndDocument)) {
+      isDone = true
+    }

Review comment:
       Yes, I took those out as well. Now we only allocate a new InfosetEvent 
at the declaration of the each infoset val




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to