Package org.apache.uima.cas.impl
Class XmiCasSerializer
- java.lang.Object
-
- org.apache.uima.cas.impl.XmiCasSerializer
-
public class XmiCasSerializer extends java.lang.Object
CAS serializer for XMI format; writes a CAS in the XML Metadata Interchange (XMI) format. To use, - create an instance of this class, - optionally) configure the instance, and then - call serialize on the instance, optionally passing in additional parameters. After the 1st 2 steps, the serializer instance may be used for multiple calls (on multiple threads) to the 3rd serialize step, if all calls use the same configuration. There are "convenience" static serialize methods that do these three steps for common configurations. Parameters can be configured in the XmiCasSerializer instance (I), and/or as part of the serialize(S) call. The parameters that can be configured are:- (S) The CAS to serialize
- (S) where to put the output - an OutputStream
- (I,S) a type system - (default null) if supplied, it is used to "filter" types and features that are serialized. If provided, only those that exist in the passed in type system are included in the serialization
- (I,S) a flag for prettyprinting - default false (no prettyprinting)
- (I) (optional) If supplied, a map used to generate a "schemaLocation" attribute in the XMI output. This argument must be a map from namespace URIs to the schema location for that namespace URI.
- (S) (optional) if supplied XmiSerializationSharedData representing FeatureStructures that were set aside when deserializing, and are to be "merged" back in when serializing
- (S) a Marker (default: null) if supplied, where the separation between "new" and previously exisiting FeatureStructures are in the CAS; causes "delta" serialization, where only the new and changed FeatureStructures are serialized.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
XmiCasSerializer.XmiDocSerializer
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
CDATA_TYPE
private CasSerializerSupport
css
static java.lang.String
DEFAULT_NAMESPACE_URI
Namespace URI to use for UIMA types that have no namespace (the "default pacakge" in Java)static java.lang.String
ID_ATTR_NAME
static char[]
INT_TO_HEX
private java.util.Map<java.lang.String,java.lang.String>
nsUriToSchemaLocationMap
static java.lang.String
SYSTEM_LINE_FEED
(package private) static char[]
URIPFX
(package private) static char[]
URISFX
static java.lang.String
XMI_NS_PREFIX
static java.lang.String
XMI_NS_URI
static XmlElementName
XMI_TAG
static java.lang.String
XMI_TAG_LOCAL_NAME
static java.lang.String
XMI_TAG_QNAME
static java.lang.String
XMI_VERSION_LOCAL_NAME
static java.lang.String
XMI_VERSION_QNAME
static java.lang.String
XMI_VERSION_VALUE
static java.lang.String
XMLNS_NS_URI
static java.lang.String
XSI_NS_URI
-
Constructor Summary
Constructors Constructor Description XmiCasSerializer(TypeSystem ts)
Creates a new XmiCasSerializer.XmiCasSerializer(TypeSystem ts, java.util.Map<java.lang.String,java.lang.String> nsUriToSchemaLocationMap)
Creates a new XmiCasSerializer.XmiCasSerializer(TypeSystem ts, java.util.Map<java.lang.String,java.lang.String> nsUriToSchemaLocationMap, boolean isFormattedOutput)
Creates a new XmiCasSerializerXmiCasSerializer(TypeSystem ts, UimaContext uimaContext)
Deprecated.UseXmiCasSerializer(TypeSystem)
instead.XmiCasSerializer(TypeSystem ts, UimaContext uimaContext, java.util.Map<java.lang.String,java.lang.String> nsUriToSchemaLocationMap)
Deprecated.UseXmiCasSerializer(TypeSystem, Map)
instead.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
serialize(CAS aCAS, java.io.OutputStream aStream)
Serializes a CAS to an XMI stream.static void
serialize(CAS aCAS, TypeSystem aTargetTypeSystem, java.io.OutputStream aStream)
Serializes a CAS to an XMI stream.static void
serialize(CAS aCAS, TypeSystem aTargetTypeSystem, java.io.OutputStream aStream, boolean aPrettyPrint, XmiSerializationSharedData aSharedData)
Serializes a CAS to an XMI stream.static void
serialize(CAS aCAS, TypeSystem aTargetTypeSystem, java.io.OutputStream aStream, boolean aPrettyPrint, XmiSerializationSharedData aSharedData, Marker aMarker)
Serializes a Delta CAS to an XMI stream.static void
serialize(CAS aCAS, TypeSystem aTargetTypeSystem, java.io.OutputStream aStream, boolean aPrettyPrint, XmiSerializationSharedData aSharedData, Marker aMarker, boolean useXml_1_1)
Serializes a Delta CAS to an XMI stream.void
serialize(CAS cas, org.xml.sax.ContentHandler contentHandler)
Write the CAS data to a SAX content handler.(package private) void
serialize(CAS cas, org.xml.sax.ContentHandler contentHandler, XmiCasSerializer.XmiDocSerializer ser)
void
serialize(CAS cas, org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler)
Write the CAS data to a SAX content handler.void
serialize(CAS cas, org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler, XmiSerializationSharedData sharedData)
Write the CAS data to a SAX content handler.void
serialize(CAS cas, org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler, XmiSerializationSharedData sharedData, Marker marker)
Write the CAS data to a SAX content handler.XmiCasSerializer
setErrorHandler(org.xml.sax.ErrorHandler eh)
set an error handler to receive information about errorsXmiCasSerializer
setFilterTypes(TypeSystemImpl ts)
pass in a type system to use for filtering what gets serialized; only those types and features which are defined this type system are included.XmiCasSerializer
setPrettyPrint(boolean pp)
set or reset the pretty print flag (default is false)
-
-
-
Field Detail
-
URIPFX
static final char[] URIPFX
-
URISFX
static final char[] URISFX
-
CDATA_TYPE
private static final java.lang.String CDATA_TYPE
- See Also:
- Constant Field Values
-
XMLNS_NS_URI
public static final java.lang.String XMLNS_NS_URI
- See Also:
- Constant Field Values
-
XMI_NS_URI
public static final java.lang.String XMI_NS_URI
- See Also:
- Constant Field Values
-
XSI_NS_URI
public static final java.lang.String XSI_NS_URI
- See Also:
- Constant Field Values
-
XMI_NS_PREFIX
public static final java.lang.String XMI_NS_PREFIX
- See Also:
- Constant Field Values
-
ID_ATTR_NAME
public static final java.lang.String ID_ATTR_NAME
- See Also:
- Constant Field Values
-
XMI_TAG_LOCAL_NAME
public static final java.lang.String XMI_TAG_LOCAL_NAME
- See Also:
- Constant Field Values
-
XMI_TAG_QNAME
public static final java.lang.String XMI_TAG_QNAME
- See Also:
- Constant Field Values
-
XMI_TAG
public static final XmlElementName XMI_TAG
-
XMI_VERSION_LOCAL_NAME
public static final java.lang.String XMI_VERSION_LOCAL_NAME
- See Also:
- Constant Field Values
-
XMI_VERSION_QNAME
public static final java.lang.String XMI_VERSION_QNAME
- See Also:
- Constant Field Values
-
XMI_VERSION_VALUE
public static final java.lang.String XMI_VERSION_VALUE
- See Also:
- Constant Field Values
-
DEFAULT_NAMESPACE_URI
public static final java.lang.String DEFAULT_NAMESPACE_URI
Namespace URI to use for UIMA types that have no namespace (the "default pacakge" in Java)- See Also:
- Constant Field Values
-
SYSTEM_LINE_FEED
public static final java.lang.String SYSTEM_LINE_FEED
-
INT_TO_HEX
public static final char[] INT_TO_HEX
-
css
private final CasSerializerSupport css
-
nsUriToSchemaLocationMap
private java.util.Map<java.lang.String,java.lang.String> nsUriToSchemaLocationMap
-
-
Constructor Detail
-
XmiCasSerializer
public XmiCasSerializer(TypeSystem ts)
Creates a new XmiCasSerializer.- Parameters:
ts
- An optional typeSystem (or null) to filter the types that will be serialized. If any CAS that is later passed to theserialize
method that contains types and features that are not in this typesystem, the serialization will not contain instances of those types or values for those features. So this can be used to filter the results of serialization. A null value indicates that all types and features will be serialized.
-
XmiCasSerializer
public XmiCasSerializer(TypeSystem ts, java.util.Map<java.lang.String,java.lang.String> nsUriToSchemaLocationMap)
Creates a new XmiCasSerializer.- Parameters:
ts
- An optional typeSystem (or null) to filter the types that will be serialized. If any CAS that is later passed to theserialize
method that contains types and features that are not in this typesystem, the serialization will not contain instances of those types or values for those features. So this can be used to filter the results of serialization.nsUriToSchemaLocationMap
- Map if supplied, this map is used to generate a "schemaLocation" attribute in the XMI output. This argument must be a map from namespace URIs to the schema location for that namespace URI.
-
XmiCasSerializer
public XmiCasSerializer(TypeSystem ts, java.util.Map<java.lang.String,java.lang.String> nsUriToSchemaLocationMap, boolean isFormattedOutput)
Creates a new XmiCasSerializer- Parameters:
ts
- An optional typeSystem (or null) to filter the types that will be serialized. If any CAS that is later passed to theserialize
method that contains types and features that are not in this typesystem, the serialization will not contain instances of those types or values for those features. So this can be used to filter the results of serialization.nsUriToSchemaLocationMap
- Map if supplied, this map is used to generate a "schemaLocation" attribute in the XMI output. This argument must be a map from namespace URIs to the schema location for that namespace URI.isFormattedOutput
- true makes serialization pretty print
-
XmiCasSerializer
@Deprecated public XmiCasSerializer(TypeSystem ts, UimaContext uimaContext, java.util.Map<java.lang.String,java.lang.String> nsUriToSchemaLocationMap)
Deprecated.UseXmiCasSerializer(TypeSystem, Map)
instead. The UimaContext reference is never used by this implementation.Creates a new XmiCasSerializer.- Parameters:
ts
- An optional typeSystem (or null) to filter the types that will be serialized. If any CAS that is later passed to theserialize
method that contains types and features that are not in this typesystem, the serialization will not contain instances of those types or values for those features. So this can be used to filter the results of serialization.uimaContext
- not usednsUriToSchemaLocationMap
- Map if supplied, this map is used to generate a "schemaLocation" attribute in the XMI output. This argument must be a map from namespace URIs to the schema location for that namespace URI.
-
XmiCasSerializer
@Deprecated public XmiCasSerializer(TypeSystem ts, UimaContext uimaContext)
Deprecated.UseXmiCasSerializer(TypeSystem)
instead. The UimaContext reference is never used by this implementation.Creates a new XmiCasSerializer.- Parameters:
ts
- An optional typeSystem (or null) to filter the types that will be serialized. If any CAS that is later passed to theserialize
method that contains types and features that are not in this typesystem, the serialization will not contain instances of those types or values for those features. So this can be used to filter the results of serialization.uimaContext
- not used
-
-
Method Detail
-
serialize
public static void serialize(CAS aCAS, java.io.OutputStream aStream) throws org.xml.sax.SAXException
Serializes a CAS to an XMI stream.- Parameters:
aCAS
- CAS to serialize.aStream
- output stream to which to write the XMI document- Throws:
org.xml.sax.SAXException
- if a problem occurs during XMI serialization
-
serialize
public static void serialize(CAS aCAS, TypeSystem aTargetTypeSystem, java.io.OutputStream aStream) throws org.xml.sax.SAXException
Serializes a CAS to an XMI stream. Allows a TypeSystem to be specified, to which the produced XMI will conform. Any types or features not in the target type system will not be serialized.- Parameters:
aCAS
- CAS to serialize.aTargetTypeSystem
- type system to which the produced XMI will conform. Any types or features not in the target type system will not be serialized. A null value indicates that all types and features will be serialized.aStream
- output stream to which to write the XMI document- Throws:
org.xml.sax.SAXException
- if a problem occurs during XMI serialization
-
serialize
public static void serialize(CAS aCAS, TypeSystem aTargetTypeSystem, java.io.OutputStream aStream, boolean aPrettyPrint, XmiSerializationSharedData aSharedData) throws org.xml.sax.SAXException
Serializes a CAS to an XMI stream. This version of this method allows many options to be configured.- Parameters:
aCAS
- CAS to serialize.aTargetTypeSystem
- type system to which the produced XMI will conform. Any types or features not in the target type system will not be serialized. A null value indicates that all types and features will be serialized.aStream
- output stream to which to write the XMI documentaPrettyPrint
- if true the XML output will be formatted with newlines and indenting. If false it will be unformatted.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 a problem occurs during XMI serialization
-
serialize
public static void serialize(CAS aCAS, TypeSystem aTargetTypeSystem, java.io.OutputStream aStream, boolean aPrettyPrint, XmiSerializationSharedData aSharedData, Marker aMarker) throws org.xml.sax.SAXException
Serializes a Delta CAS to an XMI stream. This version of this method allows many options to be configured.- Parameters:
aCAS
- CAS to serialize.aTargetTypeSystem
- type system to which the produced XMI will conform. Any types or features not in the target type system will not be serialized. A null value indicates that all types and features will be serialized.aStream
- output stream to which to write the XMI documentaPrettyPrint
- if true the XML output will be formatted with newlines and indenting. If false it will be unformatted.aSharedData
- an optional container for data that is shared between theXmiCasSerializer
and theXmiCasDeserializer
. See the JavaDocs forXmiSerializationSharedData
for details.aMarker
- an optional object that is used to filter and serialize a Delta CAS containing only those FSs and Views created after Marker was set and preexisting FSs and views that were modified. See the JavaDocs forMarker
for details.- Throws:
org.xml.sax.SAXException
- if a problem occurs during XMI serialization
-
serialize
public static void serialize(CAS aCAS, TypeSystem aTargetTypeSystem, java.io.OutputStream aStream, boolean aPrettyPrint, XmiSerializationSharedData aSharedData, Marker aMarker, boolean useXml_1_1) throws org.xml.sax.SAXException
Serializes a Delta CAS to an XMI stream. This version of this method allows many options to be configured.- Parameters:
aCAS
- CAS to serialize.aTargetTypeSystem
- type system to which the produced XMI will conform. Any types or features not in the target type system will not be serialized. A null value indicates that all types and features will be serialized.aStream
- output stream to which to write the XMI documentaPrettyPrint
- if true the XML output will be formatted with newlines and indenting. If false it will be unformatted.aSharedData
- an optional container for data that is shared between theXmiCasSerializer
and theXmiCasDeserializer
. See the JavaDocs forXmiSerializationSharedData
for details.aMarker
- an optional object that is used to filter and serialize a Delta CAS containing only those FSs and Views created after Marker was set and preexisting FSs and views that were modified. See the JavaDocs forMarker
for details.useXml_1_1
- if true, the output serializer is set with the OutputKeys.VERSION to "1.1".- Throws:
org.xml.sax.SAXException
- if a problem occurs during XMI serialization
-
serialize
public void serialize(CAS cas, org.xml.sax.ContentHandler contentHandler) throws org.xml.sax.SAXException
Write the CAS data to a SAX content handler.- Parameters:
cas
- The CAS to be serialized.contentHandler
- The SAX content handler the data is written to.- Throws:
org.xml.sax.SAXException
- if there was a SAX exception
-
serialize
public void serialize(CAS cas, org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler) throws org.xml.sax.SAXException
Write the CAS data to a SAX content handler.- Parameters:
cas
- The CAS to be serialized.contentHandler
- The SAX content handler the data is written to.errorHandler
- the SAX Error Handler to use- Throws:
org.xml.sax.SAXException
- if there was a SAX exception
-
serialize
public void serialize(CAS cas, org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler, XmiSerializationSharedData sharedData) throws org.xml.sax.SAXException
Write the CAS data to a SAX content handler.- Parameters:
cas
- The CAS to be serialized.contentHandler
- The SAX content handler the data is written to.sharedData
- data structure used to allow the XmiCasSerializer and XmiCasDeserializer to share information.errorHandler
- the SAX Error Handler to use- Throws:
org.xml.sax.SAXException
- if there was a SAX exception
-
serialize
public void serialize(CAS cas, org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler, XmiSerializationSharedData sharedData, Marker marker) throws org.xml.sax.SAXException
Write the CAS data to a SAX content handler.- Parameters:
cas
- The CAS to be serialized.contentHandler
- The SAX content handler the data is written to.errorHandler
- the SAX Error Handler to usesharedData
- data structure used to allow the XmiCasSerializer and XmiCasDeserializer to share information.marker
- an object used to filter the FSs and Views to determine if these were created after the mark was set. Used to serialize a Delta CAS consisting of only new FSs and views and preexisting FSs and Views that have been modified.- Throws:
org.xml.sax.SAXException
- if there was a SAX exception
-
serialize
void serialize(CAS cas, org.xml.sax.ContentHandler contentHandler, XmiCasSerializer.XmiDocSerializer ser) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
setPrettyPrint
public XmiCasSerializer setPrettyPrint(boolean pp)
set or reset the pretty print flag (default is false)- Parameters:
pp
- true to do pretty printing of output- Returns:
- the original instance, possibly updated
-
setFilterTypes
public XmiCasSerializer setFilterTypes(TypeSystemImpl ts)
pass in a type system to use for filtering what gets serialized; only those types and features which are defined this type system are included.- Parameters:
ts
- the filter- Returns:
- the original instance, possibly updated
-
setErrorHandler
public XmiCasSerializer setErrorHandler(org.xml.sax.ErrorHandler eh)
set an error handler to receive information about errors- Parameters:
eh
- the error handler- Returns:
- the original instance, possibly updated
-
-