Package org.apache.uima.cas.impl
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
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) AllowPreexistingFS
private StringBuilder
private CASImpl
private int
private TOP
private TypeImpl
This is a list of deferred FSs to be processed.(package private) boolean
private static final int
private static final int
private static final int
(package private) IntVector
private final List
<Runnable_withSaxException> Deferred Set of feature value assignments to do after all FSs are deserialized,private static final int
private int
private static final int
private List
<FSIndexRepository> private boolean
normally false, set true when processing deferred FSs child elements(package private) boolean
local map from xmi:id to FS address, used when merging multiple XMI CASes into one CAS object.private Locator
private int
private int
private boolean
normally false; set true when processing deferred FSsprivate static final int
private XmiSerializationSharedData
private int
Next expected content Values: (*) means valid state for "startElement" * DOC_STATE - start of the XML document * FS_STATE - start of a Feature Structure, or document text element, or the end of the XML input.private final DeferredIndexUpdates
a list by view of FSs to be added to the indexesprivate final DeferredIndexUpdates
a list by view of FSs to be removed from the indexesprivate static final String
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
XmiCasDeserializerHandler
(CASImpl aCAS, boolean lenient, XmiSerializationSharedData sharedData, int mergePoint, AllowPreexistingFS allowPreexistingFS) Creates a SAX handler used for deserializing an XMI CAS. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addFsToXmiId
(TOP fs, int xmiId) private void
addNonsharedFSToEncompassingFSMapping
(TOP nonsharedFS, TOP encompassingFS) private void
addToOutOfTypeSystemData
(XmlElementName xmlElementName, Attributes attrs) void
characters
(char[] chars, int start, int length) private XCASParsingException
createException
(int code) private XCASParsingException
createException
(int code, String arg) private CommonList
createListFromStringValues
(List<String> stringValues, int startPos, EmptyList emptyNode) There are two variants - one for primitives, and one for values which are refs to FS.(package private) CommonList
createListFromStringValues
(List<String> stringValues, EmptyList emptyNode) private CommonArrayFS
createNewArray
(TypeImpl type, List<String> values) Create an array in the CAS.private CommonArrayFS
createOrUpdateArray
(TypeImpl arrayType, List<String> values, int xmiId, CommonArrayFS existingArray) Create or update an array in the CAS If the array is an FSArray, and the elements are not yet deserialized, a lambda expression is put on a "todo" list to be executed after all the FSs are deserialized, to set the value later.private ByteArray
createOrUpdateByteArray
(String hexString, int xmiId, ByteArray existingArray) Create a byte array in the CAS.private CommonList
createOrUpdateList
(TypeImpl listType, List<String> values, int xmiId, CommonList existingList) Called only for non-shared lists where all the list items serialized with the featureprivate void
deserializeFsRef
(String featVal, FeatureImpl fi, TOP fs) private void
doDeferFsOrThrow
(String idStr, String nameSpaceURI, String localName, String qualifiedName, Attributes attrs) private final boolean
void
void
endElement
(String nsURI, String localName, String qualifiedName) void
void
private void
finalizeFSArrayRefValue
(int xmiId, FSArray fsArray, int index) private void
finalizeFSListRefValue
(int xmiId, NonEmptyFSList neNode) private void
finalizeRefValue
(int xmiId, TOP fs, FeatureImpl fi) private TOP
getFsForXmiId
(int xmiId) private FSIndexRepositoryImpl
getIndexRepo
(String sofaXmiIdAsString, int sofaXmiId) private void
handleFeatMultiValue
(TOP fs, FeatureImpl fi, List<String> featVals) private int
called from endElement after collecting non-byte array element instances into a string list for a particular array or list feature (excluding oots and deferred FSs)private void
handleFeatSingleValue
(TOP fs, FeatureImpl fi, String featVal) private int
handleFeatureFromName
(TypeImpl type, TOP fs, String featName, String featVal, boolean isNewFS) Deserialize one feature called from readFS 751 called from processDeferred, to handle features specified as child elementsprivate byte
hexCharToByte
(char c) void
ignorableWhitespace
(char[] arg0, int arg1, int arg2) private boolean
isNewFS
(int id) private TOP
maybeGetFsForXmiId
(int xmiId) private void
maybeSetFsArrayElement
(List<String> values, int i, FSArray fsArray) private void
maybeSetFsListHead
(String featVal, NonEmptyFSList neNode) private String[]
parseArray
(String val) Parse an XMI multi-valued attribute into a String array, by splitting on whitespace.private void
private void
processView
(String sofa, String membersString) Handles the processing of a cas:View element in the XMI.private void
processView
(String sofa, String addmembersString, String delmemberString, String reindexmemberString) Handles the processing of a cas:View element in the XMI.private void
readFS
(String nameSpaceURI, String localName, String qualifiedName, Attributes attrs) Read one FS, create a new FS or update an existing oneprivate void
readFS
(TOP fs, Attributes attrs, boolean isNewFs) private final void
void
void
void
startElement
(String nameSpaceURI, String localName, String qualifiedName, Attributes attrs) private void
updateExistingArray
(List<String> values, CommonArrayFS existingArray) Update existing array.private CommonList
updateExistingList
(List<String> values, CommonList existingList) existingList guaranteed non-null, but could be EmptyList instance values could be null or empty Return the existing list or a replacement for it which might be an emptylistvoid
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, notationDecl, processingInstruction, resolveEntity, skippedEntity, startPrefixMapping, unparsedEntityDecl
-
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
- See Also:
-
locator
-
casBeingFilled
-
state
private int stateNext expected content Values: (*) means valid state for "startElement" * DOC_STATE - start of the XML document * FS_STATE - start of a Feature Structure, or document text element, or the end of the XML input. * FEAT_STATE - features encoded as sub-elements, or end of the Feature Structure FEAT_CONTENT_STATE - the feature value for a feature called via "characters" callback accumulates chars to "buffer" * IGNORING_XMI_ELEMENTS_STATE - REF_FEAT_STATE - inside invalid input: '<'feat href= "#1"). expect only end of element -
buffer
-
currentFs
-
currentType
-
currentArrayId
private int currentArrayId -
currentArrayElements
-
multiValuedFeatures
-
indexRepositories
-
views
-
lenient
boolean lenient -
ignoreDepth
private int ignoreDepth -
nsPrefixToUriMap
-
nextSofaNum
private int nextSofaNum -
mergePoint
private int mergePoint -
outOfTypeSystemElement
-
deferredFSs
This is a list of deferred FSs to be processed. It is added to when a FS which is- a subtype of AnnotationBase
- has its Sofa ref to some XmiId which is unknown at the time
-
deferredFsElement
-
processingDeferredFSs
private boolean processingDeferredFSsnormally false; set true when processing deferred FSs -
isDoingDeferredChildElements
private boolean isDoingDeferredChildElementsnormally false, set true when processing deferred FSs child elements -
localXmiIdToFs
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
a list by view of FSs to be added to the indexes -
toBeRemoved
a list by view of FSs to be removed from the indexes -
fixupToDos
Deferred Set of feature value assignments to do after all FSs are deserialized, -
uimaSerializableFixups
-
-
Constructor Details
-
Method Details
-
resetBuffer
private final void resetBuffer() -
startDocument
- Specified by:
startDocument
in interfaceContentHandler
- Overrides:
startDocument
in classDefaultHandler
- Throws:
SAXException
-
startElement
public void startElement(String nameSpaceURI, String localName, String qualifiedName, Attributes attrs) throws SAXException - Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- 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
- -
-
doDeferFsOrThrow
private void doDeferFsOrThrow(String idStr, String nameSpaceURI, String localName, String qualifiedName, Attributes attrs) throws XCASParsingException - Throws:
XCASParsingException
-
processView
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 sofaXmiIdAsString, int sofaXmiId) throws XCASParsingException - Parameters:
sofaXmiIdAsString
- xmiIdsofaNum
- 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
- Throws:
SAXException
-
emptyVal
-
handleFeatureFromName
private int handleFeatureFromName(TypeImpl type, TOP fs, String featName, String featVal, boolean isNewFS) throws SAXException Deserialize one feature called from readFS 751 called from processDeferred, to handle features specified as child elements- Parameters:
type
- -fs
- the FSfeatName
- the feature namefeatVal
- the value of the featureisNewFS
- 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
-
handleFeatMultiValueFromName
private int handleFeatMultiValueFromName(Type type, TOP fs, String featName, ArrayList<String> featVals) throws SAXException called from endElement after collecting non-byte array element instances into a string list for a particular array or list feature (excluding oots and deferred FSs)- Parameters:
type
- -fs
- -featName
- -featVals
- -- Returns:
- the feature code of the featName arg, or -1 if feature not found (oots) and lenient
- Throws:
SAXException
-
handleFeatSingleValue
- Throws:
SAXException
-
deserializeFsRef
-
parseArray
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
-
handleFeatMultiValue
private void handleFeatMultiValue(TOP fs, FeatureImpl fi, List<String> featVals) throws SAXException - Throws:
SAXException
-
createOrUpdateList
private CommonList createOrUpdateList(TypeImpl listType, List<String> values, int xmiId, CommonList existingList) Called only for non-shared lists where all the list items serialized with the feature- Parameters:
listType
- -values
- - guaranteed to have at least one.existingList
- - the existing list head ref- Returns:
- the existingList or a new list
-
createOrUpdateArray
private CommonArrayFS createOrUpdateArray(TypeImpl arrayType, List<String> values, int xmiId, CommonArrayFS existingArray) throws XCASParsingException Create or update an array in the CAS If the array is an FSArray, and the elements are not yet deserialized, a lambda expression is put on a "todo" list to be executed after all the FSs are deserialized, to set the value later.- Parameters:
arrayType
- CAS type for the arrayvalues
- List of strings, each representing an element in the arrayxmiId
- xmi:id assigned to the array object.existingArray
- preexisting non-shared array when processing a Delta CAS.- Returns:
- the new or updated-existing FS for the array
- Throws:
XCASParsingException
-
createNewArray
Create an array in the CAS.- Parameters:
values
- List of strings, each containing the value of an element of the array.arrayType
- CAS type code for the array- Returns:
- a reference to the array FS
-
updateExistingArray
Update existing array. The size has already been checked to be equal, but could be 0- Parameters:
values
-existingArray
-arrayType
-
-
updateExistingList
existingList guaranteed non-null, but could be EmptyList instance values could be null or empty Return the existing list or a replacement for it which might be an emptylist -
maybeSetFsArrayElement
-
maybeSetFsListHead
-
createListFromStringValues
-
createListFromStringValues
private CommonList createListFromStringValues(List<String> stringValues, int startPos, EmptyList emptyNode) There are two variants - one for primitives, and one for values which are refs to FS. For both variants, the items in the list are always single-reachable from their previous nodes; that is, there are no loops or other sharing of nodes. If there were, this would not be serialized as a simple list of values. For the refs to FS case, the head references cannot be to any node in the list except the 1st one. This is because the other nodes have no xmiIds in the serialized representation. If some reference was to this, then the list would be serialized in the alternate format. For head references to Feature Structures not known (not yet serialized, or out-of-type-system), a null value is used, and a fixupToDos entry is added to fix this up after all Feature Structures have been serialized. (same as FSArray deserialization)- Parameters:
stringValues
- - the primitive values in string representation, or the xmiIds for referencesstartPos
- - where in the list of values to start (in case we're adding to an existing list)emptyNode
- - the last node in the list, the empty node that terminates it- Returns:
- the first node in the list of nodes (could be the empty node for an empty list)
-
createOrUpdateByteArray
private ByteArray createOrUpdateByteArray(String hexString, int xmiId, ByteArray existingArray) throws XCASParsingException Create a byte array in the CAS. Treatment of null and empty. The existing value can be null. - if not null, it has a size(), which may be 0. The incoming values may be: - null - a 0 length string - a string of some length (must be even number of bytes, else an error) If the incoming value is null - return null If the incoming value is 0 length string - return a 0 length ByteArray. If the incoming value's length matches the length of the existing ByteArray, - replace the value. If the incoming value's length doesn't match, return a new ByteArray. Cases: definitions: - non-shared / shared : "non-shared" - meaning it is encoded at the spot of the feature in the serialization - fs already exists, meaning we're updating the array value (delta cas update below the line, by matching xmi:id's ) case 1: the existingArray is null, or the incoming array is null or 0-length string - the incoming array replaces the existing value (if any), including setting it to null. case 1: values are encoded in place at feature reference spot (implies non-shared) - fs exists if lengths the same, update the existing byte array, else throw exception - can't update size of existing one - fs is new make a new one case 2: values are encoded as a separate feature structure - fs exists if lengths the same, update the existing byte array, else throw exception - can't update size of existing one - fs is new make a new one- Parameters:
hexString
- value of the byte array as a hex stringxmiId
- xmiId - this will be -1 if this is a non-shared (encoded locally with the Feature) byte array FS.existingFs
- the existing ByteArrayFS used when processing a Delta CAS.- Returns:
- the new or updated-existing FS for the array
- Throws:
XCASParsingException
-
hexCharToByte
private byte hexCharToByte(char c) -
characters
- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
- Throws:
SAXException
-
endElement
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
- Throws:
SAXException
-
endDocument
- Specified by:
endDocument
in interfaceContentHandler
- Overrides:
endDocument
in classDefaultHandler
- Throws:
SAXException
-
finalizeRefValue
- Throws:
XCASParsingException
-
finalizeFSListRefValue
- Throws:
XCASParsingException
-
finalizeFSArrayRefValue
private void finalizeFSArrayRefValue(int xmiId, FSArray fsArray, int index) throws XCASParsingException - Throws:
XCASParsingException
-
createException
-
createException
-
error
- Specified by:
error
in interfaceErrorHandler
- Overrides:
error
in classDefaultHandler
- Throws:
SAXException
-
fatalError
- Specified by:
fatalError
in interfaceErrorHandler
- Overrides:
fatalError
in classDefaultHandler
- Throws:
SAXException
-
ignorableWhitespace
- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Overrides:
ignorableWhitespace
in classDefaultHandler
- Throws:
SAXException
-
setDocumentLocator
- Specified by:
setDocumentLocator
in interfaceContentHandler
- Overrides:
setDocumentLocator
in classDefaultHandler
-
warning
- Specified by:
warning
in interfaceErrorHandler
- Overrides:
warning
in classDefaultHandler
- Throws:
SAXException
-
addFsToXmiId
-
getFsForXmiId
-
maybeGetFsForXmiId
-
addToOutOfTypeSystemData
private void addToOutOfTypeSystemData(XmlElementName xmlElementName, Attributes attrs) throws XCASParsingException - Throws:
XCASParsingException
-
isNewFS
private boolean isNewFS(int id) -
processDeferredFSs
- Throws:
SAXException
-