org.apache.uima.cas.impl

## 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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `CASImpl` | `cas`
    `TypeSystemImpl` | `filterTypeSystem_inner`
    `List<TOP>[]` | `indexedFSs` Array of Lists of all FS that are indexed in some view (other than sofas).
    `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.
    `boolean` | `isDynamicMultiRef` Set to true for JSON configuration of using dynamic multi-ref detection for arrays and lists
    `boolean` | `isFiltering` Whether the serializer needs to check for filtered-out types/features.
    `boolean` | `isFormattedOutput_inner`
    `MarkerImpl` | `marker` Used to tell if a FS was created before or after mark.
    `List<TOP>` | `modifiedEmbeddedValueFSs`
    `Set<TOP>` | `multiRefFSs` Set of FSs that have multiple references Has an entry for each FS (not just array or list FSs) which is (from some point on) being serialized as a multi-ref, that is, is **not** being serialized (any more) using the special notation for arrays and lists or, for JSON, **not** being serialized using the embedded notation This is for JSON which is computing the multi-refs, not depending on the setting in a feature.
    `boolean` | `needNameSpaces`
    `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
    `Map<String,String>` | `nsUriToPrefixMap` map from a namespace expanded form to the namespace prefix, to identify potential collisions when generating a namespace string
    `List<TOP>` | `previouslySerializedFSs`
    `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
    `Comparator<TOP>` | `sortFssByType` Called for JSon Serialization Sort a view, by type and then by begin/end asc/des for subtypes of Annotation, then by id
    `TypeSystemImpl` | `tsi`
    `org.apache.uima.internal.util.XmlElementName[]` | `typeCode2namespaceNames`
    `Set<TOP>` | `visited_not_yet_written` set of FSs that have been visited and enqueued to be serialized - exception: arrays and lists which are "inline" are put into this set, but are not enqueued to be serialized.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CasDocSerializer(ContentHandler ch, CASImpl cas, XmiSerializationSharedData sharedData, MarkerImpl marker, CasSerializerSupport.CasSerializerSupportSerialize csss)`
    `CasDocSerializer(ContentHandler ch, CASImpl cas, XmiSerializationSharedData sharedData, MarkerImpl marker, CasSerializerSupport.CasSerializerSupportSerialize csss, boolean trackMultiRefs)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `encodeFS(TOP fs)` Encode an individual FS.
    `void` | `encodeIndexed()`
    `void` | `encodeQueued()`
    `String` | `getNameSpacePrefix(String uimaTypeName, String nsUri, int lastDotIndex)`
    `Sofa` | `getSofa(int sofaNum)`
    `TypeImpl[]` | `getSortedUsedTypes()`
    `String` | `getTypeNameFromXmlElementName(org.apache.uima.internal.util.XmlElementName xe)`
    `String` | `getUniqueString(String s)`
    `String` | `getXmiId(TOP fs)` Get the XMI ID to use for an FS.
    `int` | `getXmiIdAsInt(TOP fs)`
    `boolean` | `isStaticMultiRef(FeatureImpl fi)`
    `void` | `serialize()` Starts serialization
    `void` | `writeViewsCommons()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### cas

          public final CASImpl cas

    - #### tsi

          public final TypeSystemImpl tsi

    - #### visited_not_yet_written

          public final Set<TOP> visited_not_yet_written

      set of FSs that have been visited and enqueued to be serialized - exception: arrays and lists which are "inline" are put into this set, but are not enqueued to be serialized. - FSs added to this, during "enqueue" phase, prior to encoding uses: - for Arrays and Lists, used to detect multi-refs - for Lists, used to detect loops - during enqueuing phase, prevent multiple enqueuings - during encoding phase, to prevent multiple encodings Public for use by JsonCasSerializer

    - #### multiRefFSs

          public final Set<TOP> multiRefFSs

      Set of FSs that have multiple references Has an entry for each FS (not just array or list FSs) which is (from some point on) being serialized as a multi-ref, that is, is **not** being serialized (any more) using the special notation for arrays and lists or, for JSON, **not** being serialized using the embedded notation This is for JSON which is computing the multi-refs, not depending on the setting in a feature. This is also for xmi, to enable adding to "queue" (once) for each FSs of this kind. Used: - limit the number of times this is put onto the queue to 1. - skip encoding of items on "queue" if not in this Set (maybe not needed? 8/2017 mis) - serialize if not in indexed set, dynamic ref == true, and in this set (otherwise serialize only from ref)

    - #### isDynamicMultiRef

          public final boolean isDynamicMultiRef

      Set to true for JSON configuration of using dynamic multi-ref detection for arrays and lists

    - #### previouslySerializedFSs

          public List<TOP> previouslySerializedFSs

    - #### modifiedEmbeddedValueFSs

          public List<TOP> modifiedEmbeddedValueFSs

    - #### indexedFSs

          public final List<TOP>[] indexedFSs

      Array of Lists of all FS that are indexed in some view (other than sofas). Array indexed by view.

    - #### typeCode2namespaceNames

          public org.apache.uima.internal.util.XmlElementName[] typeCode2namespaceNames

    - #### 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.

    - #### filterTypeSystem_inner

          public TypeSystemImpl filterTypeSystem_inner

    - #### isFormattedOutput_inner

          public final boolean isFormattedOutput_inner

    - #### sortFssByType

          public final Comparator<TOP> sortFssByType

      Called for JSon Serialization Sort a view, by type and then by begin/end asc/des for subtypes of Annotation, then by id

  - ### Constructor Detail

    - #### CasDocSerializer

          public CasDocSerializer(ContentHandler ch,
                                  CASImpl cas,
                                  XmiSerializationSharedData sharedData,
                                  MarkerImpl marker,
                                  CasSerializerSupport.CasSerializerSupportSerialize csss)

      Parameters:
        `ch` - -
        `cas` - -
        `sharedData` - -
        `marker` - -
        `csss` - -

    - #### CasDocSerializer

          public CasDocSerializer(ContentHandler ch,
                                  CASImpl cas,
                                  XmiSerializationSharedData sharedData,
                                  MarkerImpl marker,
                                  CasSerializerSupport.CasSerializerSupportSerialize csss,
                                  boolean trackMultiRefs)

  - ### Method Detail

    - #### serialize

          public void serialize()
                         throws Exception

      Starts serialization
      Throws:
        `Exception` - -

    - #### getSofa

          public Sofa getSofa(int sofaNum)

      Parameters:
        `sofaNum` - - starts at 1
      Returns:
        the sofa FS, or null

    - #### writeViewsCommons

          public void writeViewsCommons()
                                 throws Exception

      Throws:
        `Exception`

    - #### getSortedUsedTypes

          public TypeImpl[] getSortedUsedTypes()

    - #### encodeIndexed

          public void encodeIndexed()
                             throws Exception

      Throws:
        `Exception`

    - #### encodeQueued

          public void encodeQueued()
                            throws Exception

      Throws:
        `Exception`

    - #### encodeFS

          public void encodeFS(TOP fs)
                        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:
        `fs` - the FS to be encoded.
      Throws:
        `SAXException` - passthru
        `Exception`

    - #### getXmiId

          public String getXmiId(TOP fs)

      Get the XMI ID to use for an FS.
      Parameters:
        `fs` - the FS
      Returns:
        XMI ID or null

    - #### getXmiIdAsInt

          public int getXmiIdAsInt(TOP fs)

    - #### getNameSpacePrefix

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

    - #### getUniqueString

          public String getUniqueString(String s)

    - #### getTypeNameFromXmlElementName

          public String getTypeNameFromXmlElementName(org.apache.uima.internal.util.XmlElementName xe)

    - #### isStaticMultiRef

          public boolean isStaticMultiRef(FeatureImpl fi)

Copyright © 2006–2022 The Apache Software Foundation. All rights reserved.