org.apache.metamodel.xml
Class XmlDomDataContext

java.lang.Object
  extended by org.apache.metamodel.AbstractDataContext
      extended by org.apache.metamodel.QueryPostprocessDataContext
          extended by org.apache.metamodel.xml.XmlDomDataContext
All Implemented Interfaces:
HasReadTypeConverters, DataContext
Direct Known Subclasses:
XmlDataContext

public class XmlDomDataContext
extends QueryPostprocessDataContext

A DataContext strategy that reads XML content and maps it to a table-based model similar to the rest of MetaModel. Tables are created by examining the data in the XML file, NOT by reading XML Schemas (xsd/dtd's). This enables compliancy with ALL xml formats but also raises a risk that two XML files with the same format wont nescesarily yield the same table model if some optional attributes or tags are omitted in one of the files. The parsing method applied in this datacontext is DOM based, which means that at upon parsing (only a single point in time), the whole file will be read and it's tree structure kept in memory. Therefore this DataContext is NOT appropriate for large XML files (10's, 100's or 1000's of megabytes).

See Also:
XmlSaxDataContext

Field Summary
static String NATIVE_TYPE_ATTRIBUTE
           
static String NATIVE_TYPE_FOREIGN_KEY
           
static String NATIVE_TYPE_PRIMARY_KEY
           
static String NATIVE_TYPE_TEXT
           
 
Fields inherited from class org.apache.metamodel.QueryPostprocessDataContext
INFORMATION_SCHEMA_NAME
 
Constructor Summary
XmlDomDataContext(File file)
          Creates an XML DataContext strategy based on a file.
XmlDomDataContext(File file, boolean autoFlattenTables)
           
XmlDomDataContext(InputSource inputSource, String schemaName, boolean autoFlattenTables)
           
XmlDomDataContext(Resource resource, boolean autoFlattenTables)
          Creates an XML DataContext strategy based on a file.
XmlDomDataContext(String schemaName, Document document, boolean autoFlattenTables)
          Creates an XML DataContext strategy based on an already parsed Document.
XmlDomDataContext(URL url, boolean autoFlattenTables)
           
 
Method Summary
 XmlDomDataContext autoFlattenTables()
          Automatically flattens tables that only contain a single data carrying column.
 XmlDomDataContext flattenTables(Relationship relationship)
           
static Attr[] getAttributes(Element element)
           
static Element[] getChildElements(Element element)
           
protected  Schema getMainSchema()
           
protected  String getMainSchemaName()
           
static String getTextContent(Element element)
           
static boolean hasSiblings(Element element)
           
 boolean isAutoFlattenTables()
           
static boolean isRootElement(Element element)
           
 XmlDomDataContext loadSchema()
          Loads the schema if it hasn't been loaded before
 DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows)
           
 XmlDomDataContext reloadSchema()
          Forces a fresh load of the schema, even though it has already been loaded
 void setAutoFlattenTables(boolean autoFlattenTables)
           
 
Methods inherited from class org.apache.metamodel.QueryPostprocessDataContext
addConverter, executeCountQuery, executePrimaryKeyLookupQuery, executeQuery, getDefaultSchemaName, getMainSchemaInternal, getSchemaByNameInternal, getSchemaNamesInternal, isMainSchemaTable, materializeFromItem, materializeMainSchemaTable, materializeMainSchemaTable, materializeMainSchemaTable, materializeTable, materializeTable
 
Methods inherited from class org.apache.metamodel.AbstractDataContext
compileQuery, executeQuery, executeQuery, getColumnByQualifiedLabel, getDefaultSchema, getSchemaByName, getSchemaNames, getSchemas, getTableByQualifiedLabel, isQualifiedPathDelim, parseQuery, query, refreshSchemas
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NATIVE_TYPE_PRIMARY_KEY

public static final String NATIVE_TYPE_PRIMARY_KEY
See Also:
Constant Field Values

NATIVE_TYPE_FOREIGN_KEY

public static final String NATIVE_TYPE_FOREIGN_KEY
See Also:
Constant Field Values

NATIVE_TYPE_ATTRIBUTE

public static final String NATIVE_TYPE_ATTRIBUTE
See Also:
Constant Field Values

NATIVE_TYPE_TEXT

public static final String NATIVE_TYPE_TEXT
See Also:
Constant Field Values
Constructor Detail

XmlDomDataContext

public XmlDomDataContext(String schemaName,
                         Document document,
                         boolean autoFlattenTables)
Creates an XML DataContext strategy based on an already parsed Document.

Parameters:
schemaName -
document -
autoFlattenTables -

XmlDomDataContext

public XmlDomDataContext(Resource resource,
                         boolean autoFlattenTables)
                  throws IllegalArgumentException
Creates an XML DataContext strategy based on a file.

Parameters:
file - the file to parse
autoFlattenTables - a parameter indicating whether or not tags with only text content or a single attribute should be flattened with it's parent table
Throws:
IllegalArgumentException - if the file does not exist

XmlDomDataContext

public XmlDomDataContext(File file,
                         boolean autoFlattenTables)

XmlDomDataContext

public XmlDomDataContext(InputSource inputSource,
                         String schemaName,
                         boolean autoFlattenTables)

XmlDomDataContext

public XmlDomDataContext(URL url,
                         boolean autoFlattenTables)
                  throws IllegalArgumentException
Throws:
IllegalArgumentException

XmlDomDataContext

public XmlDomDataContext(File file)
Creates an XML DataContext strategy based on a file.

Parameters:
file - the file to parse
Method Detail

isAutoFlattenTables

public boolean isAutoFlattenTables()

setAutoFlattenTables

public void setAutoFlattenTables(boolean autoFlattenTables)

materializeMainSchemaTable

public DataSet materializeMainSchemaTable(Table table,
                                          Column[] columns,
                                          int maxRows)
Specified by:
materializeMainSchemaTable in class QueryPostprocessDataContext

getMainSchemaName

protected String getMainSchemaName()
                            throws MetaModelException
Specified by:
getMainSchemaName in class QueryPostprocessDataContext
Throws:
MetaModelException

getMainSchema

protected Schema getMainSchema()
                        throws MetaModelException
Specified by:
getMainSchema in class QueryPostprocessDataContext
Throws:
MetaModelException

reloadSchema

public XmlDomDataContext reloadSchema()
Forces a fresh load of the schema, even though it has already been loaded


loadSchema

public XmlDomDataContext loadSchema()
Loads the schema if it hasn't been loaded before


getTextContent

public static String getTextContent(Element element)

getAttributes

public static Attr[] getAttributes(Element element)

hasSiblings

public static boolean hasSiblings(Element element)

getChildElements

public static Element[] getChildElements(Element element)

isRootElement

public static boolean isRootElement(Element element)

flattenTables

public XmlDomDataContext flattenTables(Relationship relationship)

autoFlattenTables

public XmlDomDataContext autoFlattenTables()
Automatically flattens tables that only contain a single data carrying column. Data carrying column are all columns that are not artificial columns (created to enable referential integrity between tag-to-table mapped tables).



Copyright © 2007–2015 The Apache Software Foundation. All rights reserved.