public final class XmlImport extends Importer implements TableReader
Runtime support is partial at this time; not all modes and features are supported. PRODATASET is not supported at this time.
| Modifier and Type | Class and Description |
|---|---|
private static class |
XmlImport.Relation
Internal structure for storing a
DataSet relation until the full set of tables is
read. |
Importer.FieldMaker, Importer.ImportContext| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
ATTR_NIL
Nil attribute name
|
private java.util.Stack<java.util.Map<java.lang.String,java.lang.String>> |
attrs
Elements attributes' stack
|
private int |
attrSetOffset
The location of the currently processed element.
|
private java.util.Map<java.lang.String,java.lang.String> |
crtAttSet
The set of attributes of the current read XML element.
|
private java.lang.String |
dsNsUri
The future namespace of the read dataset.
|
private static java.lang.String |
ELEM_IMPORT
XSD import element name
|
private static java.lang.String |
ELEM_SCHEMA
XSD schema element name
|
private java.util.Stack<java.lang.String> |
elements
Elements' stack
|
private boolean |
embeddedSchema
Flag indicating that XML document contains embedded schema
|
private boolean |
external
Flag indicating that we're reading external schema
|
private java.util.Map<java.lang.String,java.lang.String> |
fieldTypeMapping
The desired mapping of fields to new type, if one is defined.
|
private boolean |
inferStructure
Flag indicating that the table/dataset structure should be inferred from the XML file.
|
private boolean |
knownTableSchema
Flags whether the processed table has a known schema or it should be read from file.
|
private static CentralLogger |
LOG
Logger for objects of this type.
|
private java.lang.String |
namespace
The future namespace of the read temp-table.
|
private java.util.Map<java.lang.String,java.lang.String> |
prefixByNs
XML NS refix for NS by NS
|
private LookAheadXmlStreamReader |
reader
The stream where the data is read from.
|
private java.util.List<XmlImport.Relation> |
relations
The list of read relations of a dataset being read.
|
private java.lang.String |
schemaLocation
'External' schema location, if one is provided.
|
private boolean |
singleEntry
Flag indicating that XML contains row separators.
|
private java.util.Map<java.lang.String,java.lang.String> |
singleEntryAttr
Set of attributes and text of the field for single entry syntax.
|
private java.util.Map<java.lang.String,java.lang.String> |
tablesByXmlName
The mapping of the legacy table names by their (case-insensitive) XML name.
|
private static java.lang.String |
TEXT_TRUE
String constant for 'true'
|
private boolean |
trackXml
Flag indicating that XML parsing will be self-checked
(for debugging)
|
private java.lang.String |
ttPrefix
The future namespace prefix of the read temp-table.
|
private java.util.Map<java.lang.String,P2JIndex> |
uniqueIndexes
All unique indexes in this dataset, mapped by their unique names.
|
private boolean |
useLobs
Use CLOB/BLOB instead of character/raw type? (Value of
override-default-mapping parameter). |
private SerializeOptions.Verify |
verifySchemaMode
Verify schema mode.
|
b4tables, bufMan, childFieldsByChild, ctx, ds, inferredRelations, loader, peerMapping, readingBefore, readMode, savedCtx, source, tables| Constructor and Description |
|---|
XmlImport(SourceData source,
java.lang.String readMode,
java.lang.String schemaLocation,
boolean overrideDefaultMapping,
java.util.Map<java.lang.String,java.lang.String> fieldTypeMapping,
java.lang.String verifySchemaMode)
Constructor which configures the importer for an import of a Dataset or a TempTable/Buffer.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
addField(TempTableBuilder ttb,
java.lang.String name,
java.lang.Object val,
java.util.function.Predicate<java.lang.String> isAttr)
Add field to the temp-table.
|
private void |
addValue(java.util.Map<java.lang.String,java.lang.Object> readValues,
java.lang.String name,
java.lang.String value)
Add named value to a map of values, with extent handling.
|
private boolean |
checkNil(TempTableSchema.Column column)
Check whether the current temp-table value read from XML content is null.
|
private java.lang.String |
get4GLType(java.lang.String type,
java.lang.String proType,
java.lang.String nullable,
boolean useLobs,
java.lang.String tableName,
java.lang.String fieldName)
Helper method for detecting the 4GL field type using XML data types.
|
private java.lang.String |
getXmlAttribute(java.lang.String fullName)
Obtain the value of an attribute for the currently processed XML element.
|
private java.util.Map<java.lang.String,java.lang.String> |
getXmlAttributes()
Get map of attributes by name.
|
private java.util.Map<java.lang.String,java.lang.String> |
getXmlNamespaces()
Get map of NS prefixes by namespace.
|
boolean |
importDataset(DataSet dataSet,
java.util.function.BiConsumer<RecordBuffer,Record> loader)
Imports a dataset.
|
boolean |
importDatasetSchema(DataSet ds)
Configures a dataset schema or validates it against the XML file.
|
boolean |
importTable(AbstractTempTable tempTable,
java.util.function.BiConsumer<RecordBuffer,Record> loader)
Reads a TEMP-TABLE from the configured source.
|
boolean |
importTempTableSchema(AbstractTempTable tt)
Configures a temp-table schema or validates it against the XML file.
|
private javax.xml.stream.XMLInputFactory |
newXmlInputFactory()
Create a factory which treats XML 1.0 files as XML 1.1.
|
private java.io.Reader |
openReader(java.io.InputStream stream)
Create a
Reader which has the encoding as specified in the XML file targeted by this stream. |
private boolean |
parseRecord(Buffer parent)
Parse XML record to retrieve fields' data, prepare table.
|
private void |
processDsBuffers()
Process buffers for the imported dataset tables.
|
(package private) boolean |
processNestedRecord()
Process a single nested record.
|
private void |
processRelations(Buffer parent)
Pre-process nested relations.
|
private boolean |
readDatasetData()
Reads data from XML stream and populates the tables of a
DataSet. |
private boolean |
readDatasetSchema(boolean verify)
Reads and processes a
DataSet schema. |
private boolean |
readFromHandle(java.util.function.Function<XmlImport,java.lang.Boolean> reader)
Import from a handle.
|
private boolean |
readIndex(java.lang.String indexName,
java.lang.String originalName,
java.lang.String nsPrefix,
boolean primary,
boolean unique,
boolean word,
boolean asIndex)
Reads and process an index from the XML stream.
|
private boolean |
readNested(java.lang.String name)
Read nested table data.
|
private boolean |
readRecord()
Read XML content from the stream corresponding with a single data record and store it in
the temp-table.
|
private boolean |
readRecord(Buffer parent)
Read XML content from the stream corresponding with a single data record and store it in
the temp-table.
|
private boolean |
readRecord2(Buffer parent)
Read XML content from the stream corresponding with a single data record and store it in
the temp-table.
|
boolean |
readTable(java.lang.String tableName,
TempTableBuilder table,
java.util.function.BiConsumer<RecordBuffer,Record> loader)
Read XML/JSON data from the input source and store it in the just created empty TEMP-TABLE.
|
private boolean |
readTableSchema(AbstractTempTable tempTable,
java.lang.String nsPrefix,
java.lang.String nsUri)
Reads and processes a
TEMP-TABLE schema. |
private boolean |
readTableSchema(java.lang.String tableName,
java.lang.String nsPrefix)
The read table is automatically added to the dataset if one is processed.
|
private boolean |
readTableSchema(java.lang.String xmlNodeName,
java.lang.String nsPrefix,
java.lang.String nsUri)
Reads and processes an
AbstractTempTable schema. |
private java.lang.String |
readText()
Read text content from within an element or a CDATA section.
|
private java.lang.String |
removeNsPrefix(java.lang.String qname)
Remove the namespace prefix from the qualified name
|
private boolean |
skipRecord(java.lang.String tableName)
Skip the whole subtree because the record belongs to an unknown table.
|
protected ParmType |
typeOf(java.lang.Object val)
Get an inferred type of the value.
|
fillFromParent, getColumn, peekContext, persist, popContext, populateRecord, processHiddenFk, processId, processRowState, pushContext, setField, setField, setField, setParentValues, setupDatasetprivate static final CentralLogger LOG
private static final java.lang.String ELEM_SCHEMA
private static final java.lang.String ELEM_IMPORT
private static final java.lang.String ATTR_NIL
private static final java.lang.String TEXT_TRUE
private final SerializeOptions.Verify verifySchemaMode
private final boolean useLobs
override-default-mapping parameter).private java.lang.String dsNsUri
private java.lang.String namespace
private java.lang.String ttPrefix
private final java.util.Map<java.lang.String,java.lang.String> fieldTypeMapping
private final java.lang.String schemaLocation
private boolean external
private final java.util.Map<java.lang.String,java.lang.String> tablesByXmlName
private boolean embeddedSchema
private java.util.List<XmlImport.Relation> relations
private java.util.Map<java.lang.String,java.lang.String> prefixByNs
private final java.util.Map<java.lang.String,P2JIndex> uniqueIndexes
private LookAheadXmlStreamReader reader
private java.util.Map<java.lang.String,java.lang.String> crtAttSet
getXmlAttribute() method.private int attrSetOffset
crtAttSet, which acts as a cache. If the position of the current XML element is
different from attrSetOffset then crtAttSet needs to be updated.private boolean knownTableSchema
private boolean inferStructure
private boolean trackXml
private java.util.Stack<java.lang.String> elements
private java.util.Stack<java.util.Map<java.lang.String,java.lang.String>> attrs
private java.util.Map<java.lang.String,java.lang.String> singleEntryAttr
private boolean singleEntry
public XmlImport(SourceData source, java.lang.String readMode, java.lang.String schemaLocation, boolean overrideDefaultMapping, java.util.Map<java.lang.String,java.lang.String> fieldTypeMapping, java.lang.String verifySchemaMode)
source - XML data source which normalizes access of various media to an input stream.readMode - Read mode to determine how records are stored and how non-unique records are
handled. Not currently honored, except temp-table records are deleted if mode
is EMPTY.schemaLocation - Path to XML schema (not currently used).overrideDefaultMapping - Not currently used.fieldTypeMapping - Not currently used.verifySchemaMode - Not currently used.public boolean importDatasetSchema(DataSet ds)
ds - The destination for read schema.true on success. On failure, false is returned and the eventual
error is already displayed.public boolean importTempTableSchema(AbstractTempTable tt)
tt - The destination for read schema.true on success. On failure, false is returned and the eventual error is
already displayed.public boolean importDataset(DataSet dataSet, java.util.function.BiConsumer<RecordBuffer,Record> loader)
dataSet - The destination for read data.loader - A BiConsumer which helps loading a Record into the buffer.true on success. On failure, false is returned and the eventual
error is already displayed.public boolean importTable(AbstractTempTable tempTable, java.util.function.BiConsumer<RecordBuffer,Record> loader)
tempTable - Temp-table in which data will be stored.loader - A BiConsumer which helps loading a Record into the buffer.true on success.public boolean readTable(java.lang.String tableName,
TempTableBuilder table,
java.util.function.BiConsumer<RecordBuffer,Record> loader)
throws PersistenceException
readTable in interface TableReadertableName - table nametable - TEMP-TABLE to be loaded.loader - A BiConsumer which helps loading a Record into the buffer.true on success.PersistenceException - if there is any error reading or storing XML/JSON data.protected ParmType typeOf(java.lang.Object val) throws PersistenceException
typeOf in class Importerval - value to be analyzedPersistenceException - on invalid value typeprivate boolean readFromHandle(java.util.function.Function<XmlImport,java.lang.Boolean> reader)
X-Document is currently supported.reader - The reader function.true if the import was successful.private java.io.Reader openReader(java.io.InputStream stream)
throws java.io.IOException
Reader which has the encoding as specified in the XML file targeted by this stream.
If no encoding is specified, it defaults to UTF-8.
The reader is wrapped in a filter which automatically escapes ISO control characters which are not whitespace.
stream - input stream.java.io.IOExceptionprivate javax.xml.stream.XMLInputFactory newXmlInputFactory()
private boolean readTableSchema(AbstractTempTable tempTable, java.lang.String nsPrefix, java.lang.String nsUri) throws javax.xml.stream.XMLStreamException
TEMP-TABLE schema.nsPrefix - The detected XML namespace prefix.nsUri - The detected XML namespace URI.true on success and false otherwise. When false is returned
then the error message has already been dispatched to ErrorManager.javax.xml.stream.XMLStreamException - If a XML-related error occurs (like an unexpected end of stream).private boolean readDatasetSchema(boolean verify)
throws javax.xml.stream.XMLStreamException
DataSet schema. If the DataSet is in CLEAR state, the
structure is initialized and its tables and relations are set up. Otherwise the schema is
checked according to verifySchemaMode.verify - When true the schema is only verified. Otherwise the methods attempts to create the
read schema into the dataset.true on success and false otherwise. When false is returned
then the error message has already been dispatched to ErrorManager.javax.xml.stream.XMLStreamException - If a XML-related error occurs (like an unexpected end of stream).private java.lang.String removeNsPrefix(java.lang.String qname)
qname - qualified name to be simplifiedprivate void processDsBuffers()
private boolean readTableSchema(java.lang.String xmlNodeName,
java.lang.String nsPrefix,
java.lang.String nsUri)
throws javax.xml.stream.XMLStreamException
AbstractTempTable schema. If the TempTable is in CLEAR state, the
structure is initialized. Otherwise the schema is checked according to verifySchemaMode.xmlNodeName - The detected XML node name.nsPrefix - The detected XML namespace prefix.nsUri - The detected XML namespace URI.true on success and false otherwise. When false is returned
then the error message has already been dispatched to ErrorManager.javax.xml.stream.XMLStreamException - If a XML-related error occurs (like an unexpected end of stream).private boolean readIndex(java.lang.String indexName,
java.lang.String originalName,
java.lang.String nsPrefix,
boolean primary,
boolean unique,
boolean word,
boolean asIndex)
throws javax.xml.stream.XMLStreamException
indexName - The index name (aka XML name).originalName - The index's original name only if the xml name was altered because of collisions.nsPrefix - The detected XML namespace prefix.primary - true if this is a primary index.unique - true is this is an unique index.word - true is this is a word index.asIndex - true is this taken from the 'index' node.true on success and false otherwise. When false is returned
then the error message has already been dispatched to ErrorManager.javax.xml.stream.XMLStreamException - If a XML-related error occurs (like an unexpected end of stream).private boolean readDatasetData()
throws javax.xml.stream.XMLStreamException,
PersistenceException
DataSet.true on success and false otherwise. When false is returned
then the error message has already been dispatched to ErrorManager.javax.xml.stream.XMLStreamException - if a XML-related error occurs (like an unexpected end of stream).PersistenceException - if a persistence error occurs while saving data to database.private boolean readTableSchema(java.lang.String tableName,
java.lang.String nsPrefix)
throws javax.xml.stream.XMLStreamException
<xsd:element> node for this table was already processed
(no look-ahead) in order to decide to call this method.tableName - The name of the table which is being processed.nsPrefix - The detected XML namespace prefix.true if the operation is successful. If the operation fails, false is returned.javax.xml.stream.XMLStreamException - in the event of an exception occurred while reading the XML stream.private boolean skipRecord(java.lang.String tableName)
throws javax.xml.stream.XMLStreamException
tableName - The table name.true on success. Otherwise an error is issued before returning false.javax.xml.stream.XMLStreamException - if the XML stream cannot be parsed.private boolean readRecord()
throws javax.xml.stream.XMLStreamException,
PersistenceException
This version ensures that the group and decimal separators are ',' and '.' for the duration of the deserialization.
javax.xml.stream.XMLStreamException - if there is an error reading XML content from the stream.PersistenceException - if there is an error storing data in the temp-table.private boolean readRecord(Buffer parent) throws javax.xml.stream.XMLStreamException, PersistenceException
This version ensures that the group and decimal separators are ',' and '.' for the duration of the deserialization.
parent - The parent buffer, if this is called for a NESTED relation fields.javax.xml.stream.XMLStreamException - if there is an error reading XML content from the stream.PersistenceException - if there is an error storing data in the temp-table.private boolean readRecord2(Buffer parent) throws javax.xml.stream.XMLStreamException, PersistenceException
parent - The parent buffer, if this is called for a NESTED relation fields.javax.xml.stream.XMLStreamException - if there is an error reading XML content from the stream.PersistenceException - if there is an error storing data in the temp-table.boolean processNestedRecord()
throws javax.xml.stream.XMLStreamException,
PersistenceException
true on success.javax.xml.stream.XMLStreamExceptionPersistenceExceptionprivate void processRelations(Buffer parent)
parent - The parent buffer, if this is called for a NESTED relation fields.private boolean parseRecord(Buffer parent) throws javax.xml.stream.XMLStreamException, PersistenceException
parent - The parent buffer, if this is called for a NESTED relation fields.javax.xml.stream.XMLStreamException - if there is an error reading XML content from the stream.PersistenceException - if there is an error storing data in the temp-table.private boolean readNested(java.lang.String name)
throws PersistenceException
name - The name of the table to be populated.true in successPersistenceException - in errorprivate void addValue(java.util.Map<java.lang.String,java.lang.Object> readValues,
java.lang.String name,
java.lang.String value)
readValues - The map which colelcts the key/values pairs.name - The key.value - The value associated with the key. If there is already a scalar value associated with the key,
it is replaced by a list containing the extent data. If the old value is already a list the
value is appended to it.private java.lang.String readText()
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException - if there is an error reading XML content from the stream.private boolean checkNil(TempTableSchema.Column column)
column - Schema information for the associated column.true if the XML content is nil; else false.ErrorConditionException - if value is nil and column does not allow null values.private java.lang.String getXmlAttribute(java.lang.String fullName)
attrSetOffset to compare the location of the current element. If they are different,
the cache is updated. Note that the cache is updated only on request, the current of
crtAttSet may be stalled if the getXmlAttribute() was not yet called for the
new element.fullName - The full-name of the attribute.null if there is no such attribute
in current element.private java.util.Map<java.lang.String,java.lang.String> getXmlAttributes()
private java.util.Map<java.lang.String,java.lang.String> getXmlNamespaces()
private java.lang.String get4GLType(java.lang.String type,
java.lang.String proType,
java.lang.String nullable,
boolean useLobs,
java.lang.String tableName,
java.lang.String fieldName)
type - The pure xsd type.proType - Additional information needed to distinct the original 4GL type.nullable - Whether the original field type was nullable.useLobs - If true, clob and blob types will be used instead of character
and raw, respectively.tableName - Optional. If specified the table name is looked up in the type map instead of the type
specified in XML file.fieldName - Optional. If specified the field name is looked up in the type map instead of the type
specified in XML file.null is returned.Util.xsdMap,
Util.xsdProdataMapprivate void addField(TempTableBuilder ttb, java.lang.String name, java.lang.Object val, java.util.function.Predicate<java.lang.String> isAttr) throws PersistenceException
ttb - The destination temp-table builder.name - The name of the field to be added.val - The value of field. It is used for inferring the type of the new field.isAttr - A predicate which allows identification of fields with ATTRIBUTE node type.PersistenceException - If the type of the field cannot be inferred from the provided value.