Class XmlDomDataContext

  • All Implemented Interfaces:
    org.apache.metamodel.convert.HasReadTypeConverters, org.apache.metamodel.DataContext

    public class XmlDomDataContext
    extends org.apache.metamodel.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
    • 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​(org.apache.metamodel.util.Resource resource,
                                 boolean autoFlattenTables)
                          throws IllegalArgumentException
        Creates an XML DataContext strategy based on a file.
        Parameters:
        resource - the resource 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​(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 org.apache.metamodel.data.DataSet materializeMainSchemaTable​(org.apache.metamodel.schema.Table table,
                                                                            List<org.apache.metamodel.schema.Column> columnList,
                                                                            int maxRows)
        Specified by:
        materializeMainSchemaTable in class org.apache.metamodel.QueryPostprocessDataContext
      • getMainSchemaName

        protected String getMainSchemaName()
                                    throws org.apache.metamodel.MetaModelException
        Specified by:
        getMainSchemaName in class org.apache.metamodel.QueryPostprocessDataContext
        Throws:
        org.apache.metamodel.MetaModelException
      • getMainSchema

        protected org.apache.metamodel.schema.Schema getMainSchema()
                                                            throws org.apache.metamodel.MetaModelException
        Specified by:
        getMainSchema in class org.apache.metamodel.QueryPostprocessDataContext
        Throws:
        org.apache.metamodel.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​(org.apache.metamodel.schema.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).