public final class XmlExport
extends java.lang.Object
Runtime support is partial at this time; not all modes and features are supported.
Modifier and Type | Class and Description |
---|---|
private static interface |
XmlExport.XmlWriter
Implementations of this interface actively write XML /XSD code.
|
Modifier and Type | Field and Description |
---|---|
private static TempTableSchema.Column |
AFTER_ROWID |
private static java.lang.String |
ATTR_NS_XSI
XML namespace attribute
|
private static java.lang.String |
ATTR_XSI_NIL
Nil attribute
|
private static TempTableSchema.Column |
DATASOURCE_ROWID |
private DataSet |
ds
The current
DataSet , if one is processed. |
private java.lang.String |
encoding
Character encoding (not currently used).
|
private static TempTableSchema.Column |
ERROR_FLAG |
private static TempTableSchema.Column |
ERROR_STRING |
private boolean |
format
Flag indicating whether XML output should be pretty-printed
|
private static java.lang.String |
INDENT
The 4GL output files use a 2-space indentation.
|
private int |
indentLevel
The indentation level.
|
private java.util.Map<java.lang.Integer,org.apache.commons.lang3.tuple.Pair<java.lang.String,TableMapper.LegacyIndexInfo>> |
indexes
The list of indexes, in order of their buffers.
|
private boolean |
isSchemaOnly
Flags a
WRITE-XMLSCHEMA method in progress (for both DataSet and
TempTable ). |
private java.util.Set<DataRelation> |
keyrefs
We store here the
DataRelation s which have promoted to xsd:keyref s. |
private static java.lang.String |
lineSep
Platform-specific line separator
|
private static java.lang.String |
NS_URI
Namespace URI for XML schema
|
private static TempTableSchema.Column |
ORIGIN_ROWID |
private java.util.Map<java.lang.String,org.apache.commons.lang3.tuple.Pair<java.lang.String,java.lang.String>> |
prodsErrors
The map with eventual error strings.
|
private static TempTableSchema.Column |
ROW_STATE |
private TargetData |
target
XML data target which normalizes access of various media to an output stream.
|
private java.lang.String |
ttNsPrefix
The namespace prefix for the currently exported temp-table, if any.
|
private java.util.Map<java.lang.String,TableMapper.LegacyIndexInfo> |
uidxByUniqueNames
Unique names for unique indexes map to their original
LegacyIndexInfo objects. |
private java.util.Map<TableMapper.LegacyIndexInfo,java.lang.String> |
uidxUniqueNames
Maps the
LegacyIndexInfo objects to unique names for them, if their name is not unique
across the dataset. |
private javax.xml.stream.XMLStreamWriter |
writer
XML stream writer
|
Constructor and Description |
---|
XmlExport(TargetData target,
boolean formatted,
java.lang.String encoding)
Constructor which saves the internal data for writing a XML/XSD stream.
|
Modifier and Type | Method and Description |
---|---|
private void |
indent()
Write a soft indent to the XML output stream, if formatting is enabled.
|
private void |
lineBreak()
Write a line break to the XML output stream, if formatting is enabled.
|
private boolean |
serializeTempTable(DataRelation relation,
TemporaryBuffer buffer,
java.lang.String rowName,
java.lang.String xmlns,
boolean noInit,
boolean includeHidden,
boolean includeProds,
boolean before)
Writes the content of a TEMP-TABLE to serializer.
|
private boolean |
write(XmlExport.XmlWriter code)
The framework for writing a XML file.
|
private void |
writeColumns(Record dmo,
java.lang.Iterable<TempTableSchema.Column> columns,
boolean hidden,
boolean noInit)
Write data for the given columns from a single record into the XML output stream.
|
boolean |
writeDataset(DataSet dataSet,
java.lang.String schemaLocation,
boolean writeXmlSchema,
boolean minXmlSchema,
boolean writeBeforeImage,
boolean omitInitialValues)
Performs the export of a DATASET.
|
boolean |
writeDatasetSchema(DataSet dataSet,
boolean minSchema,
boolean noInitial)
Performs the export of a DATASET schema.
|
private boolean |
writeDatasetSchemaImpl(DataSet dataSet,
boolean minSchema,
boolean defaultValues,
java.lang.String dsName,
java.lang.String nsUri,
java.lang.String nodeName)
Writes a XML-SCHEMA to XML stream.
|
private void |
writeDatum(TempTableSchema.Column column,
BaseDataType datum)
Write a single data value to the XML output stream, according to the instructions stored
in the temp-table schema.
|
private void |
writeDatum2(TempTableSchema.Column column,
BaseDataType datum)
Write a single data value to the XML output stream, according to the instructions stored
in the temp-table schema.
|
boolean |
writeRecord(BufferImpl bufferImpl,
boolean omitInitial)
Writes a single record.
|
private void |
writeRecord(TemporaryBuffer buffer,
TempRecord dmo,
java.lang.String rowName,
TempTableSchema schema,
java.lang.String xmlns,
boolean hidden,
boolean prodsId,
boolean before,
boolean omitInitialValues)
Write a temp-table record's data to the XML output stream.
|
private boolean |
writeTableSchema(BufferImpl buffer,
TempTableSchema schema,
boolean minSchema,
boolean defaultValues)
Performs the export of a TEMP-TABLE schema.
|
boolean |
writeTableSchema(TemporaryBuffer buffer,
boolean minSchema,
boolean noInitial)
Performs the export of a TEMP-TABLE schema.
|
private boolean |
writeTableSchemaImpl(BufferImpl buffer,
TempTableSchema schema,
java.lang.String tableName,
boolean defaultValues,
boolean minSchema,
boolean inDataset)
Writes the XML-SCHEMA of a TEMP-TABLE to XML stream.
|
boolean |
writeTempTable(TemporaryBuffer buffer,
java.lang.String schemaLocation,
boolean writeXmlSchema,
boolean minXmlSchema,
boolean writeBeforeImage,
boolean omitInitialValues)
Constructor which immediately performs the export of a TEMP-TABLE.
|
private static final java.lang.String INDENT
private static final java.lang.String ATTR_NS_XSI
private static final java.lang.String NS_URI
private static final java.lang.String ATTR_XSI_NIL
private static final java.lang.String lineSep
private final boolean format
private final TargetData target
private final java.lang.String encoding
private javax.xml.stream.XMLStreamWriter writer
private int indentLevel
private DataSet ds
DataSet
, if one is processed. null
if a table is processed.private boolean isSchemaOnly
WRITE-XMLSCHEMA
method in progress (for both DataSet
and
TempTable
). When a WRITE-XML
is processed the value is false
.private final java.util.Map<java.lang.Integer,org.apache.commons.lang3.tuple.Pair<java.lang.String,TableMapper.LegacyIndexInfo>> indexes
private final java.util.Map<java.lang.String,org.apache.commons.lang3.tuple.Pair<java.lang.String,java.lang.String>> prodsErrors
private java.lang.String ttNsPrefix
private final java.util.Map<TableMapper.LegacyIndexInfo,java.lang.String> uidxUniqueNames
LegacyIndexInfo
objects to unique names for them, if their name is not unique
across the dataset.private final java.util.Map<java.lang.String,TableMapper.LegacyIndexInfo> uidxByUniqueNames
LegacyIndexInfo
objects. This is the
reverse of uidxUniqueNames
. All unique indexes can be found here.private final java.util.Set<DataRelation> keyrefs
DataRelation
s which have promoted to xsd:keyref
s. Those not present
in this set will be serialized as prodata:relation
s.private static final TempTableSchema.Column ERROR_FLAG
private static final TempTableSchema.Column ORIGIN_ROWID
private static final TempTableSchema.Column DATASOURCE_ROWID
private static final TempTableSchema.Column ERROR_STRING
private static final TempTableSchema.Column AFTER_ROWID
private static final TempTableSchema.Column ROW_STATE
public XmlExport(TargetData target, boolean formatted, java.lang.String encoding)
target
- XML data target which normalizes access of various media to an output stream.formatted
- true
if serialized output should be pretty-printed for human-friendly
reading; false
to omit formatting.encoding
- Character encoding (not currently used).public boolean writeDataset(DataSet dataSet, java.lang.String schemaLocation, boolean writeXmlSchema, boolean minXmlSchema, boolean writeBeforeImage, boolean omitInitialValues)
dataSet
- The DatSet
from which data is exported.schemaLocation
- Path to XML schema (not currently used).writeXmlSchema
- true
to write XML schema information; false
to write only data.
If true
, schema will be written to schemaLocation
, if provided;
if not provided, schema will be embedded in XML output. Not currently honored.minXmlSchema
- true
to write minimal schema information; false
to write verbose
schema information. Ignored if writeXmlSchema
is false
. Not
currently honored.writeBeforeImage
- Not currently honored.omitInitialValues
- If true
, record values which match default initial values will be omitted
from serialized output, else they will be included. Not currently honored.true
on success. Otherwise the error is already dispatched to
ErrorManager
before returning.public boolean writeTempTable(TemporaryBuffer buffer, java.lang.String schemaLocation, boolean writeXmlSchema, boolean minXmlSchema, boolean writeBeforeImage, boolean omitInitialValues)
buffer
- Temp-table buffer from which data is exported.schemaLocation
- Path to XML schema (not currently used).writeXmlSchema
- true
to write XML schema information; false
to write only data.
If true
, schema will be written to schemaLocation
, if provided;
if not provided, schema will be embedded in XML output. Not currently honored.minXmlSchema
- true
to write minimal schema information; false
to write verbose
schema information. Ignored if writeXmlSchema
is false
. Not
currently honored.writeBeforeImage
- Not currently honored.omitInitialValues
- If true
, record values which match default initial values will be omitted
from serialized output, else they will be included. Not currently honored.true
on success. Otherwise the error is already dispatched to
ErrorManager
before returning.public boolean writeDatasetSchema(DataSet dataSet, boolean minSchema, boolean noInitial)
dataSet
- The DatSet
to be described.minSchema
- true
to write minimal schema information; false
to write verbose
schema information. Ignored if writeXmlSchema
is false
. Not
currently honored.noInitial
- If true
, record values which match default initial values will be omitted
from serialized output, else they will be included. Not currently honored.true
on success. Otherwise, the error is already dispatched to
ErrorManager
before returning.public boolean writeTableSchema(TemporaryBuffer buffer, boolean minSchema, boolean noInitial)
buffer
- A buffer of a TempTable
to be described.minSchema
- true
to write minimal schema information; false
to write verbose
schema information. Ignored if writeXmlSchema
is false
.noInitial
- If true
, record values which match default initial values will be omitted
from serialized output, else they will be included. Not currently honored.true
on success. Otherwise, the error is already dispatched to
ErrorManager
before returning.public boolean writeRecord(BufferImpl bufferImpl, boolean omitInitial)
bufferImpl
- The buffer which holds the record to be exported.omitInitial
- If true
the unmodified fields (those that are equals to the declared initial value)
are skipped in order to minimize the output.true
if operation is successful and false
if an error occurred.private boolean writeTableSchema(BufferImpl buffer, TempTableSchema schema, boolean minSchema, boolean defaultValues) throws javax.xml.stream.XMLStreamException
buffer
- A buffer of a TempTable
to be described.schema
- The schema of the TEMP-TABLE.minSchema
- true
to write minimal schema information; false
to write verbose
schema information. Ignored if writeXmlSchema
is false
. Not
currently honored.defaultValues
- If true
, record values which match default initial values will be omitted
from serialized output, else they will be included.
NOTE: actually setting [defaultValues] to [TRUE] which is the [omit-initial-values] from
ABL will cause some extra info to be added in field description (see + attributes):
<xsd:element name="f11" type="xsd:string" nillable="true" +minOccurs="0" +default=""/>
<xsd:element name="f12" type="xsd:int" nillable="true" +minOccurs="0" +default="0"/>
<xsd:element name="f13" type="xsd:date" nillable="true" +minOccurs="0" +prodata:initial="prodata:unknown"/>
<xsd:element name="f14" type="xsd:decimal" nillable="true" +minOccurs="0" +default="0.0"/>
true
on success. Otherwise the error is already dispatched to
ErrorManager
before returning.javax.xml.stream.XMLStreamException
- If XML-related issued occur.private boolean writeDatasetSchemaImpl(DataSet dataSet, boolean minSchema, boolean defaultValues, java.lang.String dsName, java.lang.String nsUri, java.lang.String nodeName) throws javax.xml.stream.XMLStreamException
dataSet
- The DataSet
to be described.minSchema
- true
to write minimal schema information; false
to write verbose
schema information. Ignored if writeXmlSchema
is false
. Not
currently honored.defaultValues
- If true
, the initial values for the fields will be written.dsName
- The DataSet
's name.nsUri
- The namespace-uri of the dataset. May be empty, but not null
.nodeName
- The DataSet
's node name.true
on success. Otherwise the error is already dispatched to
ErrorManager
before returning.javax.xml.stream.XMLStreamException
- If XML-related issued occurs.private boolean writeTableSchemaImpl(BufferImpl buffer, TempTableSchema schema, java.lang.String tableName, boolean defaultValues, boolean minSchema, boolean inDataset) throws javax.xml.stream.XMLStreamException
buffer
- The buffer that identifies the TEMP-TABLE to be described.schema
- The schema of the TEMP-TABLE.tableName
- The name of the table.defaultValues
- If true
the initial values are written for the fields that declared them.minSchema
- true
to write minimal schema information; false
to write verbose
schema information. Ignored if writeXmlSchema
is false
.inDataset
- If true
, this is part of a dataset SCHEMA and additional attributes will
be written.true
on success. Otherwise the error is already dispatched to
ErrorManager
before returning.javax.xml.stream.XMLStreamException
- If XML-related issued occurs.private boolean serializeTempTable(DataRelation relation, TemporaryBuffer buffer, java.lang.String rowName, java.lang.String xmlns, boolean noInit, boolean includeHidden, boolean includeProds, boolean before)
relation
- The relation on which this buffer is a child of.buffer
- The buffer to be used for accessing TEMP-TABLE records.rowName
- The name of the XML element that holds a record.xmlns
- The XML namespace uri, is set.includeHidden
- If true
, the hidden fields will also be dumped.includeProds
- If true
, the PROGRESS specific attribute will be written.before
- This is a BEFORE
table. Rows written will be slightly decorated.true
on success. Otherwise the error is already dispatched to
ErrorManager
before returning.private void writeRecord(TemporaryBuffer buffer, TempRecord dmo, java.lang.String rowName, TempTableSchema schema, java.lang.String xmlns, boolean hidden, boolean prodsId, boolean before, boolean omitInitialValues)
buffer
- The buffer being serialized.dmo
- Object containing temp-table record's data.rowName
- Name applied to the element or attribute associated with the row data in the XML
output.schema
- The table schema to be used.xmlns
- The XML namespace uri, is set.hidden
- If true
include the hidden fields (__name__
) for each record
written to stream.prodsId
- If true
include the prods:id
attribute for each record written.before
- true
if a BEFORE-TABLE record is processed.private void writeColumns(Record dmo, java.lang.Iterable<TempTableSchema.Column> columns, boolean hidden, boolean noInit) throws java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException, javax.xml.stream.XMLStreamException
dmo
- The DMO to be serialized.columns
- The set of columns for that DMO.hidden
- If true
include the hidden fields (__name__
) for each record
written to stream.java.lang.IllegalAccessException
- if a DMO getter method cannot be accessed using reflection.java.lang.IllegalArgumentException
- if an illegal argument is passed to the DMO getter method for a column.java.lang.reflect.InvocationTargetException
- if there is a problem invoking a getter method on the given DMO.javax.xml.stream.XMLStreamException
- if there is an error writing to the XML stream.private void writeDatum(TempTableSchema.Column column, BaseDataType datum) throws javax.xml.stream.XMLStreamException
This version ensures that the group and decimal separators are ',' and '.' for the duration of the serialization.
column
- Temp-table column schema information.datum
- Datum to be written to XML output.javax.xml.stream.XMLStreamException
- if there is an error writing to the XML stream.private void writeDatum2(TempTableSchema.Column column, BaseDataType datum) throws javax.xml.stream.XMLStreamException
column
- Temp-table column schema information.datum
- Datum to be written to XML output.javax.xml.stream.XMLStreamException
- if there is an error writing to the XML stream.private void lineBreak() throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
- if there is an error writing to the XML stream.private void indent() throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
- if there is an error writing to the XML stream.private boolean write(XmlExport.XmlWriter code)
target
with requested encoding
, write XML header and allow the code
to write
the XML body (main element). At the end, the end of document is written and the file is
closed.
In case that the code
exit abruptly, the expected Exception
s are catched as
a last resort and the stack trace is printed.
code
- The code to be executed. It should build the actual XML content.true
on success. Otherwise the error is already dispatched to
ErrorManager
before returning.