All Packages Class Hierarchy This Package Previous Next Index
Class de.tudarmstadt.ito.xmldbms.mapfactories.MapFactory_DTD
java.lang.Object
|
+----de.tudarmstadt.ito.xmldbms.mapfactories.MapFactory_DTD
- public class MapFactory_DTD
- extends Object
Create a Map from a DTD object.
MapFactory_DTD constructs tables and columns in which the element types
and attributes described in the DTD object can be stored, then creates
a Map that maps the element types and attributes to these tables and
columns. The resulting Map cannot be used immediately with DBMSToDOM or
DOMToDBMS because no connection has been set on it. Furthermore, it is
possible that the tables referred to by the map don't yet exist. However,
it can be serialized as a mapping document or used to generate CREATE
TABLE statements.
For example, the following code creates a map from the DTD document.dtd,
creates the tables, sets the connection, and then transfers data to the
database:
// Instantiate a new map factory and create a map.
factory = new MapFactory_DTD();
map = factory.createMapFromDTD(src, MapFactory_DTD.DTD_EXTERNAL, true, null);
// Create the tables used by the map. Note that this function calls
// Map.getCreateTableStrings(), then executes each string in a
// JDBC Statement.
createTables(map);
// Set the database connection, then transfer the data to the database.
map.setConnection(conn);
domToDBMS = new DOMToDBMS(map);
domToDBMS.storeDocument(doc);
MapFactory_DTD constructs tables and columns roughly as follows. Note
that these tables and columns are not actually created in the database;
to do this, the application must retrieve CREATE TABLE strings from
the resulting Map and execute these in JDBC statements. The reason for
this is that applications will commonly want to change the table structure
predicted by MapFactory_DTD before actually creating tables or simply
use this factory as a tool for creating Maps, which can be serialized
with the Map.serialize() method.
- For each element type that has attributes or child elements, a table
is generated. In this table are a primary key (PK) column, one column for each
single-valued attribute, one column for each singly-occurring child
element type that contains only PCDATA and has no attributes, an (optional)
order column for each child element type column, and one foreign key (FK)
column for each parent element type. If the element type has attributes and
PCDATA but no child element types, then there is also a column for its
PCDATA. Note that the PK column appears only if needed to link to
a child table or if the element type is a potential root element type.
- If an attribute is multi-valued (IDREFS, NMTOKENS, or ENTITIES), it
is stored in a separate table, with an element type FK column, a value
column, and an (optional) order column.
- If a child element type that contains only PCDATA and has no attributes
can occur multiple times in its parent, it is stored in a separate table,
with a parent element type FK column, a value column, and an
(optional) order column.
- Except as noted above, PCDATA is stored in a separate table with an
element type FK column, a value column, and an (optional) order column.
- The code also guesses at what the legal root element types are. An
element type is considered to be a root if it has no parents. If all
element types have parents, then all element types are made legal roots.
WARNING! This code does not check for name collisions. A number
of name collisions are possible. The possible table and column names are
listed below. If these clash with each other, the result is missing tables
and/or columns. If these clash with existing table names, the result is
the inability to correctly transfer data to the database. You should also
remember that table and column names in many databases are case insensitive,
so collisions due to case folding are possible.
Table name: element type name
Column names:
element type name + "PK"
element type name + "PCDATA"
element type name + "PCDATA" + "Order"
parent element type name + "FK"
child element type name + "FK"
child element type name + "Order"
attribute name
Table name: attribute name
Column names:
element type name + "FK"
attribute name
attribute name + "Order"
Table name: element type name + "PCDATA"
Column names:
element type name + "FK"
element type name + "PCDATA"
element type name + "PCDATA" + "Order"
- Version:
- 1.01
- Author:
- Ronald Bourret, Technical University of Darmstadt
-
DTD_EXTERNAL
- DTD is an external subset.
-
DTD_XMLDOCUMENT
- The DTD is in an XML document, as an internal subset, reference
to an external subset, or both.
-
SCHEMA_DCD
- Schema document uses DCD (not supported).
-
SCHEMA_DDML
- Schema document uses DDML.
-
SCHEMA_SOX
- Schema document uses SOX (not supported).
-
SCHEMA_W3C
- Schema document uses W3C XML Schemas (not supported).
-
SCHEMA_XMLDATA
- Schema document uses XML-Data (not supported).
-
MapFactory_DTD()
- Construct a new MapFactory_DTD.
-
createMap(DTD, boolean)
- Create a map from a DTD object.
-
createMapFromDTD(InputSource, int, boolean, Hashtable)
- Create a map from an InputSource representing an external DTD subset or
an XML document containing a DTD.
-
createMapFromSchema(InputSource, int, boolean, Parser)
- Create a map from an InputSource representing a schema.
SCHEMA_DCD
public static final int SCHEMA_DCD
- Schema document uses DCD (not supported).
SCHEMA_DDML
public static final int SCHEMA_DDML
- Schema document uses DDML.
SCHEMA_SOX
public static final int SCHEMA_SOX
- Schema document uses SOX (not supported).
SCHEMA_W3C
public static final int SCHEMA_W3C
- Schema document uses W3C XML Schemas (not supported).
SCHEMA_XMLDATA
public static final int SCHEMA_XMLDATA
- Schema document uses XML-Data (not supported).
DTD_EXTERNAL
public static final int DTD_EXTERNAL
- DTD is an external subset.
DTD_XMLDOCUMENT
public static final int DTD_XMLDOCUMENT
- The DTD is in an XML document, as an internal subset, reference
to an external subset, or both.
MapFactory_DTD
public MapFactory_DTD()
- Construct a new MapFactory_DTD.
createMapFromDTD
public Map createMapFromDTD(InputSource src,
int type,
boolean storeOrder,
Hashtable namespaceURIs) throws InvalidMapException, DTDException, EOFException, MalformedURLException, IOException
- Create a map from an InputSource representing an external DTD subset or
an XML document containing a DTD.
- Parameters:
- filename - The name of the schema file.
- type - DTD_EXTERNAL or DTD_XMLDOCUMENT.
- storeOrder - Whether the map should store order information in
the database.
- namespaceURIs - A Hashtable using prefixes as keys and namespace
URIs as values. May be null.
- Returns:
- The Map object.
- Throws: InvalidMapException
- Thrown if a mapping error occurs.
- Throws: DTDException
- Thrown if a DTD error is found.
- Throws: EOFException
- Thrown if EOF is reached prematurely.
- Throws: MalformedURLException
- Thrown if a system ID is malformed.
- Throws: IOException
- Thrown if an I/O error occurs.
createMapFromSchema
public Map createMapFromSchema(InputSource src,
int type,
boolean storeOrder,
Parser parser) throws InvalidMapException, SAXException, IOException
- Create a map from an InputSource representing a schema.
Currently, only DDML files are supported.
- Parameters:
- filename - The name of the schema file.
- type - The schema type: SCHEMA_DCD, SCHEMA_DDML, SCHEMA_SOX,
SCHEMA_XMLDATA, SCHEMA_W3C.
- storeOrder - Whether the map should store order information in
the database.
- parser - A SAX Parser to parse the InputSource.
- Returns:
- The Map object.
- Throws: InvalidMapException
- Thrown if a mapping error occurs.
- Throws: SAXException
- Thrown if a SAX error occurs.
- Throws: IOException
- Thrown if an I/O error occurs.
createMap
public Map createMap(DTD dtd,
boolean storeOrder) throws InvalidMapException
- Create a map from a DTD object.
- Parameters:
- dtd - A DTD object from which to create the Map.
- storeOrder - Whether the map should store order information in
the database.
- Returns:
- The Map object.
- Throws: InvalidMapException
- Thrown if a map error occurs.
All Packages Class Hierarchy This Package Previous Next Index