Package org.apache.uima.cas.impl
Class XmiCasDeserializer
- java.lang.Object
-
- org.apache.uima.cas.impl.XmiCasDeserializer
-
public class XmiCasDeserializer extends java.lang.Object
XMI CAS deserializer. Used to read in a CAS from XML Metadata Interchange (XMI) format.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
XmiCasDeserializer.XmiCasDeserializerHandler
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
ID_ATTR_NAME
private static boolean
IS_EXISTING_FS
private static boolean
IS_NEW_FS
private static int
sofaTypeCode
private TypeSystemImpl
ts
private static java.util.regex.Pattern
whiteSpace
private java.util.Map<java.lang.String,java.lang.String>
xmiNamespaceToUimaNamespaceMap
-
Constructor Summary
Constructors Constructor Description XmiCasDeserializer(TypeSystem ts)
XmiCasDeserializer(TypeSystem ts, UimaContext uimaContext)
Create a new deserializer from a type system.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addOutOfTypeSystemAttributes(XmiSerializationSharedData.OotsElementData ootsElem, org.xml.sax.Attributes attrs)
static void
deserialize(java.io.InputStream aStream, CAS aCAS)
Deserializes a CAS from XMI.static void
deserialize(java.io.InputStream aStream, CAS aCAS, boolean aLenient)
Deserializes a CAS from XMI.static void
deserialize(java.io.InputStream aStream, CAS aCAS, boolean aLenient, XmiSerializationSharedData aSharedData)
Deserializes a CAS from XMI.static void
deserialize(java.io.InputStream aStream, CAS aCAS, boolean aLenient, XmiSerializationSharedData aSharedData, int aMergePoint)
Deserializes a CAS from XMI.static void
deserialize(java.io.InputStream aStream, CAS aCAS, boolean aLenient, XmiSerializationSharedData aSharedData, int aMergePoint, AllowPreexistingFS allowPreexistingFS)
Deserializes a CAS from XMI.org.xml.sax.helpers.DefaultHandler
getXmiCasHandler(CAS cas)
Create a default handler for deserializing a CAS from XMI.org.xml.sax.helpers.DefaultHandler
getXmiCasHandler(CAS cas, boolean lenient)
Create a default handler for deserializing a CAS from XMI.org.xml.sax.helpers.DefaultHandler
getXmiCasHandler(CAS cas, boolean lenient, XmiSerializationSharedData sharedData)
Create a default handler for deserializing a CAS from XMI.org.xml.sax.helpers.DefaultHandler
getXmiCasHandler(CAS cas, boolean lenient, XmiSerializationSharedData sharedData, int mergePoint)
Create a default handler for deserializing a CAS from XMI.org.xml.sax.helpers.DefaultHandler
getXmiCasHandler(CAS cas, boolean lenient, XmiSerializationSharedData sharedData, int mergePoint, AllowPreexistingFS allow)
Create a default handler for deserializing a CAS from XMI.private void
report0xmiId()
private java.lang.String
xmiElementName2uimaTypeName(java.lang.String nsUri, java.lang.String localName)
Converts an XMI element name to a UIMA-style dotted type name.
-
-
-
Field Detail
-
IS_NEW_FS
private static final boolean IS_NEW_FS
- See Also:
- Constant Field Values
-
IS_EXISTING_FS
private static final boolean IS_EXISTING_FS
- See Also:
- Constant Field Values
-
sofaTypeCode
private static final int sofaTypeCode
- See Also:
- Constant Field Values
-
whiteSpace
private static final java.util.regex.Pattern whiteSpace
-
ID_ATTR_NAME
private static final java.lang.String ID_ATTR_NAME
- See Also:
- Constant Field Values
-
ts
private TypeSystemImpl ts
-
xmiNamespaceToUimaNamespaceMap
private java.util.Map<java.lang.String,java.lang.String> xmiNamespaceToUimaNamespaceMap
-
-
Constructor Detail
-
XmiCasDeserializer
public XmiCasDeserializer(TypeSystem ts, UimaContext uimaContext)
Create a new deserializer from a type system.Note: all CAS arguments later supplied to
getXCASHandler()
must have this type system as their type system.- Parameters:
ts
- The type system of the CASes to be deserialized.uimaContext
- the UIMA Context to use for the deserialization
-
XmiCasDeserializer
public XmiCasDeserializer(TypeSystem ts)
-
-
Method Detail
-
getXmiCasHandler
public org.xml.sax.helpers.DefaultHandler getXmiCasHandler(CAS cas)
Create a default handler for deserializing a CAS from XMI.- Parameters:
cas
- This CAS will be used to hold the data deserialized from the XMI- Returns:
- The
DefaultHandler
to pass to the SAX parser.
-
getXmiCasHandler
public org.xml.sax.helpers.DefaultHandler getXmiCasHandler(CAS cas, boolean lenient)
Create a default handler for deserializing a CAS from XMI. By default this is not lenient, meaning that if the XMI references Types that are not in the Type System, an Exception will be thrown. UsegetXmiCasHandler(CAS,boolean)
to turn on lenient mode and ignore any unknown types.- Parameters:
cas
- This CAS will be used to hold the data deserialized from the XMIlenient
- if true, unknown Types will be ignored. If false, unknown Types will cause an exception. The default is false.- Returns:
- The
DefaultHandler
to pass to the SAX parser.
-
getXmiCasHandler
public org.xml.sax.helpers.DefaultHandler getXmiCasHandler(CAS cas, boolean lenient, XmiSerializationSharedData sharedData)
Create a default handler for deserializing a CAS from XMI.- Parameters:
cas
- This CAS will be used to hold the data deserialized from the XMIlenient
- if true, unknown Types will be ignored. If false, unknown Types will cause an exception. The default is false.sharedData
- data structure used to allow the XmiCasSerializer and XmiCasDeserializer to share information.- Returns:
- The
DefaultHandler
to pass to the SAX parser.
-
getXmiCasHandler
public org.xml.sax.helpers.DefaultHandler getXmiCasHandler(CAS cas, boolean lenient, XmiSerializationSharedData sharedData, int mergePoint)
Create a default handler for deserializing a CAS from XMI.- Parameters:
cas
- This CAS will be used to hold the data deserialized from the XMIlenient
- if true, unknown Types will be ignored. If false, unknown Types will cause an exception. The default is false.sharedData
- data structure used to allow the XmiCasSerializer and XmiCasDeserializer to share information.mergePoint
- (represented as an xmiId, not an fsAddr) 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.- Returns:
- The
DefaultHandler
to pass to the SAX parser.
-
getXmiCasHandler
public org.xml.sax.helpers.DefaultHandler getXmiCasHandler(CAS cas, boolean lenient, XmiSerializationSharedData sharedData, int mergePoint, AllowPreexistingFS allow)
Create a default handler for deserializing a CAS from XMI. By default this is not lenient, meaning that if the XMI references Types that are not in the Type System, an Exception will be thrown. UsegetXmiCasHandler(CAS,boolean)
to turn on lenient mode and ignore any unknown types.- Parameters:
cas
- This CAS will be used to hold the data deserialized from the XMIlenient
- if true, unknown Types will be ignored. If false, unknown Types will cause an exception. The default is false.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.allow
- indicates what action to do if a pre-existing FS is found- Returns:
- The
DefaultHandler
to pass to the SAX parser.
-
deserialize
public static void deserialize(java.io.InputStream aStream, CAS aCAS) throws org.xml.sax.SAXException, java.io.IOException
Deserializes a CAS from XMI.- Parameters:
aStream
- input stream from which to read the XMI documentaCAS
- CAS into which to deserialize. This CAS must be set up with a type system that is compatible with that in the XMI- Throws:
org.xml.sax.SAXException
- if an XML Parsing error occursjava.io.IOException
- if an I/O failure occurs
-
deserialize
public static void deserialize(java.io.InputStream aStream, CAS aCAS, boolean aLenient) throws org.xml.sax.SAXException, java.io.IOException
Deserializes a CAS from XMI.- Parameters:
aStream
- input stream from which to read the XMI documentaCAS
- CAS into which to deserialize. This CAS must be set up with a type system that is compatible with that in the XMIaLenient
- if true, unknown Types will be ignored. If false, unknown Types will cause an exception. The default is false.- Throws:
org.xml.sax.SAXException
- if an XML Parsing error occursjava.io.IOException
- if an I/O failure occurs
-
deserialize
public static void deserialize(java.io.InputStream aStream, CAS aCAS, boolean aLenient, XmiSerializationSharedData aSharedData) throws org.xml.sax.SAXException, java.io.IOException
Deserializes a CAS from XMI.- Parameters:
aStream
- input stream from which to read the XMI documentaCAS
- CAS into which to deserialize. This CAS must be set up with a type system that is compatible with that in the XMIaLenient
- if true, unknown Types will be ignored. If false, unknown Types will cause an exception. The default is false.aSharedData
- an optional container for data that is shared between theXmiCasSerializer
and theXmiCasDeserializer
. See the JavaDocs forXmiSerializationSharedData
for details.- Throws:
org.xml.sax.SAXException
- if an XML Parsing error occursjava.io.IOException
- if an I/O failure occurs
-
deserialize
public static void deserialize(java.io.InputStream aStream, CAS aCAS, boolean aLenient, XmiSerializationSharedData aSharedData, int aMergePoint) throws org.xml.sax.SAXException, java.io.IOException
Deserializes a CAS from XMI. This version of this method supports merging multiple XMI documents into a single CAS.- Parameters:
aStream
- input stream from which to read the XMI documentaCAS
- CAS into which to deserialize. This CAS must be set up with a type system that is compatible with that in the XMIaLenient
- if true, unknown Types will be ignored. If false, unknown Types will cause an exception. The default is false.aSharedData
- a container for data that is shared between theXmiCasSerializer
and theXmiCasDeserializer
. See the JavaDocs forXmiSerializationSharedData
for details.aMergePoint
- 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.- Throws:
org.xml.sax.SAXException
- if an XML Parsing error occursjava.io.IOException
- if an I/O failure occurs
-
deserialize
public static void deserialize(java.io.InputStream aStream, CAS aCAS, boolean aLenient, XmiSerializationSharedData aSharedData, int aMergePoint, AllowPreexistingFS allowPreexistingFS) throws org.xml.sax.SAXException, java.io.IOException
Deserializes a CAS from XMI. This version of this method supports deserializing XMI document containing only deltas. The Delta CAS XMI is in the same form as a complete CAS XMI but only consists of new and modified FSs and updates to Views. This API is for reducing the overhead associated with serialization when calling a remote service. The service can send back only the deltas which are deserialized into the original outgoing CAS.- Parameters:
aStream
- input stream from which to read the XMI documentaCAS
- CAS into which to deserialize. This CAS must be set up with a type system that is compatible with that in the XMIaLenient
- if true, unknown Types will be ignored. If false, unknown Types will cause an exception. The default is false.aSharedData
- a container for data that is shared between theXmiCasSerializer
and theXmiCasDeserializer
. See the JavaDocs forXmiSerializationSharedData
for details.aMergePoint
- 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.allowPreexistingFS
- used when deserializing delta CAS whether to allow, disallow or ignore elements representign preexisting FSs or preexisting FSs updates in View element. if IGNORE, FSs below the mergePoint are ignored and only new FSs are processed. if ALLOW, FSs below the mergePoint are processed as well as new FSs. if DISALLOW FSs below mergePoint will cause serialization to fail. FSs below the mergePoint referenced in View element will be flagged as an error condition and will not modifiy the CAS being filled and an exception reporting this will be thrown at the end of deserialization.- Throws:
org.xml.sax.SAXException
- if an XML Parsing error occursjava.io.IOException
- if an I/O failure occurs NOTES: It is expected that Delta CAS serialization will serialize modified preexisting FSs first so that disallowed preexisting FSs are detected at the start and the CAS being filled is left untouched. If disallowed prexisting FS is encountered in the View element, the FS is ignored and the deserialization completes but throws an exception at the end. Possible performance issue with StringListFS. When processing String, StringArrayFS and StringListFS features of a preexisting FS, the string value in the CAS is updated only if it is not equal to the incoming string value. Processing of a StringListFS where a new string value has been inserted, all subsequent strings in the list will be updated with new strings.
-
xmiElementName2uimaTypeName
private java.lang.String xmiElementName2uimaTypeName(java.lang.String nsUri, java.lang.String localName) throws org.xml.sax.SAXException
Converts an XMI element name to a UIMA-style dotted type name.- Parameters:
nsUri
- the namespace URI of the XMI elementlocalName
- the local name of the XMI element- Returns:
- the UIMA type name corresponding to the XMI element name
- Throws:
org.xml.sax.SAXException
-
addOutOfTypeSystemAttributes
private void addOutOfTypeSystemAttributes(XmiSerializationSharedData.OotsElementData ootsElem, org.xml.sax.Attributes attrs)
-
report0xmiId
private void report0xmiId()
-
-