You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@daffodil.apache.org by GitBox <gi...@apache.org> on 2019/01/07 16:05:20 UTC

[GitHub] stevedlawrence closed pull request #161: Make the JAPI/SAPI DataProcessors serializable

stevedlawrence closed pull request #161: Make the JAPI/SAPI DataProcessors serializable
URL: https://github.com/apache/incubator-daffodil/pull/161
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 0ab4db6db..2a77ddf5e 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 c39f595bf..f28a815eb 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 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 @@
 
 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 @@
         }
     }
 
+    /**
+     * 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 void testJavaAPI1() throws IOException {
         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 void testJavaAPI1_A_FullFails() throws Exception {
     }
 
     @Test
-    public void testJavaAPI2() throws IOException {
+    public void testJavaAPI2() throws IOException, ClassNotFoundException {
         LogWriterForJAPITest lw = new LogWriterForJAPITest();
 
         Daffodil.setLogWriter(lw);
@@ -210,6 +263,8 @@ public void testJavaAPI2() throws IOException {
         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 void testJavaAPI2() throws IOException {
      * @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 void testJavaAPI3_A() throws Exception {
     }
 
     @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 void testJavaAPI4b() throws IOException {
     }
 
     @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 void testJavaAPI5() throws IOException {
                                                 // 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 void testJavaAPI6() throws IOException {
      * @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 void testJavaAPI7() throws IOException {
         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 void testJavaAPI7() throws IOException {
      * @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 void testJavaAPI8() throws IOException {
         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 void testJavaAPI8() throws IOException {
      * 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 void testJavaAPI9() throws IOException {
         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 void testJavaAPI9() throws IOException {
      * 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 void testJavaAPI10() throws IOException {
      * 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 void testJavaAPI11() throws IOException {
     }
 
     @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 void testJavaAPI12() throws IOException {
         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 void testJavaAPI12() throws IOException {
     }
 
     @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 void testJavaAPI13() throws IOException {
         ProcessorFactory pf = c.compileFile(schemaFile);
 
         DataProcessor dp = pf.onPath("/");
+        dp = reserializeDataProcessor(dp);
         dp.setDebugger(debugger);
         dp.setDebugging(true);
 
@@ -696,7 +769,7 @@ public void testJavaAPI13() throws IOException {
     }
 
     @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 void testJavaAPI14() throws IOException {
         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 void testJavaAPI14() throws IOException {
     }
 
     @Test
-    public void testJavaAPI15() throws IOException {
+    public void testJavaAPI15() throws IOException, ClassNotFoundException {
         LogWriterForJAPITest lw = new LogWriterForJAPITest();
 
         Daffodil.setLogWriter(lw);
@@ -755,6 +829,8 @@ public void testJavaAPI15() throws IOException {
         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 void testJavaAPI15() throws IOException {
     }
 
     @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 void testJavaAPI16() throws IOException, InvalidUsageException {
     }
 
     @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 void testJavaAPI17() throws IOException, InvalidUsageException {
     }
 
     @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 void testJavaAPI18() throws IOException {
       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 911e72651..6c58e839b 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 ba1761de7..14305d81b 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)


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services