Class CasSerializerSupport.CasDocSerializer

java.lang.Object
org.apache.uima.cas.impl.CasSerializerSupport.CasDocSerializer
Enclosing class:
CasSerializerSupport

public class CasSerializerSupport.CasDocSerializer extends Object
Use an inner class to hold the data for serializing a CAS. Each call to serialize() creates its own instance. package private to allow a test case to access not static to share the logger and the initializing values (could be changed)
  • Field Details

    • cas

      public final CASImpl cas
    • tsi

      public final TypeSystemImpl tsi
    • visited_not_yet_written

      public final PositiveIntSet_impl visited_not_yet_written
      set of FSs that have been enqueued to be serialized Computed during "enqueue" phase, prior to encoding Used to prevent duplicate enqueuing
    • multiRefFSs

      public final PositiveIntSet multiRefFSs
      set of FSs that have multiple references This is for JSON which is computing the multi-refs, not depending on the setting in a feature.
    • previouslySerializedFSs

      public IntVector previouslySerializedFSs
    • modifiedEmbeddedValueFSs

      public IntVector modifiedEmbeddedValueFSs
    • indexedFSs

      public final IntVector[] indexedFSs
    • queue

      private final IntVector queue
    • listUtils

      public final ListUtils listUtils
    • typeCode2namespaceNames

      public XmlElementName[] typeCode2namespaceNames
    • typeUsed

      private final BitSet typeUsed
    • needNameSpaces

      public boolean needNameSpaces
    • nsUriToPrefixMap

      public final Map<String,String> nsUriToPrefixMap
      map from a namespace expanded form to the namespace prefix, to identify potential collisions when generating a namespace string
    • nsPrefixesUsed

      public final Set<String> nsPrefixesUsed
      the set of all namespace prefixes used, to disallow some if they are in use already in set-aside data (xmi serialization) being merged back in
    • marker

      public final MarkerImpl marker
      Used to tell if a FS was created before or after mark.
    • sharedData

      public final XmiSerializationSharedData sharedData
      for Delta serialization, holds the info gathered from deserialization needed for delta serialization and for handling out-of-type-system data for both plain and delta serialization
    • isDelta

      public final boolean isDelta
      Whether the serializer needs to serialize only the deltas, that is, new FSs created after mark represented by Marker object and preexisting FSs and Views that have been modified. Set to true if Marker object is not null and CASImpl object of this serialize matches the CASImpl in Marker object.
    • isFiltering

      public final boolean isFiltering
      Whether the serializer needs to check for filtered-out types/features. Set to true if type system of CAS does not match type system that was passed to constructor of serializer.
    • sortedUsedTypes

      private TypeImpl[] sortedUsedTypes
    • errorHandler

      private final ErrorHandler errorHandler
    • filterTypeSystem

      public TypeSystemImpl filterTypeSystem
    • uniqueStrings

      private final Map<String,String> uniqueStrings
    • isFormattedOutput

      public final boolean isFormattedOutput
    • csss

    • sortFssByType

      public final Comparator<Integer> sortFssByType
      sort a view, by type and then by begin/end asc/des for subtypes of Annotation, then by id
  • Constructor Details

  • Method Details

    • reportMultiRefWarning

      private void reportMultiRefWarning(int featCode) throws SAXException
      Throws:
      SAXException
    • serialize

      public void serialize() throws Exception
      Starts serialization
      Throws:
      Exception - -
    • getSofaAddr

      public int getSofaAddr(int sofaNum)
      Parameters:
      sofaNum - - starts at 1
      Returns:
      the addr of the sofa FS, or 0
    • writeViewsCommons

      public void writeViewsCommons() throws Exception
      Throws:
      Exception
    • getSortedUsedTypes

      public TypeImpl[] getSortedUsedTypes()
    • getUsedTypesIterable

      private Iterable<TypeImpl> getUsedTypesIterable()
    • enqueueIncoming

      private void enqueueIncoming()
      Enqueues all FS that are stored in the sharedData's id map. This map is populated during the previous deserialization. This method is used to make sure that all incoming FS are echoed in the next serialization. It is required if there are out-of-type FSs that are being merged back into the serialized form; those might reference some of these.
    • enqueueIndexed

      private void enqueueIndexed()
      add the indexed FSs onto the indexedFSs by view. add the SofaFSs onto the by-ref queue
    • enqueueNonsharedMultivaluedFS

      private void enqueueNonsharedMultivaluedFS()
      When serializing Delta CAS, enqueue encompassing FS of nonshared multivalued FS that have been modified. The embedded nonshared-multivalued item could be a list or an array
    • enqueueFeaturesOfIndexed

      private void enqueueFeaturesOfIndexed() throws SAXException
      Enqueue everything reachable from features of indexed FSs.
      Throws:
      SAXException
    • enqueueFeaturesOfFSs

      private void enqueueFeaturesOfFSs(IntVector fss) throws SAXException
      Throws:
      SAXException
    • enqueueCommon

      int enqueueCommon(int addr)
    • enqueueCommonWithoutDeltaAndFilteringCheck

      int enqueueCommonWithoutDeltaAndFilteringCheck(int addr)
    • enqueueCommon

      private int enqueueCommon(int addr, boolean doDeltaAndFilteringCheck)
    • enqueueIndexedFs

      void enqueueIndexedFs(int viewNumber, int addr)
    • enqueue

      private void enqueue(int addr) throws SAXException
      Enqueue an FS, and everything reachable from it. This call is recursive with enqueueFeatures, \ and an arbitrary long chain can get stack overflow error. Probably should fix this someday. See https://issues.apache.org/jira/browse/UIMA-106
      Parameters:
      addr - The FS address.
      Throws:
      SAXException
    • isArrayOrList

      boolean isArrayOrList(int typeCode)
    • isArrayType

      private boolean isArrayType(int typeCode)
    • isListType

      private boolean isListType(int typeCode)
    • isListElementsMultiplyReferenced

      private boolean isListElementsMultiplyReferenced(int listNode, int featCode) throws SAXException
      Parameters:
      curNode -
      featCode -
      Returns:
      true if OK, false if found cycle or multi-ref
      Throws:
      SAXException
    • isMultiRef_enqueue

      private boolean isMultiRef_enqueue(int featCode, int featVal, boolean alreadyVisited, boolean isListNode, boolean isListFeat) throws SAXException
      Throws:
      SAXException
    • enqueueFeatures

      private void enqueueFeatures(int addr, int typeCode) throws SAXException
      Enqueue all FSs reachable from features of the given FS.
      Parameters:
      addr - address of an FS
      typeCode - type of the FS
      insideListNode - true iff the enclosing FS (addr) is a list type
      Throws:
      SAXException
    • enqueueFSArrayElements

      private void enqueueFSArrayElements(int addr) throws SAXException
      Enqueues all FS reachable from an FSArray.
      Parameters:
      addr - Address of an FSArray
      Throws:
      SAXException
    • enqueueFSListElements

      private void enqueueFSListElements(int addr) throws SAXException
      Enqueues all FS reachable from an FSList. This does NOT include the list nodes themselves.
      Parameters:
      addr - Address of an FSList
      Throws:
      SAXException
    • encodeIndexed

      public void encodeIndexed() throws Exception
      Throws:
      Exception
    • encodeFSs

      private void encodeFSs(IntVector fss) throws Exception
      Throws:
      Exception
    • encodeQueued

      public void encodeQueued() throws Exception
      Throws:
      Exception
    • compareInts

      private int compareInts(int i1, int i2)
    • compareFeat

      private int compareFeat(int o1, int o2, int featCode)
    • encodeFS

      public void encodeFS(int addr) throws Exception
      Encode an individual FS. Json has 2 encodings For type: "typeName" : [ { "@id" : 123, feat : value .... }, { "@id" : 456, feat : value .... }, ... ], ... For id: "nnnn" : {"@type" : typeName ; feat : value ...} For cases where the top level type is an array or list, there is a generated feature name, "@collection" whose value is the list or array of values associated with that type.
      Parameters:
      addr - The address to be encoded.
      Throws:
      SAXException - passthru
      Exception
    • filterType

      int filterType(int addr)
    • classifyType

      public final int classifyType(int type)
      Classifies a type. This returns an integer code identifying the type as one of the primitive types, one of the array types, one of the list types, or a generic FS type (anything else).

      The LowLevelCAS.ll_getTypeClass(int) method classifies primitives and array types, but does not have a special classification for list types, which we need for XMI serialization. Therefore, in addition to the type codes defined on LowLevelCAS, this method can return one of the type codes TYPE_CLASS_INTLIST, TYPE_CLASS_FLOATLIST, TYPE_CLASS_STRINGLIST, or TYPE_CLASS_FSLIST.

      Parameters:
      type - the type to classify
      Returns:
      one of the TYPE_CLASS codes defined on LowLevelCAS or on this interface.
    • getElementCountForSharedData

      int getElementCountForSharedData()
    • getXmiId

      public String getXmiId(int addr)
      Get the XMI ID to use for an FS.
      Parameters:
      addr - address of FS
      Returns:
      XMI ID. If addr == CASImpl.NULL, returns null
    • getXmiIdAsInt

      public int getXmiIdAsInt(int addr)
    • getNameSpacePrefix

      public String getNameSpacePrefix(String uimaTypeName, String nsUri, int lastDotIndex)
    • getUniqueString

      public String getUniqueString(String s)
    • getTypeNameFromXmlElementName

      public String getTypeNameFromXmlElementName(XmlElementName xe)
    • isStaticMultiRef

      public boolean isStaticMultiRef(int featCode)