Class XmiCasDeserializer.XmiCasDeserializerHandler

java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.apache.uima.cas.impl.XmiCasDeserializer.XmiCasDeserializerHandler
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler
Enclosing class:
XmiCasDeserializer

private class XmiCasDeserializer.XmiCasDeserializerHandler extends DefaultHandler
  • Field Details

    • DOC_STATE

      private static final int DOC_STATE
      See Also:
    • FS_STATE

      private static final int FS_STATE
      See Also:
    • FEAT_STATE

      private static final int FEAT_STATE
      See Also:
    • FEAT_CONTENT_STATE

      private static final int FEAT_CONTENT_STATE
      See Also:
    • IGNORING_XMI_ELEMENTS_STATE

      private static final int IGNORING_XMI_ELEMENTS_STATE
      See Also:
    • REF_FEAT_STATE

      private static final int REF_FEAT_STATE
      See Also:
    • unknownXMLSource

      private static final String unknownXMLSource
      See Also:
    • ID_ATTR_NAME

      private String ID_ATTR_NAME
    • locator

      private Locator locator
    • casBeingFilled

      private CASImpl casBeingFilled
    • deserializedFsAddrs

      private IntVector deserializedFsAddrs
    • fsListNodesFromMultivaluedProperties

      private IntVector fsListNodesFromMultivaluedProperties
    • state

      private int state
    • buffer

      private StringBuffer buffer
    • currentAddr

      private int currentAddr
    • currentType

      private TypeImpl currentType
    • currentArrayId

      private int currentArrayId
    • currentArrayElements

      private List<String> currentArrayElements
    • multiValuedFeatures

      private Map<String,List<String>> multiValuedFeatures
    • sofaTypeCode

      private int sofaTypeCode
    • sofaNumFeatCode

      private int sofaNumFeatCode
    • sofaFeatCode

      private int sofaFeatCode
    • indexRepositories

      private List<FSIndexRepository> indexRepositories
    • views

      private List<CAS> views
    • listUtils

      private ListUtils listUtils
    • featureType

      private int[] featureType
    • lenient

      boolean lenient
    • ignoreDepth

      private int ignoreDepth
    • nsPrefixToUriMap

      private Map<String,String> nsPrefixToUriMap
    • sharedData

      private XmiSerializationSharedData sharedData
    • nextSofaNum

      private int nextSofaNum
    • mergePoint

      private int mergePoint
    • outOfTypeSystemElement

      private XmiSerializationSharedData.OotsElementData outOfTypeSystemElement
    • localXmiIdToFsAddrMap

      private IntRedBlackTree localXmiIdToFsAddrMap
      local map from xmi:id to FS address, used when merging multiple XMI CASes into one CAS object.
    • allowPreexistingFS

      AllowPreexistingFS allowPreexistingFS
    • featsSeen

      IntVector featsSeen
    • disallowedViewMemberEncountered

      boolean disallowedViewMemberEncountered
    • toBeAdded

      private final DeferredIndexUpdates toBeAdded
      a list by view of FSs to be added to the indexes
    • toBeRemoved

      private final DeferredIndexUpdates toBeRemoved
      a list by view of FSs to be removed from the indexes
  • Constructor Details

    • XmiCasDeserializerHandler

      private XmiCasDeserializerHandler(CASImpl aCAS, boolean lenient, XmiSerializationSharedData sharedData, int mergePoint, AllowPreexistingFS allowPreexistingFS)
      Creates a SAX handler used for deserializing an XMI CAS.
      Parameters:
      aCAS - CAS to deserialize into
      lenient - if true, unknown types/features result in an exception. If false, unknown types/features are ignored.
      sharedData - data structure used to allow the XmiCasSerializer and XmiCasDeserializer to share information.
      mergePoint - used to support merging multiple XMI CASes. If the mergePoint is negative, "normal" deserialization will be done, meaning the target CAS will be reset and the entire XMI content will be deserialized. If the mergePoint is nonnegative (including 0), the target CAS will not be reset, and only Feature Structures whose xmi:id is strictly greater than the mergePoint value will be deserialized.
  • Method Details

    • resetBuffer

      private final void resetBuffer()
    • startDocument

      public void startDocument() throws SAXException
      Specified by:
      startDocument in interface ContentHandler
      Overrides:
      startDocument in class DefaultHandler
      Throws:
      SAXException
    • startElement

      public void startElement(String nameSpaceURI, String localName, String qualifiedName, Attributes attrs) throws SAXException
      Specified by:
      startElement in interface ContentHandler
      Overrides:
      startElement in class DefaultHandler
      Throws:
      SAXException
    • readFS

      private void readFS(String nameSpaceURI, String localName, String qualifiedName, Attributes attrs) throws SAXException
      Read one FS, create a new FS or update an existing one
      Parameters:
      nameSpaceURI - -
      localName - -
      qualifiedName - -
      attrs - -
      Throws:
      SAXException - -
    • processView

      private void processView(String sofa, String membersString) throws SAXParseException
      Handles the processing of a cas:View element in the XMI. The cas:View element encodes indexed FSs.
      Parameters:
      sofa - xmi:id of the sofa for this view, null indicates base CAS "view"
      membersString - whitespace-separated string of FS addresses. Each FS is to be added to the specified sofa's index repository The adding takes place after FSs are finalized, to enable checking the sofa refs are OK https://issues.apache.org/jira/browse/UIMA-4099
      Throws:
      SAXParseException
    • getIndexRepo

      private FSIndexRepositoryImpl getIndexRepo(String sofa, int sofaXmiId) throws XCASParsingException
      Parameters:
      sofaNum - 1 if sofa null, or the sofa Xmi Id
      Returns:
      the FS Repository associated with the sofa xmiId
      Throws:
      XCASParsingException
    • processView

      private void processView(String sofa, String addmembersString, String delmemberString, String reindexmemberString) throws SAXParseException
      Handles the processing of a cas:View element in the XMI. The cas:View element encodes indexed FSs.
      Parameters:
      sofa - xmi:id of the sofa for this view, null indicates base CAS "view"
      membersString - whitespace-separated string of FS addresses. Each FS is to be added to the specified sofa's index repository
      Throws:
      SAXParseException
    • readFS

      private void readFS(int fsAddr, Attributes attrs, boolean isNewFs) throws SAXException
      Throws:
      SAXException
    • emptyVal

      private final boolean emptyVal(String val)
    • handleFeature

      private int handleFeature(Type type, int fsAddr, String featName, String featVal, boolean isNewFS) throws SAXException
      Deserialize one feature
      Parameters:
      type - -
      fsAddr - the address of the FS
      featName - the feature name
      featVal - the value of the feature
      isNewFS - true if this is a new FS
      Returns:
      feature code or -1 if no feature in this type system
      Throws:
      SAXException - if Type doesn't have the feature, and we're not in lenient mode
    • handleFeature

      private int handleFeature(Type type, int addr, String featName, List<String> featVals) throws SAXException
      Throws:
      SAXException
    • handleFeature

      private void handleFeature(int addr, int featCode, String featVal) throws SAXException
      Throws:
      SAXException
    • parseArray

      private String[] parseArray(String val)
      Parse an XMI multi-valued attribute into a String array, by splitting on whitespace.
      Parameters:
      val - XMI attribute value
      Returns:
      an array with each array value as an element
    • handleFeature

      private void handleFeature(int addr, int featCode, List<String> featVals) throws SAXException
      Throws:
      SAXException
    • createArray

      private int createArray(int arrayType, List<String> values, int xmiId, int addr)
      Create or update an array in the CAS
      Parameters:
      arrayType - CAS type code for the array
      values - List of strings, each representing an element in the array
      xmiId - xmi:id assigned to the array object.
      addr - address of preexisting non-shared array
      Returns:
    • createNewArray

      private int createNewArray(int arrayType, List<String> values)
      Create an array in the CAS.
      Parameters:
      arrayType - CAS type code for the array
      values - List of strings, each containing the value of an element of the array.
      Returns:
      a reference to the array FS
    • updateExistingArray

      private void updateExistingArray(int arrayType, List<String> values, int casArray)
    • createByteArray

      private int createByteArray(String hexString, int xmiId, int addr)
      Create a byte array in the CAS.
      Parameters:
      hexString - value of the byte array as a hex string
      xmiId - xmiId - this will be -1 if this is a non-shared byte array FS.
      addr - the current address of the non-shared ByteArrayFS used when processing a Delta CAS.
      Returns:
      a reference to the Feature Structure in the CAS
    • hexCharToByte

      private byte hexCharToByte(char c)
    • characters

      public void characters(char[] chars, int start, int length) throws SAXException
      Specified by:
      characters in interface ContentHandler
      Overrides:
      characters in class DefaultHandler
      Throws:
      SAXException
    • isAllWhitespace

      boolean isAllWhitespace(StringBuffer b)
    • endElement

      public void endElement(String nsURI, String localName, String qualifiedName) throws SAXException
      Specified by:
      endElement in interface ContentHandler
      Overrides:
      endElement in class DefaultHandler
      Throws:
      SAXException
    • endDocument

      public void endDocument() throws SAXException
      Specified by:
      endDocument in interface ContentHandler
      Overrides:
      endDocument in class DefaultHandler
      Throws:
      SAXException
    • finalizeFS

      private void finalizeFS(int addr) throws SAXParseException
      Throws:
      SAXParseException
    • remapFSListHeads

      private void remapFSListHeads(int addr) throws SAXParseException
      Throws:
      SAXParseException
    • finalizeArray

      private void finalizeArray(int type, int addr) throws SAXParseException
      Walk an array, remapping IDs. If called on a primitive array,this method does nothing.
      Parameters:
      type - CAS type code for the array
      addr - address of the array
      Throws:
      SAXParseException
    • createException

      private XCASParsingException createException(int code)
    • createException

      private XCASParsingException createException(int code, String arg)
    • error

      public void error(SAXParseException e) throws SAXException
      Specified by:
      error in interface ErrorHandler
      Overrides:
      error in class DefaultHandler
      Throws:
      SAXException
    • fatalError

      public void fatalError(SAXParseException e) throws SAXException
      Specified by:
      fatalError in interface ErrorHandler
      Overrides:
      fatalError in class DefaultHandler
      Throws:
      SAXException
    • ignorableWhitespace

      public void ignorableWhitespace(char[] arg0, int arg1, int arg2) throws SAXException
      Specified by:
      ignorableWhitespace in interface ContentHandler
      Overrides:
      ignorableWhitespace in class DefaultHandler
      Throws:
      SAXException
    • setDocumentLocator

      public void setDocumentLocator(Locator loc)
      Specified by:
      setDocumentLocator in interface ContentHandler
      Overrides:
      setDocumentLocator in class DefaultHandler
    • warning

      public void warning(SAXParseException e) throws SAXException
      Specified by:
      warning in interface ErrorHandler
      Overrides:
      warning in class DefaultHandler
      Throws:
      SAXException
    • classifyType

      private 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 defined on XmiCasSerializer interface.

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

      private void addFsAddrXmiIdMapping(int fsAddr, int xmiId)
    • getFsAddrForXmiId

      private int getFsAddrForXmiId(int xmiId)
    • addToOutOfTypeSystemData

      private void addToOutOfTypeSystemData(XmlElementName xmlElementName, Attributes attrs) throws XCASParsingException
      Throws:
      XCASParsingException
    • addOutOfTypeSystemFeature

      private void addOutOfTypeSystemFeature(XmiSerializationSharedData.OotsElementData ootsElem, String featName, List<String> featVals)
    • isNewFS

      private boolean isNewFS(int id)
    • addNonsharedFSToEncompassingFSMapping

      private void addNonsharedFSToEncompassingFSMapping(int nonsharedFS, int encompassingFS)