Author: schor
Date: Tue Aug 16 21:36:10 2016
New Revision: 1756548

URL: http://svn.apache.org/viewvc?rev=1756548&view=rev
Log:
[UIMA-4685] update CasIOUtils, after some refactoring and pushing down the 
handling of embedded TSI info so all deserializers (not just CasIOUtils) 
properly decode these forms.

Modified:
    
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CASRuntimeException.java
    
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/SerialFormat.java
    
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java
    
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASMgrSerializer.java
    
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CommonSerDes.java
    
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/Serialization.java
    
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java
    
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasLoadMode.java
    
uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties
    
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasIOUtilsTest.java

Modified: 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CASRuntimeException.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CASRuntimeException.java?rev=1756548&r1=1756547&r2=1756548&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CASRuntimeException.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CASRuntimeException.java
 Tue Aug 16 21:36:10 2016
@@ -155,6 +155,9 @@ public class CASRuntimeException extends
    */
        public static final String BLOB_DESERIALIZATION = 
"BLOB_DESERIALIZATION";
 
+       /** Deserializing Compressed Form 6 with CasLoadMode LENIENT, but no 
Type System provided. */
+       public static final String LENIENT_FORM_6_NO_TS = 
"LENIENT_FORM_6_NO_TS";
+       
        /** Error trying to open a stream to Sofa data. */
        public static final String SOFADATASTREAM_ERROR = 
"SOFADATASTREAM_ERROR";
 
@@ -213,6 +216,8 @@ public class CASRuntimeException extends
   /** While FS was in the index, illegal attempt to modify Feature "{0}" which 
is used as a key in one or more indexes; FS = "{1}" */
   public static final String ILLEGAL_FEAT_SET = "ILLEGAL_FEAT_SET";
 
+  /** Lenient deserialization not support for input of type {0}. */
+  public static final String LENIENT_NOT_SUPPORTED = "LENIENT_NOT_SUPPORTED";
   
        public CASRuntimeException() {
                super();

Modified: 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/SerialFormat.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/SerialFormat.java?rev=1756548&r1=1756547&r2=1756548&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/SerialFormat.java 
(original)
+++ 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/SerialFormat.java 
Tue Aug 16 21:36:10 2016
@@ -40,7 +40,7 @@ public enum SerialFormat {
   XMI("xmi"),
 
   /**
-   * Java-serialized CAS without type system, no filtering
+   * Plain custom binary serialized CAS without type system, no filtering
    */
   BINARY("bcas"),
 
@@ -66,14 +66,37 @@ public enum SerialFormat {
 
   /**
    * Java-serialized CAS with type system and index definitions
+   * The Typs System and Index Definition replaces the CAS's when 
deserializing.
    */
   SERIALIZED_TSI("scas"),
 
   /**
-   * Binary compressed CAS with embedded Java-serialized type system
-   * with reachability and type and feature filtering (form 6)
+   * Binary compressed form 6 CAS with embedded type system
+   * representing the type system encoding the serialization
+   *
+   * specifies the type system used for the serialized form
    */
-  COMPRESSED_FILTERED_TSI("bcas");
+  COMPRESSED_FILTERED_TS("bcas"),
+  
+  /** 
+   * Type system and index specification included
+   * used to reinitialize the CAS and 
+   * specifies the type system used for the serialized form
+   */
+  COMPRESSED_FILTERED_TSI("bcas"),
+  
+  /**
+   * Plain custom binary serialized CAS, no filtering, plus serialized TSI
+   *   used to reinitialize the CAS
+   */
+  BINARY_TSI("bcas"),
+  
+  /**
+   * Binary Compressed Form 4, plus serialized TSI
+   *   used to reinitialize the CAS
+   */
+  COMPRESSED_TSI("bcas"),
+  ;
   
   private String defaultFileExtension;
 

Modified: 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java?rev=1756548&r1=1756547&r2=1756548&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java
 Tue Aug 16 21:36:10 2016
@@ -80,6 +80,7 @@ import org.apache.uima.internal.util.Int
 import org.apache.uima.internal.util.rb_trees.Int2IntRBT;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.util.CasLoadMode;
 import org.apache.uima.util.impl.DataIO;
 import org.apache.uima.util.impl.OptimizeStrings;
 import org.apache.uima.util.impl.SerializationMeasures;
@@ -312,7 +313,7 @@ public class BinaryCasSerDes6 {
   /**
    * Things that are used by common routines among serialization and 
deserialization
    */
-  private boolean isTypeMappingCmn;
+  final private boolean isTypeMappingCmn;
   private CasTypeSystemMapper typeMapperCmn;
 
   /*****************************************************
@@ -344,11 +345,17 @@ public class BinaryCasSerDes6 {
 
   final private TypeSystemImpl tgtTs;
 
-  private boolean isTsiIncluded;
+  private boolean isTsIncluded;   // type system used for the serialization
+  private boolean isTsiIncluded;  // types plus index definition, used to 
reset the cas
   
   private TypeInfo typeInfo; // type info for the current type being 
serialized/deserialized
                              // always the "src" typeInfo I think, except for 
compareCas use
   final private CasTypeSystemMapper typeMapper;
+  
+  /**
+   * This is the used version of isTypeMapping, normally == to isTypeMappingCmn
+   *   But compareCASes sets this false temporarily while setting up the 
compare
+   */
   private boolean isTypeMapping;
 
   final private int[] iPrevHeapArray; // index of previous instance of this 
typecode in heap, by typecode
@@ -470,11 +477,24 @@ public class BinaryCasSerDes6 {
    * @param compressStrategy if not null, specifies enum instance for compress 
strategy
    * @throws ResourceInitializationException if the target type system is 
incompatible with the source type system
    */
+   
   public BinaryCasSerDes6(
       AbstractCas aCas,
       MarkerImpl mark,
       TypeSystemImpl tgtTs,
-      boolean storeTSI,      
+      ReuseInfo rfs,
+      boolean doMeasurements,
+      CompressLevel compressLevel, 
+      CompressStrat compressStrategy) throws ResourceInitializationException {
+    this(aCas, mark, tgtTs, false, false, rfs, doMeasurements, compressLevel, 
compressStrategy);
+  }
+   
+  private BinaryCasSerDes6(
+      AbstractCas aCas,
+      MarkerImpl mark,
+      TypeSystemImpl tgtTs,
+      boolean storeTS,
+      boolean storeTSI,
       ReuseInfo rfs,
       boolean doMeasurements,
       CompressLevel compressLevel, 
@@ -494,6 +514,7 @@ public class BinaryCasSerDes6 {
     isDelta = isSerializingDelta = (mark != null);
     typeMapperCmn = typeMapper = ts.getTypeSystemMapper(tgtTs);
     isTypeMappingCmn = isTypeMapping = (null != typeMapper);
+    isTsIncluded = storeTS;
     isTsiIncluded = storeTSI;
     
     heap = cas.getHeap().heap;
@@ -523,13 +544,53 @@ public class BinaryCasSerDes6 {
     this.tgtTs = tgtTs;
   }
   
+  BinaryCasSerDes6(BinaryCasSerDes6 f6, TypeSystemImpl tgtTs) throws 
ResourceInitializationException {
+    cas = f6.cas;
+    
+    this.ts = cas.getTypeSystemImpl();
+    this.mark = f6.mark;
+    if (null != mark && !mark.isValid() ) {
+      throw new CASRuntimeException(
+                CASRuntimeException.INVALID_MARKER, new String[] { "Invalid 
Marker." });
+    }
+
+    this.doMeasurements = f6.doMeasurements;
+    this.sm = doMeasurements ? new SerializationMeasures() : null;
+    
+    isDelta = isSerializingDelta = (mark != null);
+    typeMapperCmn = typeMapper = ts.getTypeSystemMapper(tgtTs);
+    isTypeMappingCmn = isTypeMapping = (null != typeMapper);
+    isTsIncluded = f6.isTsIncluded;
+    isTsiIncluded = f6.isTsiIncluded;
+    
+    heap = cas.getHeap().heap;
+    heapEnd = cas.getHeap().getCellsUsed();
+    heapStart = isSerializingDelta ? mark.getNextFSId() : 0;
+    
+    stringHeapObj = cas.getStringHeap();
+    longHeapObj   = cas.getLongHeap();
+    shortHeapObj  = cas.getShortHeap();
+    byteHeapObj   = cas.getByteHeap();
+       
+    iPrevHeapArray = new int[ts.getTypeArraySize()];
+    prevHeapInstanceWithIntValues = new int[ts.getTypeArraySize()] [];
+
+    this.compressLevel = f6.compressLevel;
+    this.compressStrategy = f6.compressStrategy;
+    reuseInfoProvided = f6.reuseInfoProvided;
+    foundFSs = f6.foundFSs;
+    foundFSsArray = f6.foundFSsArray;
+    fsStartIndexes = f6.fsStartIndexes;
+    this.tgtTs = tgtTs;
+  }
+  
   /**
    * Setup to serialize (not delta) or deserialize (not delta) using binary 
compression, no type mapping but only processing reachable Feature Structures
    * @param cas -
    * @throws ResourceInitializationException never thrown 
    */
   public BinaryCasSerDes6(AbstractCas cas) throws 
ResourceInitializationException {
-    this(cas, null, null, false, null, false, CompressLevel.Default, 
CompressStrat.Default);
+    this(cas, null, null, false, false, null, false, CompressLevel.Default, 
CompressStrat.Default);
   }
   
   /**
@@ -539,7 +600,7 @@ public class BinaryCasSerDes6 {
    * @throws ResourceInitializationException if the target type system is 
incompatible with the source type system
    */
   public BinaryCasSerDes6(AbstractCas cas, TypeSystemImpl tgtTs) throws 
ResourceInitializationException {
-    this(cas, null, tgtTs, false, null, false, CompressLevel.Default, 
CompressStrat.Default);
+    this(cas, null, tgtTs, false, false, null, false, CompressLevel.Default, 
CompressStrat.Default);
   }
 
   /**
@@ -551,7 +612,7 @@ public class BinaryCasSerDes6 {
    * @throws ResourceInitializationException if the target type system is 
incompatible with the source type system
    */
   public BinaryCasSerDes6(AbstractCas cas, MarkerImpl mark, TypeSystemImpl 
tgtTs, ReuseInfo rfs) throws ResourceInitializationException {
-    this(cas, mark, tgtTs, false, rfs, false, CompressLevel.Default, 
CompressStrat.Default);
+    this(cas, mark, tgtTs, false, false, rfs, false, CompressLevel.Default, 
CompressStrat.Default);
   }
   
   /**
@@ -564,7 +625,7 @@ public class BinaryCasSerDes6 {
    * @throws ResourceInitializationException if the target type system is 
incompatible with the source type system
    */
   public BinaryCasSerDes6(AbstractCas cas, MarkerImpl mark, TypeSystemImpl 
tgtTs, ReuseInfo rfs, boolean doMeasurements) throws 
ResourceInitializationException {
-    this(cas, mark, tgtTs, false, rfs, doMeasurements, CompressLevel.Default, 
CompressStrat.Default);
+    this(cas, mark, tgtTs, false, false, rfs, doMeasurements, 
CompressLevel.Default, CompressStrat.Default);
   }
 
   /**
@@ -574,18 +635,19 @@ public class BinaryCasSerDes6 {
    * @throws ResourceInitializationException never thrown
    */
   public BinaryCasSerDes6(AbstractCas cas, ReuseInfo rfs) throws 
ResourceInitializationException {
-    this(cas, null, null, false, rfs, false, CompressLevel.Default, 
CompressStrat.Default);
+    this(cas, null, null, false, false, rfs, false, CompressLevel.Default, 
CompressStrat.Default);
   }
 
   /**
    * Setup to serialize (not delta) or deserialize (maybe delta) using binary 
compression, no type mapping, optionally storing TSI, and only processing 
reachable Feature Structures
    * @param cas -
    * @param rfs -
-   * @param storeTSI -
+   * @param storeTS - 
+   * @param storeTSI - 
    * @throws ResourceInitializationException never thrown
    */
-  public BinaryCasSerDes6(AbstractCas cas, ReuseInfo rfs, boolean storeTSI) 
throws ResourceInitializationException {
-    this(cas, null, null, storeTSI, rfs, false, CompressLevel.Default, 
CompressStrat.Default);
+  public BinaryCasSerDes6(AbstractCas cas, ReuseInfo rfs, boolean storeTS, 
boolean storeTSI) throws ResourceInitializationException {
+    this(cas, null, null, storeTS, storeTSI, rfs, false, 
CompressLevel.Default, CompressStrat.Default);
   }
 
   
/*********************************************************************************************
@@ -606,7 +668,7 @@ public class BinaryCasSerDes6 {
       throw new UnsupportedOperationException("Can't do Delta Serialization 
with different target TS");
     }
 
-    if (isTsiIncluded && (tgtTs != null)) {
+    if (isTsIncluded && (tgtTs != null)) {
       throw new UnsupportedOperationException("Can't store a different target 
TS in the serialized form");
     }
     
@@ -634,12 +696,15 @@ public class BinaryCasSerDes6 {
     .form6()
     .delta(isSerializingDelta)
     .seqVer(0)
-    .typeSystemIncluded(isTsiIncluded)
+    .typeSystemIncluded(isTsIncluded)
+    .typeSystemIndexDefIncluded(isTsiIncluded)
     .write(serializedOut);
  
-    if (isTsiIncluded) {
+    if (isTsIncluded || isTsiIncluded) {
       ObjectOutputStream tsiOS = new ObjectOutputStream(serializedOut);
-      tsiOS.writeObject(Serialization.serializeCASMgr((CASMgr) cas));
+      tsiOS.writeObject(isTsiIncluded 
+                          ? Serialization.serializeCASMgr((CASMgr) cas) 
+                          : 
Serialization.serializeCASMgrTypeSystemOnly((CASMgr) cas));
       tsiOS.flush();
     }
  
@@ -1634,7 +1699,7 @@ public class BinaryCasSerDes6 {
    * @throws IOException -
    */
   public void deserialize(InputStream istream) throws IOException {
-    readHeader(istream);
+    Header h = readHeader(istream);  // side effect, sets deserIn
 
     if (isReadingDelta) {
       if (!reuseInfoProvided) {
@@ -1643,8 +1708,9 @@ public class BinaryCasSerDes6 {
     } else {
       cas.resetNoQuestions();
     }
-
-    deserializeAfterVersion(deserIn, isReadingDelta, AllowPreexistingFS.allow);
+      
+    cas.reinit(h, deserIn, null, CasLoadMode.DEFAULT, this, 
AllowPreexistingFS.allow);
+//    deserializeAfterVersion(deserIn, isReadingDelta, 
AllowPreexistingFS.allow);
   }
   
   /**
@@ -1654,7 +1720,7 @@ public class BinaryCasSerDes6 {
    * @throws IOException passthru
    */
   public void deserialize(InputStream istream, AllowPreexistingFS 
allowPreexistingFS) throws IOException {
-    readHeader(istream);
+    Header h = readHeader(istream);
 
     if (isReadingDelta) {
       if (!reuseInfoProvided) {
@@ -1664,7 +1730,7 @@ public class BinaryCasSerDes6 {
       throw new UnsupportedOperationException("Delta CAS required for this 
call");
     }
 
-    deserializeAfterVersion(deserIn, isReadingDelta, allowPreexistingFS);
+    cas.reinit(h, deserIn, null, CasLoadMode.DEFAULT, this, 
allowPreexistingFS);
   }
   
   
@@ -3568,7 +3634,7 @@ public class BinaryCasSerDes6 {
     }
   }
   
-  private void readHeader(InputStream istream) throws IOException {
+  private Header readHeader(InputStream istream) throws IOException {
     deserIn = CommonSerDes.maybeWrapToDataInputStream(istream);
     Header h = CommonSerDes.readHeader(deserIn);
     if (!h.isCompressed) {
@@ -3581,6 +3647,7 @@ public class BinaryCasSerDes6 {
     }
     
     isReadingDelta = h.isDelta;
+    return h;
   }
   
   /* *******************************************
@@ -3640,4 +3707,11 @@ public class BinaryCasSerDes6 {
     }
     return v.toArray();
   }
+
+  /**
+   * @return the tgtTs
+   */
+  TypeSystemImpl getTgtTs() {
+    return tgtTs;
+  }
 }

Modified: 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASMgrSerializer.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASMgrSerializer.java?rev=1756548&r1=1756547&r2=1756548&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASMgrSerializer.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASMgrSerializer.java
 Tue Aug 16 21:36:10 2016
@@ -59,7 +59,7 @@ public class CASMgrSerializer implements
   // encoded explicitly. I.e., the fact that tokens are in any index that
   // annotations are in is implicit.
 
-  public int[] typeOrder;
+  public int[] typeOrder = null;
 
   /**
    * The index identifiers. Note that more than one identifier can refer to 
the same index.
@@ -511,4 +511,7 @@ public class CASMgrSerializer implements
     return ir;
   }
 
+  public boolean hasIndexRepository() {
+    return this.typeOrder != null;
+  }
 }

Modified: 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CommonSerDes.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CommonSerDes.java?rev=1756548&r1=1756547&r2=1756548&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CommonSerDes.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CommonSerDes.java
 Tue Aug 16 21:36:10 2016
@@ -72,7 +72,8 @@ public class CommonSerDes {
     boolean isV3style;
     boolean form4;
     boolean form6;
-    boolean typeSystemIncluded;
+    boolean typeSystemIncluded;  // for form 6, TS only
+    boolean typeSystemIndexDefIncluded;
     byte seqVersionNbr;
     boolean isV3;
     boolean swap;
@@ -86,6 +87,7 @@ public class CommonSerDes {
     public Header form4() {isCompressed = form4 = true; form6 = false; return 
this; }
     public Header form6() {isCompressed = form6 = true; form4 = false; return 
this; }
     public Header typeSystemIncluded(boolean f) {typeSystemIncluded = f; 
return this; }
+    public Header typeSystemIndexDefIncluded(boolean f) 
{typeSystemIndexDefIncluded = f; return this; }
     public Header seqVer(int v2) { assert (v2 >= 0 && v2 < 256); seqVersionNbr 
= (byte)v2; return this; }
     public Header v3() {isV3 = true; return this; }
     
@@ -94,7 +96,7 @@ public class CommonSerDes {
       v = (!isCompressed && !isDelta) ? 1 : 0;
       if (isDelta) v |= 0x02;
       if (isCompressed) v |= 0x04;
-      if (typeSystemIncluded) v |= 0x08;
+      if (typeSystemIndexDefIncluded) v |= 0x08;
       v |= (seqVersionNbr << 8);
       if (isV3) v |= 0x010000;
       
@@ -132,9 +134,12 @@ public class CommonSerDes {
     public boolean isForm6() {
       return form6;
     }
+    public boolean isTypeSystemIndexDefIncluded() {
+      return typeSystemIndexDefIncluded;
+    }
     public boolean isTypeSystemIncluded() {
       return typeSystemIncluded;
-    }
+    }    
     public byte getSeqVersionNbr() {
       return seqVersionNbr;
     }
@@ -189,7 +194,7 @@ public class CommonSerDes {
     
     h.isDelta = (v & 2) != 0;
     h.isCompressed = (v & 4) != 0;
-    h.typeSystemIncluded = (v & 8) != 0;
+    h.typeSystemIndexDefIncluded = (v & 8) != 0;
     h.seqVersionNbr = (byte) ((v & 0xFF00) >> 8);
    
     if (h.isCompressed) {

Modified: 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/Serialization.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/Serialization.java?rev=1756548&r1=1756547&r2=1756548&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/Serialization.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/Serialization.java
 Tue Aug 16 21:36:10 2016
@@ -95,6 +95,19 @@ public class Serialization {
             .getBaseIndexRepository());
     return ser;
   }
+  
+  /**
+   * Convert a Type System into a 
+   * CASMgrSerializer object which can be serialized
+   * 
+   * @param casMgr the type system and index repo definitions
+   * @return a serializable object version of these
+   */
+  public static CASMgrSerializer serializeCASMgrTypeSystemOnly(CASMgr casMgr) {
+    CASMgrSerializer ser = new CASMgrSerializer();
+    ser.addTypeSystem((TypeSystemImpl) casMgr.getCAS().getTypeSystem());
+    return ser;
+  }
 
   /**
    * Convert a CAS + the type system and index definitions into a
@@ -223,13 +236,14 @@ public class Serialization {
    * 
    * @param cas the CAS to serialize
    * @param out an OutputStream, a DataOutputStream, or a File
-   * @param tgtTypeSystem null or a target TypeSystem, which must be mergable 
with this CAS's type system
+   * @param includeTS true to serialize the type system
+   * @param includeTSI true to serialize the type system and the indexes 
definition
    * @return information to be used on subsequent serializations (to save 
time) or deserializations (for receiving delta CASs), or reserializations (if 
sending delta CASs)
    * @throws IOException if IO exception
    * @throws ResourceInitializationException if target type system is 
incompatible with this CAS's type system
    */  
-  public static ReuseInfo serializeWithCompression(CAS cas, Object out, 
boolean includeTSI) throws IOException, ResourceInitializationException {
-    BinaryCasSerDes6 bcs = new BinaryCasSerDes6(cas, null, includeTSI);
+  public static ReuseInfo serializeWithCompression(CAS cas, Object out, 
boolean includeTS, boolean includeTSI) throws IOException, 
ResourceInitializationException {
+    BinaryCasSerDes6 bcs = new BinaryCasSerDes6(cas, null, includeTS, 
includeTSI);
     bcs.serialize(out);
     return bcs.getReuseInfo();
   }

Modified: 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java?rev=1756548&r1=1756547&r2=1756548&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java 
(original)
+++ 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java 
Tue Aug 16 21:36:10 2016
@@ -37,6 +37,7 @@ import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASRuntimeException;
 import org.apache.uima.cas.SerialFormat;
 import org.apache.uima.cas.admin.CASMgr;
+import org.apache.uima.cas.impl.AllowPreexistingFS;
 import org.apache.uima.cas.impl.CASCompleteSerializer;
 import org.apache.uima.cas.impl.CASImpl;
 import org.apache.uima.cas.impl.CASMgrSerializer;
@@ -44,18 +45,23 @@ import org.apache.uima.cas.impl.CASSeria
 import org.apache.uima.cas.impl.CommonSerDes;
 import org.apache.uima.cas.impl.CommonSerDes.Header;
 import org.apache.uima.cas.impl.Serialization;
-import org.apache.uima.cas.impl.TypeSystemImpl;
-import org.apache.uima.cas.impl.XCASDeserializer;
 import org.apache.uima.cas.impl.XCASSerializer;
-import org.apache.uima.cas.impl.XmiCasDeserializer;
 import org.apache.uima.cas.impl.XmiCasSerializer;
 import org.xml.sax.SAXException;
 
 /**
  * a collection of static methods aimed at making it easy to 
  *  - save and load CASes, and to
- *  - optionally include their Type Systems and index definitions based on 
those type systems (abbreviated TSI). 
+ *  - optionally include their Type Systems (abbreviated TS) 
+ *    and perhaps also their index definitions based on those type systems 
(abbreviated TSI). 
  *
+ *    * The TSI's purpose: these are used to replace a CAS's existing type 
system and index definition.
+ *      
+ *    * The TS's purpose: these are only used with Compressed Form 6 to 
specify the type system used in the serialized data,
+ *      in order to allow deserializing into some other type system in the 
CAS, leniently.
+ *      
+ *      ** Note: this use does **not** replace the CAS's type system, like the 
TSI use does.
+ * 
  * There are several serialization formats supported; these are listed in the 
Java enum SerialFormat, 
  * together with their preferred file extension name.
  * 
@@ -68,17 +74,15 @@ import org.xml.sax.SAXException;
  * If none of these apply, then the first few bytes of the input are examined 
to determine the format.
  * 
  * For loading, the inputs may be supplied as URLs or as InputStream.  
- * You can use Files or Paths by converting these to URLs:
+ * Note: You can use Files or Paths by converting these to URLs:
  *    URL url = a_path.toUri().toURL();
  *    URL url = a_file.toUri().toURL();
  *    
- *  When loading, an optional lenient boolean flag may be specified.  
- *  It is observed only for the XMI and XCAS formats.
- *  If true, then types and/or features being deserialized which don't exist 
in the receiving CAS are silently ignored.
+ * When loading, an optional CasLoadMode enum value may be specified.  See the 
Javadocs for that for details.
  *  
- *  When TSI is saved, it is either saved in the same destination (e.g. file 
or stream), or in a separate one.
- *    - One serialization format, SERIALIZED_TSI, supports saving the TSI in 
the same destination. 
- *      Other formats require the TSI to be saved to a separate OutputStream.
+ * When TS or TSI information is saved, it is either saved in the same 
destination (e.g. file or stream), or in a separate one.
+ *   - The serialization formats ending in _TSI support saving the TSI in the 
same destination. 
+ *     The save APIs for other formats can optionally also save the TSI into a 
separate (second) OutputStream.
  *      
  *  Summary of the APIs for saving:
  *    save(CAS, OutputStream, SerialFormat)
@@ -91,19 +95,22 @@ import org.xml.sax.SAXException;
  *    load(URL        , CAS)
  *    load(InputStream, CAS)
  *    
- *    load(URL        , URL        , CAS, lenient_flag)   - the second URL is 
for loading a separately-stored TSI
- *    load(InputStream, InputStream, CAS, lenient_flag)
+ *    load(URL        , URL        , CAS, CasLoadMode)   - the second URL is 
for loading a separately-stored TSI
+ *    load(InputStream, InputStream, CAS, CasLoadMode)
  *    
- *  You may specify the lenient_flag without the TSI input by setting the TSI 
input argument to null.
- *
+ *  When loading, a TSI or a TS may be available.  If available, it is used 
for one of two purposes:
+ *    - except for Compressed Form 6, it must be a TSI and 
+ *      it is used to reset the CAS to have the specified type system and 
index specification
+ *    - for Compressed Form 6 (only) it is used to specify the type system of 
the serialized data, to enable
+ *      form 6's lenient deserialization. 
  */
 
 public class CasIOUtils {
 
   /**
    * Loads a Cas from a URL source. The format is determined from the file 
extension name and the content.
-   * For formats of type SERIALIZED_TSI, the type system and index definitions 
are reset
-   * Lenient is false; to use lenient loading, use the 4 argument form.
+   * For formats ending with _TSI, the type system and index definitions are 
reset.
+   * CasLoadMode is DEFAULT.  To specify this explicitly, use the 4 argument 
form.
    * 
    * @param casUrl
    *          The url containing the CAS
@@ -115,17 +122,14 @@ public class CasIOUtils {
    */
   public static SerialFormat load(URL casUrl, CAS aCAS) throws IOException {
 
-    return load(casUrl, null, aCAS, false);
+    return load(casUrl, null, aCAS, CasLoadMode.DEFAULT);
   }
 
   /**
-   * Loads a CAS from a URL source. The format is determined from the file 
extension name and the content.
-   * For formats of type SERIALIZED_TSI, the type system and index definitions 
are read from the casUrl source;
-   * the value of tsiInputStream is ignored.    
-   * For other formats, if the tsiUrl is not null, type system and index 
definitions are read from that source.
+   * Loads a CAS from a URL source. The format is determined from the content.
    * 
-   * To specify lenient loading, without specifying an additional type system 
and index definition source, 
-   * pass null for the tsiUrl.
+   * If the value of tsiUrl is non-null, it is read.
+   *   If values from both the tsiUrl and embedded values are available, the 
tsiUrl value is used.    
    * 
    * @param casUrl
    *          The url to deserialize the CAS from
@@ -133,52 +137,23 @@ public class CasIOUtils {
    *          The optional url to deserialize the type system and index 
definitions from
    * @param aCAS
    *          The CAS that should be filled
-   * @param leniently
-   *          for XCAS and XMI formats, ignore feature structures and features 
of non-existing types and/or features.
-   *          ignored for other formats.
+   * @param casLoadMode specifies how to handle reinitialization and lenient 
loading
+   *          see the Javadocs for CasLoadMode
    * @return the SerialFormat of the loaded CAS
-   * @throws IOException
-   *           - Problem loading from given URL
+   * @throws IOException Problem loading
    */
-  public static SerialFormat load(URL casUrl, URL tsiUrl, CAS aCAS, boolean 
leniently)
+  public static SerialFormat load(URL casUrl, URL tsiUrl, CAS aCAS, 
CasLoadMode casLoadMode)
           throws IOException {
-    String path = casUrl.getPath().toLowerCase();
-
-    if (path.endsWith(SerialFormat.XMI.getDefaultFileExtension())) {
-      InputStream casIS = new BufferedInputStream(casUrl.openStream());
-      try {
-        XmiCasDeserializer.deserialize(casIS, aCAS, leniently);
-        return SerialFormat.XMI;
-      } catch (SAXException e) {
-        throw new IOException(e);
-      } finally {
-        closeQuitely(casIS);
-      }
-    }
-    
-    if (path.endsWith(SerialFormat.XCAS.getDefaultFileExtension())
-            || path.endsWith(".xml")) {
-      InputStream casIS = new BufferedInputStream(casUrl.openStream());
-      try {
-        XCASDeserializer.deserialize(casIS, aCAS, leniently);
-        return SerialFormat.XCAS;
-      } catch (SAXException e) {
-        throw new IOException(e);
-      } finally {
-        closeQuitely(casIS);
-      }
-    } 
-  
     InputStream casIS = new BufferedInputStream(casUrl.openStream());
     InputStream tsIS = (tsiUrl == null) ? null : new 
BufferedInputStream(tsiUrl.openStream());
     try {
-      return load(casIS, tsIS, aCAS, leniently);
+      return load(casIS, tsIS, aCAS, casLoadMode);
     } finally {
       closeQuitely(casIS);
       closeQuitely(tsIS);
     }  
   }
-
+  
   /**
    * Loads a Cas from a URL source. The format is determined from the content.
    * For formats of type SERIALIZED_TSI, the type system and index definitions 
are reset.
@@ -193,92 +168,65 @@ public class CasIOUtils {
    *           - Problem loading from given InputStream
    */
   public static SerialFormat load(InputStream casInputStream, CAS aCAS) throws 
IOException {
-    return load(casInputStream, (CASMgrSerializer) null, aCAS, false);
+    return load(casInputStream, null, aCAS, CasLoadMode.DEFAULT);
   }
 
   /**
-   * Loads a CAS from a URL source. The format is determined from the content.
-   * For formats of type SERIALIZED_TSI, the type system and index definitions 
are read from the casUrl source;
+   * Loads a CAS from an Input Stream. The format is determined from the 
content.
+   * For formats of type SERIALIZED_TSI or COMPRESSED_FILTERED_TSI, 
+   * the type system and index definitions are read from the cas input source;
    * the value of tsiInputStream is ignored.
-   * For other formats, if the tsiUrl is not null, type system and index 
definitions are read from that source.
+   * For other formats, if the tsiInputStream is not null, 
+   * type system and index definitions are read from that source.
    * 
-   * To specify lenient loading, without specifying an additional type system 
and index definition source, 
-   * pass null for the tsiInputStream.
-   * 
-   * @param casInputStream
-   *          The input stream containing the CAS.
-   * @param tsiInputStream
-   *          The optional input stream containing the type system. This is 
only used if the
-   *          casInputStream does not already come with an embedded CAS 
configuration.
-   * @param aCAS
-   *          The CAS that should be filled
-   * @param leniently
-   *          for XCAS and XMI formats, ignore feature structures and features 
of non-existing types and/or features.
-   *          ignored for other formats.
-   * @return the SerialFormat of the loaded CAS
-   * @throws IOException
-   *           - Problem loading from given InputStream
-   * @throws IllegalArgumentException
-   *           - when trying to load XCAS
+   * @param casInputStream -
+   * @param tsiInputStream -
+   * @param aCAS -
+   * @return -
+   * @throws IOException -
    */
-  public static SerialFormat load(InputStream casInputStream, InputStream 
tsiInputStream, CAS aCAS,
-          boolean leniently) throws IOException {
-    CASMgrSerializer casMgrSerializer = null; 
-
-    // If there is a TSI specified, load it - we will see later if we actually 
use it.
-    if (tsiInputStream != null) {
-      if (!tsiInputStream.markSupported()) {
-        tsiInputStream = new BufferedInputStream(tsiInputStream);
-      }
-      
-      try {
-        ObjectInputStream is = new ObjectInputStream(tsiInputStream);
-        casMgrSerializer = (CASMgrSerializer) is.readObject();
-      } catch (ClassNotFoundException e) {
-        throw new IOException(e);
-      }    
-    }
+  public static SerialFormat load(InputStream casInputStream, InputStream 
tsiInputStream, CAS aCAS) throws IOException {
+    return load(casInputStream, tsiInputStream, aCAS, CasLoadMode.DEFAULT);
+  }
 
-    return load(casInputStream, casMgrSerializer, aCAS, leniently);
+  public static SerialFormat load(InputStream casInputStream, InputStream 
tsiInputStream, CAS aCAS, boolean leniently) throws IOException {
+    return load(casInputStream, tsiInputStream, aCAS, leniently ? 
CasLoadMode.LENIENT : CasLoadMode.DEFAULT);
   }
 
   /**
-   * Loads a CAS from a URL source. The format is determined from the content. 
For formats of type
-   * SERIALIZED_TSI, the type system and index definitions are read from the 
casUrl source; the
-   * value of tsiInputStream is ignored. For other formats, if the tsiUrl is 
not null, type system
-   * and index definitions are read from that source.
-   * 
-   * To specify lenient loading, without specifying an additional type system 
and index definition
-   * source, pass null for the tsiInputStream.
-   * 
-   * This method avoids the repeated loading of the typesystem and index 
definitions
-   * from a stream when loading many CASes in a row.
+   * Loads a CAS from a URL source. The format is determined from the content.
+   * For formats of type SERIALIZED_TSI or COMPRESSED_FILTERED_TSI, 
+   * the type system and index definitions are read from the cas input source;
+   * the value of tsiInputStream is ignored.
+   * For other formats, if the tsiInputStream is not null, 
+   * type system and index definitions are read from that source.
    * 
    * @param casInputStream
-   *          The input stream containing the CAS.
-   * @param casMgr
-   *          The optional CAS configuration including type system definition 
and index definition
-   *          in form of a {@link CASMgrSerializer}}. This is only used if the
-   *          casInputStream does not already come with an embedded CAS 
configuration.
+   *          The input stream containing the CAS, appropriately buffered.
+   * @param tsiInputStream
+   *          The optional input stream containing the type system, 
appropriately buffered. 
+   *          This is only used if the casInputStream does not already come 
+   *          with an embedded CAS Type System and Index Definition, and is 
non-null.
    * @param aCAS
    *          The CAS that should be filled
-   * @param leniently
-   *          for XCAS and XMI formats, ignore feature structures and features 
of non-existing types
-   *          and/or features. ignored for other formats.
+   * @param casLoadMode specifies loading alternative like lenient and reinit, 
see CasLoadMode.
+   *          For XCAS and XMI formats, ignore feature structures and features 
of non-existing types and/or features.
+   *          For Compressed Form 6, if true, the tsiInputStream is used only 
to supply the Type System for the serialized form;
+   *            the CAS type system is not altered.
+   *          For other formats, ignored.
    * @return the SerialFormat of the loaded CAS
    * @throws IOException
    *           - Problem loading from given InputStream
-   * @throws IllegalArgumentException
-   *           - when trying to load XCAS
    */
-  public static SerialFormat load(InputStream casInputStream, CASMgrSerializer 
casMgr, CAS aCAS,
-          boolean leniently) throws IOException {
+  public static SerialFormat load(InputStream casInputStream, InputStream 
tsiInputStream, CAS aCAS,
+          CasLoadMode casLoadMode) throws IOException {
 
     if (!casInputStream.markSupported()) {
       casInputStream = new BufferedInputStream(casInputStream);
     }
     
     CASImpl casImpl = (CASImpl) aCAS;
+
     // scan the first part of the file for known formats
     casInputStream.mark(6);
     byte[] firstPartOfFile = new byte[6];
@@ -288,49 +236,60 @@ public class CasIOUtils {
 
     if (start.startsWith("<?xml ")) {  // could be XCAS or XMI
       try {
-        return XmlCasDeserializer.deserializeR(casInputStream, aCAS, 
leniently);
+        casImpl.setupCasFromCasMgrSerializer(readCasManager(tsiInputStream));
+        // next call decides on XMI or XCAS via content
+        return XmlCasDeserializer.deserializeR(casInputStream, aCAS, 
casLoadMode == CasLoadMode.LENIENT);
       } catch (SAXException e) {
         throw new UIMARuntimeException(e);
       }
     }
     
+    //  Not an XML file, decode as binary file
     DataInputStream deserIn = 
CommonSerDes.maybeWrapToDataInputStream(casInputStream);
-    if (CommonSerDes.isBinaryHeader(deserIn)) {   
+    if (CommonSerDes.isBinaryHeader(deserIn)) {
+      
+      /*******************************************
+       * Binary, Compressed Binary (form 4 or 6)
+       ******************************************/
       Header h = CommonSerDes.readHeader(deserIn);
-      TypeSystemImpl ts = null;
-      if (h.isTypeSystemIncluded()) { // Load TSI from CAS stream
-        try {
-          ObjectInputStream ois = new ObjectInputStream(deserIn);
-          CASMgrSerializer casMgrSerializer = (CASMgrSerializer) 
ois.readObject();
-          if (!leniently) {
-            casImpl.setupCasFromCasMgrSerializer(casImpl, casMgrSerializer);  
-          } else {
-            ts = casMgrSerializer.getTypeSystem();
-            ts.commit();
-          }
-        } catch (ClassNotFoundException e) {
-          /**Unrecognized serialized CAS format*/
-          throw new 
CASRuntimeException(CASRuntimeException.UNRECOGNIZED_SERIALIZED_CAS_FORMAT);
-        }       
-      }
-      else if (casMgr != null) { // if TSI not in file, maybe set it from 
parameter
-        if (!leniently) {
-          casImpl.setupCasFromCasMgrSerializer(casImpl, casMgr);  
-        } else {
-          ts = casMgr.getTypeSystem();
-          ts.commit();
-        }
-      }
-      return casImpl.reinit(h, casInputStream, ts);
+      return casImpl.reinit(h, casInputStream, readCasManager(tsiInputStream), 
casLoadMode, null, AllowPreexistingFS.allow);
+//      TypeSystemImpl ts = null;
+//      
+//      
+//      if (h.isTypeSystemIncluded() || h.isTypeSystemIndexDefIncluded()) { // 
Load TS from CAS stream
+//        try {
+//          ObjectInputStream ois = new ObjectInputStream(deserIn);
+//          embeddedCasMgrSerializer = (CASMgrSerializer) ois.readObject();
+//        } catch (ClassNotFoundException e) {
+//          /**Unrecognized serialized CAS format*/
+//          throw new 
CASRuntimeException(CASRuntimeException.UNRECOGNIZED_SERIALIZED_CAS_FORMAT);
+//        }
+//      }
+//      
+//      maybeReinit(
+//          (null == casMgrSerializer && h.isTypeSystemIndexDefIncluded()) 
+//            ? embeddedCasMgrSerializer 
+//            : casMgrSerializer, 
+//          casLoadMode, casImpl);
+//        
+//      if (!h.isForm6() && casLoadMode == CasLoadMode.LENIENT) {
+//        /**Lenient deserialization not support for input of type {0}.*/
+//        throw new 
CASRuntimeException(CASRuntimeException.LENIENT_NOT_SUPPORTED, new Object[] 
{h.toString()});
+//      }
+//      
+//      return casImpl.reinit(h, casInputStream, ts);
+
+    
     } else {
-      // is a Java Object serialization, with or without a type system
+      
+      /******************************
+       * Java Object Serialization
+       ******************************/
       ObjectInputStream ois = new ObjectInputStream(casInputStream);
       try {
         Object o = ois.readObject();
         if (o instanceof CASSerializer) {
-          if (casMgr != null) { // maybe install type system and index def  
-            casImpl.setupCasFromCasMgrSerializer(casImpl, casMgr);  
-          }
+          casImpl.setupCasFromCasMgrSerializer(readCasManager(tsiInputStream));
           casImpl.reinit((CASSerializer) o); // deserialize from object
           return SerialFormat.SERIALIZED;
         } else if (o instanceof CASCompleteSerializer) {
@@ -348,7 +307,17 @@ public class CasIOUtils {
     }
   }
 
-
+  
+//  private static CASMgrSerializer maybeGetExternalTSI(InputStream 
tsiInputStream, CASImpl casImpl) throws IOException {
+//    return (tsiInputStream != null) ? readCasManager(tsiInputStream)
+//    CASMgrSerializer casMgrSerializer = null;
+//    if (tsiInputStream != null) {   
+//      casMgrSerializer = readCasManager(tsiInputStream);  
+//      casImpl.setupCasFromCasMgrSerializer(casMgrSerializer);
+//    }  
+//    return casMgrSerializer;
+//  }
+  
   /**
    * Write the CAS in the specified format.
    * 
@@ -407,12 +376,18 @@ public class CasIOUtils {
           serializeWithCompression(aCas, docOS);
           break;
         case COMPRESSED_FILTERED: // Binary compressed CAS (form 6)
-          serializeWithCompression(aCas, docOS, false);
+          serializeWithCompression(aCas, docOS, false, false);
+          break;
+        case COMPRESSED_FILTERED_TS:
+          // Binary compressed CAS (form 6)
+          // ... with embedded Java-serialized type system
+          serializeWithCompression(aCas, docOS, true, false);
+          typeSystemWritten = true; // Embedded type system
           break;
         case COMPRESSED_FILTERED_TSI:
           // Binary compressed CAS (form 6)
           // ... with embedded Java-serialized type system
-          serializeWithCompression(aCas, docOS, true);
+          serializeWithCompression(aCas, docOS, false, true);
           typeSystemWritten = true; // Embedded type system
           break;
         default:
@@ -432,6 +407,24 @@ public class CasIOUtils {
     }
   }
 
+  private static CASMgrSerializer readCasManager(InputStream tsiInputStream) 
throws IOException {
+    try {
+      if (null == tsiInputStream) {
+        return null;
+      }
+      ObjectInputStream is = new ObjectInputStream(tsiInputStream);
+      return (CASMgrSerializer) is.readObject();
+    } catch (ClassNotFoundException e) {
+      throw new IOException(e);
+    }    
+  }
+  
+//  private static void maybeReinit(CASMgrSerializer casMgrSerializer, 
CasLoadMode casLoadMode, CASImpl cas) {
+//    if (casLoadMode == CasLoadMode.REINIT && casMgrSerializer != null) {
+//      cas.setupCasFromCasMgrSerializer(casMgrSerializer);
+//    }
+//  }
+  
   private static void writeJavaObject(Object o, OutputStream aOS) throws 
IOException {
     ObjectOutputStream tsiOS = new ObjectOutputStream(aOS);
     tsiOS.writeObject(o);

Modified: 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasLoadMode.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasLoadMode.java?rev=1756548&r1=1756547&r2=1756548&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasLoadMode.java 
(original)
+++ 
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasLoadMode.java 
Tue Aug 16 21:36:10 2016
@@ -19,33 +19,80 @@
 package org.apache.uima.util;
 
 /**
- * Used with CasIOUtils, maybe elsewhere, to indicate how serialized CASes are 
to be loaded
- * See SerialFormat
+ * Used with CasIOUtils, maybe elsewhere, to indicate how CASes are to be 
loaded or saved.
  * 
+ * TSI = serialized type system and index definitions
+ * TS = serialized type system
  *
+ * TSI can be used to reinitialize the CAS's type system and its index 
definitions.
+ * TS (which can be obtained from TSI) is used only with Compressed form 6 
+ *   to specify the type system used to decode the serialized data.
+ *   
+ * The TS/TSI artifact is self-identifying as to which kind it is, when 
deserializing.
+ * 
+ * TSI and TS can be provided via two sources:
+ *   - embedded in some serialized forms
+ *   - via a separate artifact 
+ * 
+ * If both embedded and separate values are available for TS or TSI, then 
embedded takes precedence, external is ignored,
+ *   except for compressed form 6; in that case, both are used: 
+ *     - external used to reinitialize the CAS's type system and indexes 
definition, and
+ *     - embedded used to decode the serialized data, leniently.
+ *
+ * Compressed form 6 type system for decoding comes from the first one 
available of: 
+ *   - embedded TS or TSI
+ *   - external TS or TSI
+ *   - the receiving CAS's type system 
  */
 public enum CasLoadMode {
 
   /**
-   * If TSI information is available, 
-   *   use it to reinitialize the CAS's type system and index definitions.
-   * If TS information is available, use it with compressed form 6 to do 
lenient deserialization
-   * For XMI and XCAS, require strict matching (not lenient).
-   *   
+   * Default operation:
+   *
+   * If TSI is available, 
+   *   reinitialize the CAS's type system and its indexes definition, except 
for Compressed Form 6, 
+   *     using the first TSI in this list:
+   *       - embedded
+   *       - external
+   *     (to do this for Compressed Form 6, specify REINIT)
+   *     Logic for doing embedded before external:
+   *       Examining each serialized form:
+   *         Java Object:  if embedded is available, it's the right one, a 
different one causes exceptions
+   *         XCas, XMI:  doesn't apply - no way to have embedded
+   *         Form 6 - excluded, anyway, see below
+   *         Form 4 and Binary: these require the serialized type system match 
the CASs, so the embedded one is always right.
+   *     
+   * Compressed Form 6:
+   *   - decoding: use the first type system in this list:
+   *     - embedded TS/TSI
+   *     - external TS/TSI
+   *     - the receiving CAS's type system 
+   *     
+   * For all SerialFormats except Compressed type 6, default is to require 
strict matching (not lenient).
    */
   DEFAULT,
   
   /**
-   * load if possible with out indicating an error if the incoming data has 
types and/or features not in the receiving CAS
-   * For compressed form 6, implies not REINIT.
+   * Same as DEFAULT, except for XMI and XCAS formats:
+   *   Specifies lenient loading for those formats, which means that the 
+   *   load will not indicate an error if the incoming data has types and/or 
features not in the receiving CAS,
+   *   but will instead silently ignore these.
    */
   LENIENT,  
   
   /**
-   * Reinitialize the CAS, discarding its current type system and index 
definitions, and install new versions of these
-   * loaded from the serialized form.
+   * Used for Compressed Form 6 and to .
+   * 
+   * Same as default, except that the internal and / or external TSI is used 
to 
+   *   reinitialize the CAS's type system and its indexes definition, 
+   *   using the first TSI in this list:
+   *     - external (to allow the embedded to specify the decoding type system)
+   *     - embedded (if it is a TSI)
+   *
+   * Decode (same as DEFAULT) 
    * 
    * Error if no TSI information available
    */
-  REINIT, 
+  REINIT,  
+  ;
 }

Modified: 
uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties?rev=1756548&r1=1756547&r2=1756548&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties
 (original)
+++ 
uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties
 Tue Aug 16 21:36:10 2016
@@ -557,6 +557,7 @@ INVALID_FEATURE_PATH = The feature path
 NO_PRIMITIVE_TAIL = The feature path does not end in a primitive valued 
feature.
 BLOB_SERIALIZATION = Error trying to do binary serialization of CAS data and 
write the BLOB to an output stream.
 BLOB_DESERIALIZATION = Error while deserializing binary CAS. {0}.
+LENIENT_FORM_6_NO_TS = Deserializing Compressed Form 6 with CasLoadMode 
LENIENT, but no Type System provided.
 UNRECOGNIZED_SERIALIZED_CAS_FORMAT = Unrecognized serialized CAS format.
 SOFADATASTREAM_ERROR = Error trying to open a stream to Sofa data.
 INVALID_BASE_CAS_METHOD = Can''t call method "{0}" on the base CAS.
@@ -571,3 +572,4 @@ DESERIALIZING_BINARY_INVALID_HEADER = Wh
 DESERIALIZING_COMPRESSED_BINARY_UNSUPPORTED = Using the reinit method to 
deserialize a binary CAS serialized with compressed serialization not supported 
for this case.
 DEREF_FS_OTHER_CAS = Dereferencing a FeatureStructure of a CAS in a different 
CAS''s context. This can happen if you try to set a feature structure reference 
to a value of a feature structure belonging to an entirely different CAS. FS = 
"{0}", CAS = "{1}".
 ILLEGAL_FEAT_SET = While a FeatureStructure was in the index, an illegal 
attempt was made to modify Feature "{0}" which is used as a key in one or more 
indices; the Feature Structure being modified was "{1}".
+LENIENT_NOT_SUPPORTED = Lenient deserialization not support for input of type 
{0}.
\ No newline at end of file

Modified: 
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasIOUtilsTest.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasIOUtilsTest.java?rev=1756548&r1=1756547&r2=1756548&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasIOUtilsTest.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasIOUtilsTest.java
 Tue Aug 16 21:36:10 2016
@@ -104,12 +104,12 @@ public class CasIOUtilsTest extends Test
 
     casToUse.reset();
     try (FileInputStream casInputStream = new FileInputStream(casFile)) {
-      CasIOUtils.load(casInputStream, (CASMgrSerializer) null, casToUse, 
leniently);
+      CasIOUtils.load(casInputStream, null, casToUse, leniently ? 
CasLoadMode.LENIENT : CasLoadMode.DEFAULT);
     }
     assertCorrectlyLoaded(casToUse, leniently);
     
     casToUse.reset();
-    CasIOUtils.load(casFile.toURI().toURL(), null, casToUse, leniently);
+    CasIOUtils.load(casFile.toURI().toURL(), null, casToUse, leniently ? 
CasLoadMode.LENIENT : CasLoadMode.DEFAULT);
     assertCorrectlyLoaded(casToUse, leniently);
   }
   
@@ -134,7 +134,7 @@ public class CasIOUtilsTest extends Test
     CAS casToUse = leniently ? cas2 : cas;
     
     casToUse.reset();
-    CasIOUtils.load(casFile.toURI().toURL(), null, casToUse, leniently);
+    CasIOUtils.load(casFile.toURI().toURL(), null, casToUse, leniently ? 
CasLoadMode.LENIENT : CasLoadMode.DEFAULT);
     assertCorrectlyLoaded(casToUse, leniently);
   }
 
@@ -178,7 +178,7 @@ public class CasIOUtilsTest extends Test
     casToUse.reset();
     
     FileInputStream casInputStream = new FileInputStream(casFile);
-    SerialFormat loadedFormat = CasIOUtils.load(casInputStream, 
(CASMgrSerializer) null, casToUse, leniently);
+    SerialFormat loadedFormat = CasIOUtils.load(casInputStream, null, 
casToUse, leniently ? CasLoadMode.LENIENT : CasLoadMode.DEFAULT);
     casInputStream.close();
     Assert.assertEquals(format, loadedFormat);
     assertCorrectlyLoaded(casToUse, leniently);


Reply via email to