You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by sl...@apache.org on 2019/01/07 16:06:37 UTC
[incubator-daffodil] 01/01: Make the JAPI/SAPI DataProcessors
serializable
This is an automated email from the ASF dual-hosted git repository.
slawrence pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-daffodil.git
commit fc0b2ed3809d7d310efe74c8a4a092f896bda76a
Author: Steve Lawrence <sl...@apache.org>
AuthorDate: Fri Jan 4 09:02:03 2019 -0500
Make the JAPI/SAPI DataProcessors serializable
Some tools, like Apache Spark, need the ability to serialize the
DataProcessor to be sent to cluster nodes where it is then deserialized
and used to process data. We have the save/reload methods, but Spark
does not now how to use these. So this modifies the JAPI/SAPI
DataProcessors so that they are serializable, and modifies the JAPI/SAPI
tests to serialize/deserialize each DataProcessor before being used.
DAFFODIL-1440
---
.../scala/org/apache/daffodil/japi/Daffodil.scala | 6 +-
.../org/apache/daffodil/example/TestJavaAPI.java | 120 ++++++++++++++++---
.../scala/org/apache/daffodil/sapi/Daffodil.scala | 6 +-
.../org/apache/daffodil/example/TestScalaAPI.scala | 127 +++++++++++++++++----
4 files changed, 215 insertions(+), 44 deletions(-)
diff --git a/daffodil-japi/src/main/scala/org/apache/daffodil/japi/Daffodil.scala b/daffodil-japi/src/main/scala/org/apache/daffodil/japi/Daffodil.scala
index 0ab4db6..2a77ddf 100644
--- a/daffodil-japi/src/main/scala/org/apache/daffodil/japi/Daffodil.scala
+++ b/daffodil-japi/src/main/scala/org/apache/daffodil/japi/Daffodil.scala
@@ -302,7 +302,8 @@ class ProcessorFactory private[japi] (pf: SProcessorFactory)
* functions in [[WithDiagnostics]], is invalid and will result in an
* Exception.
*/
-abstract class WithDiagnostics private[japi] (wd: SWithDiagnostics) {
+abstract class WithDiagnostics private[japi] (wd: SWithDiagnostics)
+ extends Serializable {
/**
* Determine if any errors occurred in the creation of the parent object.
@@ -419,7 +420,8 @@ class LocationInSchemaFile private[japi] (lsf: SLocationInSchemaFile) {
* Compiled version of a DFDL Schema, used to parse data and get the DFDL infoset
*/
class DataProcessor private[japi] (dp: SDataProcessor)
- extends WithDiagnostics(dp) {
+ extends WithDiagnostics(dp)
+ with Serializable {
/**
* Enable/disable debugging.
diff --git a/daffodil-japi/src/test/java/org/apache/daffodil/example/TestJavaAPI.java b/daffodil-japi/src/test/java/org/apache/daffodil/example/TestJavaAPI.java
index c39f595..f28a815 100644
--- a/daffodil-japi/src/test/java/org/apache/daffodil/example/TestJavaAPI.java
+++ b/daffodil-japi/src/test/java/org/apache/daffodil/example/TestJavaAPI.java
@@ -24,6 +24,8 @@ import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.channels.Channels;
@@ -51,7 +53,7 @@ import org.apache.daffodil.japi.io.InputSourceDataInputStream;
public class TestJavaAPI {
- public java.io.File getResource(String resPath) {
+ private java.io.File getResource(String resPath) {
try {
return new java.io.File(this.getClass().getResource(resPath).toURI());
} catch (Exception e) {
@@ -59,8 +61,57 @@ public class TestJavaAPI {
}
}
+ /**
+ * This is a test-only helper function used to serialize and deserialize a
+ * DataProcessor to ensure all JAPI classes that need to extend
+ * Serializable do so appropriately.
+ *
+ * All of the JAPI tests create a DataProcessor. To test that we correctly
+ * made all the necessary changes to make the JAPI DataProcessor
+ * serializable, it is important to serialize and deserialize that
+ * DataProcessor before use in the tests. This function acts as a helper
+ * function to accomplish that task.
+ *
+ * So this functions accepts a DataProcessor, serializes and deserializes
+ * that DataProcessor in memory, and then returns the result. The test
+ * should then use that resulting DataProcessor for the rest of the test.
+ * This function is only used for testing purposes.
+ *
+ * Note that this function contains an ObjectInputStream for
+ * deserialization, but one that is extended to override the resolveClass
+ * function. This override is necessary to work around a bug when running
+ * tests in SBT that causes an incorrect class loader to be used. Normal
+ * users of the Java API should not need this and can serialize/deserialize
+ * as one would normally do with a standard Object{Input,Output}Stream.
+ */
+ private DataProcessor reserializeDataProcessor(DataProcessor dp) throws IOException, ClassNotFoundException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(dp);
+ oos.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bais) {
+ /**
+ * This override is here because of a bug in sbt where the wrong class loader is being
+ * used when deserializing an object.
+ * For more information, see https://github.com/sbt/sbt/issues/163
+ */
+ @Override
+ protected Class resolveClass(java.io.ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+ try {
+ return Class.forName(desc.getName(), false, getClass().getClassLoader());
+ } catch (ClassNotFoundException e) {
+ return super.resolveClass(desc);
+ }
+ }
+ };
+
+ return (DataProcessor)ois.readObject();
+ }
+
@Test
- public void testJavaAPI1() throws IOException {
+ public void testJavaAPI1() throws IOException, ClassNotFoundException {
LogWriterForJAPITest lw = new LogWriterForJAPITest();
DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
@@ -72,8 +123,10 @@ public class TestJavaAPI {
java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
ProcessorFactory pf = c.compileFile(schemaFile);
DataProcessor dp = pf.onPath("/");
+ dp = reserializeDataProcessor(dp);
dp.setDebugger(debugger);
dp.setDebugging(true);
+
java.io.File file = getResource("/test/japi/myData.dat");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
InputSourceDataInputStream dis = new InputSourceDataInputStream(fis);
@@ -199,7 +252,7 @@ public class TestJavaAPI {
}
@Test
- public void testJavaAPI2() throws IOException {
+ public void testJavaAPI2() throws IOException, ClassNotFoundException {
LogWriterForJAPITest lw = new LogWriterForJAPITest();
Daffodil.setLogWriter(lw);
@@ -210,6 +263,8 @@ public class TestJavaAPI {
java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
ProcessorFactory pf = c.compileFile(schemaFile);
DataProcessor dp = pf.onPath("/");
+ dp = reserializeDataProcessor(dp);
+
java.io.File file = getResource("/test/japi/myDataBroken.dat");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
InputSourceDataInputStream dis = new InputSourceDataInputStream(fis);
@@ -252,13 +307,15 @@ public class TestJavaAPI {
* @throws IOException
*/
@Test
- public void testJavaAPI3() throws IOException {
+ public void testJavaAPI3() throws IOException, ClassNotFoundException {
org.apache.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("/");
+ dp = reserializeDataProcessor(dp);
+
java.io.File file = getResource("/test/japi/myData16.dat");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
InputSourceDataInputStream dis = new InputSourceDataInputStream(fis);
@@ -321,13 +378,15 @@ public class TestJavaAPI {
}
@Test
- public void testJavaAPI4b() throws IOException {
+ public void testJavaAPI4b() throws IOException, ClassNotFoundException {
org.apache.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("/");
+ dp = reserializeDataProcessor(dp);
+
java.io.File file = getResource("/test/japi/myData2.dat");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
InputSourceDataInputStream dis = new InputSourceDataInputStream(fis);
@@ -349,7 +408,7 @@ public class TestJavaAPI {
}
@Test
- public void testJavaAPI5() throws IOException {
+ public void testJavaAPI5() throws IOException, ClassNotFoundException {
org.apache.daffodil.japi.Compiler c = Daffodil.compiler();
c.setValidateDFDLSchemas(false);
File schemaFileName = getResource("/test/japi/mySchema3.dfdl.xsd");
@@ -357,6 +416,8 @@ public class TestJavaAPI {
// element
ProcessorFactory pf = c.compileFile(schemaFileName);
DataProcessor dp = pf.onPath("/");
+ dp = reserializeDataProcessor(dp);
+
java.io.File file = getResource("/test/japi/myData3.dat"); // contains 5
// bytes
java.io.FileInputStream fis = new java.io.FileInputStream(file);
@@ -417,7 +478,7 @@ public class TestJavaAPI {
* @throws IOException
*/
@Test
- public void testJavaAPI7() throws IOException {
+ public void testJavaAPI7() throws IOException, ClassNotFoundException {
// 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
@@ -433,6 +494,8 @@ public class TestJavaAPI {
c.setDistinguishedRootNode("TopLevel", null);
ProcessorFactory pf = c.compileFile(schemaFile);
DataProcessor dp = pf.onPath("/");
+ dp = reserializeDataProcessor(dp);
+
java.io.File file = getResource("/test/japi/01very_simple.txt");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
InputSourceDataInputStream dis = new InputSourceDataInputStream(fis);
@@ -464,7 +527,7 @@ public class TestJavaAPI {
* @throws IOException
*/
@Test
- public void testJavaAPI8() throws IOException {
+ public void testJavaAPI8() throws IOException, ClassNotFoundException {
LogWriterForJAPITest lw = new LogWriterForJAPITest();
Daffodil.setLogWriter(lw);
@@ -476,6 +539,8 @@ public class TestJavaAPI {
c.setDistinguishedRootNode("TopLevel2", null);
ProcessorFactory pf = c.compileFile(schemaFile);
DataProcessor dp = pf.onPath("/");
+ dp = reserializeDataProcessor(dp);
+
java.io.File file = getResource("/test/japi/01very_simple.txt");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
InputSourceDataInputStream dis = new InputSourceDataInputStream(fis);
@@ -503,7 +568,7 @@ public class TestJavaAPI {
* error.
*/
@Test
- public void testJavaAPI9() throws IOException {
+ public void testJavaAPI9() throws IOException, ClassNotFoundException {
LogWriterForJAPITest lw = new LogWriterForJAPITest();
Daffodil.setLogWriter(lw);
@@ -515,6 +580,8 @@ public class TestJavaAPI {
c.setDistinguishedRootNode("TopLevel2", null);
ProcessorFactory pf = c.compileFile(schemaFile);
DataProcessor dp = pf.onPath("/");
+ dp = reserializeDataProcessor(dp);
+
java.io.File file = getResource("/test/japi/01very_simple.txt");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
InputSourceDataInputStream dis = new InputSourceDataInputStream(fis);
@@ -553,13 +620,15 @@ public class TestJavaAPI {
* Verify that hidden elements do not appear in the resulting infoset
*/
@Test
- public void testJavaAPI10() throws IOException {
+ public void testJavaAPI10() throws IOException, ClassNotFoundException {
org.apache.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("/");
+ dp = reserializeDataProcessor(dp);
+
java.io.File file = getResource("/test/japi/myData4.dat");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
InputSourceDataInputStream dis = new InputSourceDataInputStream(fis);
@@ -580,13 +649,15 @@ public class TestJavaAPI {
* Verify that nested elements do not appear as duplicates
*/
@Test
- public void testJavaAPI11() throws IOException {
+ public void testJavaAPI11() throws IOException, ClassNotFoundException {
org.apache.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("/");
+ dp = reserializeDataProcessor(dp);
+
java.io.File file = getResource("/test/japi/myData5.dat");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
InputSourceDataInputStream dis = new InputSourceDataInputStream(fis);
@@ -617,7 +688,7 @@ public class TestJavaAPI {
}
@Test
- public void testJavaAPI12() throws IOException {
+ public void testJavaAPI12() throws IOException, ClassNotFoundException {
LogWriterForJAPITest2 lw2 = new LogWriterForJAPITest2();
DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
@@ -630,6 +701,7 @@ public class TestJavaAPI {
java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
ProcessorFactory pf = c.compileFile(schemaFile);
DataProcessor dp = pf.onPath("/");
+ dp = reserializeDataProcessor(dp);
dp.setDebugger(debugger);
dp.setDebugging(true);
@@ -654,7 +726,7 @@ public class TestJavaAPI {
}
@Test
- public void testJavaAPI13() throws IOException {
+ public void testJavaAPI13() throws IOException, ClassNotFoundException {
// Demonstrates here that we can set external variables
// after compilation but before parsing via Compiler.
LogWriterForJAPITest lw = new LogWriterForJAPITest();
@@ -671,6 +743,7 @@ public class TestJavaAPI {
ProcessorFactory pf = c.compileFile(schemaFile);
DataProcessor dp = pf.onPath("/");
+ dp = reserializeDataProcessor(dp);
dp.setDebugger(debugger);
dp.setDebugging(true);
@@ -696,7 +769,7 @@ public class TestJavaAPI {
}
@Test
- public void testJavaAPI14() throws IOException {
+ public void testJavaAPI14() throws IOException, ClassNotFoundException {
// Demonstrates here that we can set external variables
// after compilation but before parsing via DataProcessor.
LogWriterForJAPITest lw = new LogWriterForJAPITest();
@@ -711,9 +784,10 @@ public class TestJavaAPI {
java.io.File schemaFile = getResource("/test/japi/mySchemaWithVars.dfdl.xsd");
ProcessorFactory pf = c.compileFile(schemaFile);
DataProcessor dp = pf.onPath("/");
+ dp.setExternalVariables(extVarFile);
+ dp = reserializeDataProcessor(dp);
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);
@@ -744,7 +818,7 @@ public class TestJavaAPI {
}
@Test
- public void testJavaAPI15() throws IOException {
+ public void testJavaAPI15() throws IOException, ClassNotFoundException {
LogWriterForJAPITest lw = new LogWriterForJAPITest();
Daffodil.setLogWriter(lw);
@@ -755,6 +829,8 @@ public class TestJavaAPI {
java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
ProcessorFactory pf = c.compileFile(schemaFile);
DataProcessor dp = pf.onPath("/");
+ dp = reserializeDataProcessor(dp);
+
java.io.File file = getResource("/test/japi/myInfosetBroken.xml");
org.jdom2.input.SAXBuilder builder = new org.jdom2.input.SAXBuilder();
@@ -784,13 +860,15 @@ public class TestJavaAPI {
}
@Test
- public void testJavaAPI16() throws IOException, InvalidUsageException {
+ public void testJavaAPI16() throws IOException, InvalidUsageException, ClassNotFoundException {
org.apache.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);
+ dp = reserializeDataProcessor(dp);
+
java.io.File file = getResource("/test/japi/myData.dat");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
InputSourceDataInputStream dis = new InputSourceDataInputStream(fis);
@@ -810,13 +888,15 @@ public class TestJavaAPI {
}
@Test
- public void testJavaAPI17() throws IOException, InvalidUsageException {
+ public void testJavaAPI17() throws IOException, InvalidUsageException, ClassNotFoundException {
org.apache.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);
+ dp = reserializeDataProcessor(dp);
+
java.io.File file = getResource("/test/japi/myData.dat");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
InputSourceDataInputStream dis = new InputSourceDataInputStream(fis);
@@ -847,7 +927,7 @@ public class TestJavaAPI {
}
@Test
- public void testJavaAPI18() throws IOException {
+ public void testJavaAPI18() throws IOException, ClassNotFoundException {
// Demonstrate that we can use the API to continue a parse where we left off
org.apache.daffodil.japi.Compiler c = Daffodil.compiler();
c.setValidateDFDLSchemas(false);
@@ -855,6 +935,8 @@ public class TestJavaAPI {
c.setDistinguishedRootNode("e4", null);
ProcessorFactory pf = c.compileFile(schemaFile);
DataProcessor dp = pf.onPath("/");
+ dp = reserializeDataProcessor(dp);
+
java.io.File file = getResource("/test/japi/myData2.dat");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
InputSourceDataInputStream input = new InputSourceDataInputStream(fis);
diff --git a/daffodil-sapi/src/main/scala/org/apache/daffodil/sapi/Daffodil.scala b/daffodil-sapi/src/main/scala/org/apache/daffodil/sapi/Daffodil.scala
index 911e726..6c58e83 100644
--- a/daffodil-sapi/src/main/scala/org/apache/daffodil/sapi/Daffodil.scala
+++ b/daffodil-sapi/src/main/scala/org/apache/daffodil/sapi/Daffodil.scala
@@ -285,7 +285,8 @@ class ProcessorFactory private[sapi] (pf: SProcessorFactory)
* functions in [[WithDiagnostics]], is invalid and will result in an
* Exception.
*/
-abstract class WithDiagnostics private[sapi] (wd: SWithDiagnostics) {
+abstract class WithDiagnostics private[sapi] (wd: SWithDiagnostics)
+ extends Serializable {
/**
* Determine if any errors occurred in the creation of the parent object.
@@ -396,7 +397,8 @@ class LocationInSchemaFile private[sapi] (lsf: SLocationInSchemaFile) {
* Compiled version of a DFDL Schema, used to parse data and get the DFDL infoset
*/
class DataProcessor private[sapi] (dp: SDataProcessor)
- extends WithDiagnostics(dp) {
+ extends WithDiagnostics(dp)
+ with Serializable {
/**
* Enable/disable debugging.
diff --git a/daffodil-sapi/src/test/scala/org/apache/daffodil/example/TestScalaAPI.scala b/daffodil-sapi/src/test/scala/org/apache/daffodil/example/TestScalaAPI.scala
index ba1761d..14305d8 100644
--- a/daffodil-sapi/src/test/scala/org/apache/daffodil/example/TestScalaAPI.scala
+++ b/daffodil-sapi/src/test/scala/org/apache/daffodil/example/TestScalaAPI.scala
@@ -23,10 +23,13 @@ import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
+import java.io.ObjectInputStream
+import java.io.ObjectOutputStream
import java.io.File
import java.nio.channels.Channels
import org.junit.Test
import org.apache.daffodil.sapi.Daffodil
+import org.apache.daffodil.sapi.DataProcessor
import org.apache.daffodil.sapi.ParseResult
import org.apache.daffodil.sapi.logger.ConsoleLogWriter
import org.apache.daffodil.sapi.logger.LogLevel
@@ -38,7 +41,7 @@ import org.apache.daffodil.sapi.io.InputSourceDataInputStream
class TestScalaAPI {
- def getResource(resPath: String): File = {
+ private def getResource(resPath: String): File = {
val f = try {
new File(this.getClass().getResource(resPath).toURI())
} catch {
@@ -47,6 +50,54 @@ class TestScalaAPI {
f
}
+ /**
+ * This is a test-only helper function used to serialize and deserialize a
+ * DataProcessor to ensure all SAPI classes that need to extend
+ * Serializable do so appropriately.
+ *
+ * All of the SAPI tests create a DataProcessor. To test that we correctly
+ * made all the necessary changes to make the SAPI DataProcessor
+ * serializable, it is important to serialize and deserialize that
+ * DataProcessor before use in the tests. This function acts as a helper
+ * function to accomplish that task.
+ *
+ * So this functions accepts a DataProcessor, serializes and deserializes
+ * that DataProcessor in memory, and then returns the result. The test
+ * should then use that resulting DataProcessor for the rest of the test.
+ * This function is only used for testing purposes.
+ *
+ * Note that this function contains an ObjectInputStream for
+ * deserialization, but one that is extended to override the resolveClass
+ * function. This override is necessary to work around a bug when running
+ * tests in SBT that causes an incorrect class loader to be used. Normal
+ * users of the Scala API should not need this and can serialize/deserialize
+ * as one would normally do with a standard Object{Input,Output}Stream.
+ */
+ private def reserializeDataProcessor(dp: DataProcessor): DataProcessor = {
+ val baos = new ByteArrayOutputStream()
+ val oos = new ObjectOutputStream(baos)
+ oos.writeObject(dp)
+ oos.close()
+
+ val bais = new ByteArrayInputStream(baos.toByteArray())
+ val ois = new ObjectInputStream(bais) {
+ /**
+ * This override is here because of a bug in sbt where the wrong class loader is being
+ * used when deserializing an object.
+ * For more information, see https://github.com/sbt/sbt/issues/163
+ */
+ override protected def resolveClass(desc: java.io.ObjectStreamClass): Class[_] = {
+ try {
+ Class.forName(desc.getName, false, getClass.getClassLoader)
+ } catch {
+ case e: ClassNotFoundException => super.resolveClass(desc);
+ }
+ }
+ }
+
+ ois.readObject().asInstanceOf[DataProcessor]
+ }
+
@Test
def testScalaAPI1() {
val lw = new LogWriterForSAPITest()
@@ -59,9 +110,11 @@ class TestScalaAPI {
c.setValidateDFDLSchemas(false)
val schemaFile = getResource("/test/sapi/mySchema1.dfdl.xsd")
val pf = c.compileFile(schemaFile)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ val dp = reserializeDataProcessor(dp1)
dp.setDebugger(debugger)
dp.setDebugging(true)
+
val file = getResource("/test/sapi/myData.dat")
val fis = new java.io.FileInputStream(file)
val input = new InputSourceDataInputStream(fis)
@@ -164,7 +217,9 @@ class TestScalaAPI {
c.setValidateDFDLSchemas(false)
val schemaFile = getResource("/test/sapi/mySchema1.dfdl.xsd")
val pf = c.compileFile(schemaFile)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ val dp = reserializeDataProcessor(dp1)
+
val file = getResource("/test/sapi/myDataBroken.dat")
val fis = new java.io.FileInputStream(file)
val input = new InputSourceDataInputStream(fis)
@@ -206,7 +261,9 @@ class TestScalaAPI {
val schemaFile = getResource("/test/sapi/mySchema3.dfdl.xsd")
val pf = c.compileFile(schemaFile)
pf.setDistinguishedRootNode("e3", null)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ val dp = reserializeDataProcessor(dp1)
+
val file = getResource("/test/sapi/myData16.dat")
val fis = new java.io.FileInputStream(file)
val input = new InputSourceDataInputStream(fis)
@@ -275,7 +332,9 @@ class TestScalaAPI {
val schemaFileName = getResource("/test/sapi/mySchema3.dfdl.xsd")
c.setDistinguishedRootNode("e4", null)
val pf = c.compileFile(schemaFileName)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ val dp = reserializeDataProcessor(dp1)
+
val file = getResource("/test/sapi/myData2.dat")
val fis = new java.io.FileInputStream(file)
val input = new InputSourceDataInputStream(fis)
@@ -304,7 +363,9 @@ class TestScalaAPI {
c.setDistinguishedRootNode("e4", null); // e4 is a 4-byte long string
// element
val pf = c.compileFile(schemaFileName)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ val dp = reserializeDataProcessor(dp1)
+
val file = getResource("/test/sapi/myData3.dat"); // contains 5
// bytes
val fis = new java.io.FileInputStream(file)
@@ -381,7 +442,9 @@ class TestScalaAPI {
val schemaFile = getResource("/test/sapi/TopLevel.dfdl.xsd")
c.setDistinguishedRootNode("TopLevel", null)
val pf = c.compileFile(schemaFile)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ val dp = reserializeDataProcessor(dp1)
+
val file = getResource("/test/sapi/01very_simple.txt")
val fis = new java.io.FileInputStream(file)
val input = new InputSourceDataInputStream(fis)
@@ -424,7 +487,9 @@ class TestScalaAPI {
val schemaFile = getResource("/test/sapi/TopLevel.dfdl.xsd")
c.setDistinguishedRootNode("TopLevel2", null)
val pf = c.compileFile(schemaFile)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ val dp = reserializeDataProcessor(dp1)
+
val file = getResource("/test/sapi/01very_simple.txt")
val fis = new java.io.FileInputStream(file)
val input = new InputSourceDataInputStream(fis)
@@ -463,7 +528,9 @@ class TestScalaAPI {
val schemaFile = getResource("/test/sapi/TopLevel.dfdl.xsd")
c.setDistinguishedRootNode("TopLevel2", null)
val pf = c.compileFile(schemaFile)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ val dp = reserializeDataProcessor(dp1)
+
val file = getResource("/test/sapi/01very_simple.txt")
val fis = new java.io.FileInputStream(file)
val input = new InputSourceDataInputStream(fis)
@@ -507,7 +574,9 @@ class TestScalaAPI {
c.setValidateDFDLSchemas(false)
val schemaFile = getResource("/test/sapi/mySchema4.dfdl.xsd")
val pf = c.compileFile(schemaFile)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ val dp = reserializeDataProcessor(dp1)
+
val file = getResource("/test/sapi/myData4.dat")
val fis = new java.io.FileInputStream(file)
val input = new InputSourceDataInputStream(fis)
@@ -531,7 +600,9 @@ class TestScalaAPI {
c.setValidateDFDLSchemas(false)
val schemaFile = getResource("/test/sapi/mySchema5.dfdl.xsd")
val pf = c.compileFile(schemaFile)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ val dp = reserializeDataProcessor(dp1)
+
val file = getResource("/test/sapi/myData5.dat")
val fis = new java.io.FileInputStream(file)
val input = new InputSourceDataInputStream(fis)
@@ -566,7 +637,9 @@ class TestScalaAPI {
val schemaFile = getResource("/test/sapi/mySchema1.dfdl.xsd")
val pf = c.compileFile(schemaFile)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ val dp = reserializeDataProcessor(dp1)
+
dp.setDebugger(debugger)
dp.setDebugging(true)
val file = getResource("/test/sapi/myData.dat")
@@ -610,7 +683,9 @@ class TestScalaAPI {
c.setExternalDFDLVariables(extVarsFile)
val pf = c.compileFile(schemaFile)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ val dp = reserializeDataProcessor(dp1)
+
dp.setDebugger(debugger)
dp.setDebugging(true)
val file = getResource("/test/sapi/myData.dat")
@@ -647,10 +722,12 @@ class TestScalaAPI {
val extVarFile = getResource("/test/sapi/external_vars_1.xml")
val schemaFile = getResource("/test/sapi/mySchemaWithVars.dfdl.xsd")
val pf = c.compileFile(schemaFile)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ dp1.setExternalVariables(extVarFile)
+ val dp = reserializeDataProcessor(dp1)
+
dp.setDebugger(debugger)
dp.setDebugging(true)
- dp.setExternalVariables(extVarFile)
val file = getResource("/test/sapi/myData.dat")
val fis = new java.io.FileInputStream(file)
@@ -733,9 +810,11 @@ class TestScalaAPI {
c.setValidateDFDLSchemas(false)
val schemaFile = getResource("/test/sapi/mySchema1.dfdl.xsd")
val pf = c.compileFile(schemaFile)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ val dp = reserializeDataProcessor(dp1)
dp.setDebugger(debugger)
dp.setDebugging(true)
+
val file = getResource("/test/sapi/myInfosetBroken.xml")
val xml = scala.xml.XML.loadFile(file)
val bos = new java.io.ByteArrayOutputStream()
@@ -763,8 +842,10 @@ class TestScalaAPI {
c.setValidateDFDLSchemas(false)
val schemaFile = getResource("/test/sapi/mySchema1.dfdl.xsd")
val pf = c.compileFile(schemaFile)
- val dp = pf.onPath("/")
- dp.setValidationMode(ValidationMode.Limited)
+ val dp1 = pf.onPath("/")
+ dp1.setValidationMode(ValidationMode.Limited)
+ val dp = reserializeDataProcessor(dp1)
+
val file = getResource("/test/sapi/myData.dat")
val fis = new java.io.FileInputStream(file)
val input = new InputSourceDataInputStream(fis)
@@ -789,8 +870,10 @@ class TestScalaAPI {
c.setValidateDFDLSchemas(false)
val schemaFile = getResource("/test/sapi/mySchema1.dfdl.xsd")
val pf = c.compileFile(schemaFile)
- val dp = pf.onPath("/")
- dp.setValidationMode(ValidationMode.Full)
+ val dp1 = pf.onPath("/")
+ dp1.setValidationMode(ValidationMode.Full)
+ val dp = reserializeDataProcessor(dp1)
+
val file = getResource("/test/sapi/myData.dat")
val fis = new java.io.FileInputStream(file)
val input = new InputSourceDataInputStream(fis)
@@ -827,7 +910,9 @@ class TestScalaAPI {
val schemaFile = getResource("/test/sapi/mySchema3.dfdl.xsd")
c.setDistinguishedRootNode("e4", null)
val pf = c.compileFile(schemaFile)
- val dp = pf.onPath("/")
+ val dp1 = pf.onPath("/")
+ val dp = reserializeDataProcessor(dp1)
+
val file = getResource("/test/sapi/myData2.dat")
val fis = new java.io.FileInputStream(file)
val input = new InputSourceDataInputStream(fis)