All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.xmlmiddleware.xmldbms.maps.XMLDBMSMap

java.lang.Object
   |
   +----org.xmlmiddleware.xmldbms.maps.MapBase
           |
           +----org.xmlmiddleware.xmldbms.maps.XMLDBMSMap

public class XMLDBMSMap
extends MapBase
Describes how an XML document is mapped to a database and vice versa; for limited use.

For people writing XML-DBMS applications

XMLDBMSMap objects describe how XML documents are mapped to databases and vice versa. You can think of them as compiled versions of map documents, although they can be created from other sources as well, such as a map factory that creates an XMLDBMSMap object from a DTD.

Applications that use XML-DBMS to transfer data treat XMLDBMSMap objects as opaque objects. That is, they call a map factory to create an XMLDBMSMap object, then pass it to a data transfer class such as DOMToDBMS or DBMSToDOM, often without calling any methods on it.

There are a variety of map utilities that can be used to modify or perform operations with maps. Most of these are used by map factories. However, some of them may be used by applications, such as to serialize a map or initialize it with the metadata in a particular database.

For example, the following code creates a map from the sales.map map document.

    // Instantiate a new map factory from a database connection
    // and SAX parser.
    factory = new MapFactory_MapDocument(parser);
// Create an XMLDBMSMap from sales.map. map = factory.createMap(new InputSource(new FileReader("sales.map")));

For people writing map factories and other internal XML-DBMS code

XMLDBMSMap objects are actually a graph of related objects. This graph can be fairly complex and it is a good idea to familiarize yourself with all map objects before trying to use them. (With a lower case m, map object refers to any of the objects in the graph, such as an XMLDBMSMap, a ClassMap, or a ColumnMap.) One way to understand the graph is to look at the private variables in each map class.

The graph of objects contains two views of the mapping, one from the XML point of view (ClassMaps) and one from the database point of view (ClassTableMaps and PropertyTableMaps). This allows the map to be accessed based either on XML metadata (element type and attribute names) or database metadata (table and column names). The MapInverter utility constructs one view from the other.

The following classes are in the XML-centric view of the map:

    ClassMap
    PropertyMap
    RelatedClassMap
    InlineClassMap
 
The following classes are in the database-centric view of the map:

    ClassTableMap
    ColumnMap
    PropertyTableMap
    RelatedClassTableMap
 
The following classes are shared by both views:

    XMLDBMSMap
    Table
    Column
    Key
    LinkInfo
    OrderInfo
 

The inheritance hierarchy of map classes is as follows. This makes clear how how similar the XML-centric and database-centric views of the map are. For example, PropertyMap (XML-centric), ColumnMap (database-centric), and PropertyTableMap (database-centric) all inherit from PropertyMapBase, since all map properties.

    XMLMiddlewareException
    MapBase
       XMLDBMSMap
       ClassMapBase
          ClassMap
          InlineClassMap
       PropertyMapBase
          PropertyMap
          ColumnMap
          PropertyTableMap
       RelatedMapBase
          RelatedClassMap
          RelatedClassTableMap
       ClassTableMap
       Table
       Column
       Key
       LinkInfo
       OrderInfo
 

Expressed as a tree, the graph looks roughly as follows. An ellipsis (...) is used to indicate that the graph continues. In many cases, there are multiple paths to the same object, which is not shown due to the tree representation. For example, the Column in a PropertyMap can also be reached through the Table in the parent ClassMap or the Table in the PropertyMap (if any).

    XMLDBMSMap
       ClassMap (hashtable of)
          Table
             Column (hashtable of)
             Key (hashtables of)
                Column (array of)
          ClassMap... (for used class map, optional)
          ClassMap... (for base class, optional)
          PropertyMap (hashtables of)
             Table... (optional)
             Column
             LinkInfo (optional)
                Key...
                Key...
             OrderInfo (optional)
                Column (optional)
          RelatedClassMap (hashtable of)
             ClassMap...
             LinkInfo...
             OrderInfo... (optional)
          InlineClassMap (hashtable of)
             PropertyMap... (hashtable of)
             RelatedClassMap... (hashtable of)
             InlineClassMap... (hashtable of)
             OrderInfo... (optional)
       ClassTableMap (hashtable of)
          Table...
          Table... (for base class, optional)
          ColumnMap (hashtable of)
             Column
             OrderInfo... (optional)
          PropertyTableMap (hashtable of)
             Table...
             Column...
             LinkInfo...
             OrderInfo... (optional)
          RelatedClassTableMap (vector of)
             ClassTableMap...
             LinkInfo...
             OrderInfo... (optional)
          ElementInsertionMap...
             ColumnMap...
             PropertyTableMap...
             RelatedClassTableMap...
             ElementInsertionMap...
             OrderInfo... (optional)
 

Methods for Creating Map Objects

Map objects are created by factory methods. These occur in all map objects except XMLDBMSMap, which has a simple constructor. For example, the following code creates a LinkInfo object.

    LinkInfo linkInfo = LinkInfo.create(parentKey, childKey);
 

In many cases, factory methods can also be found on the parent object. For example, the following code creates a ClassMap object from an XMLDBMSMap object:

    classMap = map.createClassMap(null, "foo");
 

When the factory method is called on the parent, the child object is automatically added to the parent object. Furthermore, if a child object with the same name already exists, that object will be returned instead of creating a new object. Since objects are frequently used in multiple places -- for example, the same ClassMap can appear in an XMLDBMSMap and a RelatedClassMap -- this is useful, as the alternative would be to first check if the object exists, then create it if it doesn't. For example, the following code is equivalent to calling createClassMap on an XMLDBMSMap object:

    classMap = map.getClassMap(null, "foo");
    if (classMap == null)
    {
       classMap = ClassMap.create(null, "foo");
       map.addClassMap(classMap);
    }
 

The primary difference between creating an object on its parent and adding it to its parent is that an exception is thrown when attempting to add an object that already exists on the parent. This is useful when a map factory wants to make sure that the same object is not mapped or created twice. For example, the following code throws an error if the table already has a column named "bar":

   column = Column.create("bar");
   table.addColumn(column);
 

Map Object Properties

Properties in maps fall into three categories:

Methods for Manipulating Map Object Properties

Fundamental properties are set when the map object is created. They cannot be modified, but can be retrieved with a getXxxx method. For example:

    column = Column.create("foo");
    columnName = column.getName();
 

Objects in collection properties are manipulated with methods similar to the following:

    getXxxx(String name)    // Returns an object with the specified name. Returns null if
                            // the value does not exist. Used by map utilities and data
                            // transfer classes.
    getXxxxs()              // Returns an Enumeration or Hashtable over all objects of a
                            // given type. Used by map utilities and data transfer classes.
    createXxxx(Xxxx xxx)    // Returns a single object with the specified name. The method
                            // first attempts to retrieve an existing object and, if one
                            // doesn't exist, creates a new one. Used only by map factories.
    addXxxx(Xxxx xxxx)      // Adds a new object to the collection. Throws an error if
                            // the value already exists. Used only by map factories.
    removeXxxx(String name) // Removes an object with the specified name. Throws an error
                            // if the value does not exist. Used only by map factories.
    removeAllXxxxs()        // Removes all objects of a given type. Used by map factories.
 

Single-valued properties are manipulated with methods similar to the following:

    getXxxx()               // Returns the object value. Used by map factories and data
                            // transfer classes.
    setXxxx(new value)      // Sets the object value, overriding the old value. In many cases,
                            // the argument can be null, which removes the property value.
                            // Used only by map factories.
 

Note that all getXxxx methods are optimized to the extent possible. This is done to minimize the time it takes to retrieve map information when transferring data and usually means that the method is declared final and simply returns the value of a class variable. This (hopefully) allows the method to be inlined by a clever Java compiler. It also means that no error is returned when it is inappropriate to call the method. This occurs when the state is invalid, such as during map construction, or when the state is valid but technically does not allow the method to be called, such as when OrderInfo.getFixedOrderValue() is called but an order column is used. In such cases, the returned value is not guaranteed to be correct.

Map Object State

Some collection properties and some single-valued properties are required to have values; others are not. Because map factories frequently need an object before they have enough information to completely construct it -- for example, a RelatedClassMap might be constructed before the ClassMap it points to is fully constructed -- map objects can have invalid state.

This is legal during map construction, but causes undefined behavior when the map is used to transfer data. That is, the data transfer classes such as DBMSToDOM and DOMToDBMS assume that the map objects are valid.

Because of this, map factories must ensure that a map has valid state before they return it. (The only exception to this rule is database metadata. A map factory can return an XMLDBMSMap that has not been initialized with database metadata and allow the application to do this. In this case, it is the application's responsibility to ensure the map is in a valid state.)

Map factories can check whether a map has valid state by calling MapChecker.check(XMLDBMSMap). Whether this is necessary depends on the map factory. Some map factories keep track of map state themselves, others call MapChecker to check for them.

Version:
2.0
Author:
Ronald Bourret, 1998-1999, 2001

Constructor Index

 o XMLDBMSMap()
Construct a new XMLDBMSMap.

Method Index

 o addClassMap(ClassMap)
Add a ClassMap for an element type.
 o addClassTableMap(ClassTableMap)
Add a ClassTableMap for a table.
 o addNamedFormatter(String, StringFormatter)
Add a named formatting object.
 o addNamespace(String, String)
Add a namespace prefix and URI.
 o addTable(Table)
Add a Table.
 o checkMetadata()
Checks whether metadata has been set for the columns in all tables.
 o createClassMap(String, String)
Create a ClassMap for an element type and add it to the XMLDBMSMap.
 o createClassMap(XMLName)
Create a ClassMap for an element type and add it to the XMLDBMSMap.
 o createClassTableMap(Table)
Create a ClassTableMap for a table and add it to the XMLDBMSMap.
 o createTable(String, String, String, String)
Create a Table and add it to the XMLDBMSMap.
 o emptyStringIsNull()
Are empty strings treated as NULLs?
 o getClassMap(String)
Gets the ClassMap used by an element type.
 o getClassMap(String, String)
Gets the ClassMap used by an element type.
 o getClassMaps()
Gets an Enumeration of all class maps.
 o getClassTableMap(String, String, String, String)
Gets a ClassTableMap for a table.
 o getClassTableMap(Table)
Gets a ClassTableMap for a table.
 o getClassTableMaps()
Gets an Enumeration of all class table maps.
 o getDefaultFormatter(int)
Get the default formatting object for a type.
 o getDefaultFormatters()
Get a Hashtable containing the default formatting objects hashed by JDBC type.
 o getNamedFormatter(String)
Get a named formatting object.
 o getNamedFormatters()
Get a Hashtable containing all named formatting objects hashed by name.
 o getNamespacePrefix(String)
Get a namespace prefix.
 o getNamespacePrefixes()
Get a Hashtable containing all namespace prefixes hashed by URI.
 o getNamespaceURI(String)
Get a namespace URI.
 o getNamespaceURIs()
Get a Hashtable containing all namespace URIs hashed by prefix.
 o getTable(String, String, String, String)
Gets a Table.
 o getTables()
Gets an Enumeration of all Tables.
 o removeAllClassMaps()
Remove the ClassMaps for all element types.
 o removeAllClassTableMaps()
Remove the ClassTablesMaps for all tables.
 o removeAllNamedFormatters()
Remove all named formatting objects.
 o removeAllTables()
Remove all Tables.
 o removeClassMap(String)
Remove the ClassMap for an element type.
 o removeClassMap(String, String)
Remove the ClassMap for an element type.
 o removeClassTableMap(String, String, String, String)
Remove the ClassTableMap for a table.
 o removeClassTableMap(Table)
Remove the ClassTableMap for a table.
 o removeNamedFormatter(String, StringFormatter)
Remove a named formatting object.
 o removeNamespaceByPrefix(String)
Remove a namespace prefix and URI.
 o removeNamespaceByURI(String)
Remove a namespace prefix and URI.
 o removeNamespaces()
Remove all namespace URIs.
 o removeTable(String, String, String, String)
Remove a Table.
 o removeTable(Table)
Remove a Table.
 o resetDefaultFormatters()
Reset the default formatting objects to their initial state.
 o setDefaultFormatter(int, StringFormatter)
Set the default formatting object for a type.
 o setEmptyStringIsNull(boolean)
Set whether empty strings are treated as NULLs.

Constructors

 o XMLDBMSMap
 public XMLDBMSMap()
Construct a new XMLDBMSMap.

Methods

 o emptyStringIsNull
 public final boolean emptyStringIsNull()
Are empty strings treated as NULLs?

Returns:
Whether empty strings are treated as NULLs.
 o setEmptyStringIsNull
 public void setEmptyStringIsNull(boolean flag)
Set whether empty strings are treated as NULLs.

Parameters:
flag - Whether empty strings are treated as NULLs.
 o getDefaultFormatter
 public final StringFormatter getDefaultFormatter(int type)
Get the default formatting object for a type.

This method returns an object that implements the org.xmlmiddleware.conversions.formatters.StringFormatter interface.

Parameters:
type - The JDBC type. Must be a valid value from the java.sql.Types class.
Returns:
The formatting object. This is never null.
 o getDefaultFormatters
 public final Hashtable getDefaultFormatters()
Get a Hashtable containing the default formatting objects hashed by JDBC type.

Returns:
The Hashtable.
 o setDefaultFormatter
 public void setDefaultFormatter(int type,
                                 StringFormatter formatter)
Set the default formatting object for a type.

The format object must be an object that implements the org.xmlmiddleware.conversions.formatters.StringFormatter interface.

Parameters:
type - The JDBC type.
formatter - The formatting object. Must not be null.
 o resetDefaultFormatters
 public void resetDefaultFormatters()
Reset the default formatting objects to their initial state.

 o getNamedFormatter
 public final StringFormatter getNamedFormatter(String name)
Get a named formatting object.

Parameters:
name - The name of the the formatting object. Must not be null.
Returns:
The formatting object. May be null.
 o getNamedFormatters
 public final Hashtable getNamedFormatters()
Get a Hashtable containing all named formatting objects hashed by name.

Returns:
The Hashtable.
 o addNamedFormatter
 public void addNamedFormatter(String name,
                               StringFormatter formatter) throws XMLMiddlewareException
Add a named formatting object.

Parameters:
name - The name. Must not be null.
formatter - The formatting object. Must not be null.
 o removeNamedFormatter
 public void removeNamedFormatter(String name,
                                  StringFormatter formatter) throws XMLMiddlewareException
Remove a named formatting object.

Parameters:
name - The name. Must not be null.
 o removeAllNamedFormatters
 public void removeAllNamedFormatters()
Remove all named formatting objects.

 o getNamespaceURI
 public final String getNamespaceURI(String prefix)
Get a namespace URI.

Parameters:
prefix - The namespace prefix.
Returns:
The namespace URI. Null if the prefix is not used.
 o getNamespacePrefix
 public final String getNamespacePrefix(String uri)
Get a namespace prefix.

Parameters:
uri - The namespace URI.
Returns:
The namespace prefix. Null if the URI is not used.
 o getNamespaceURIs
 public final Hashtable getNamespaceURIs()
Get a Hashtable containing all namespace URIs hashed by prefix.

Returns:
The Hashtable. May be empty.
 o getNamespacePrefixes
 public final Hashtable getNamespacePrefixes()
Get a Hashtable containing all namespace prefixes hashed by URI.

Returns:
The Hashtable. May be empty.
 o addNamespace
 public void addNamespace(String prefix,
                          String uri) throws XMLMiddlewareException
Add a namespace prefix and URI.

Parameters:
prefix - The namespace prefix.
uri - The namespace URI.
Throws: XMLMiddlewareException
Thrown if the prefix or URI is already used.
 o removeNamespaceByPrefix
 public void removeNamespaceByPrefix(String prefix) throws XMLMiddlewareException
Remove a namespace prefix and URI.

Parameters:
prefix - The namespace prefix.
Throws: XMLMiddlewareException
Thrown if the prefix is not found.
 o removeNamespaceByURI
 public void removeNamespaceByURI(String uri) throws XMLMiddlewareException
Remove a namespace prefix and URI.

Parameters:
prefix - The namespace prefix.
Throws: XMLMiddlewareException
Thrown if the prefix is not found.
 o removeNamespaces
 public void removeNamespaces()
Remove all namespace URIs.

 o getClassMap
 public final ClassMap getClassMap(String uri,
                                   String localName)
Gets the ClassMap used by an element type.

If the ClassMap for the element type uses another ClassMap (which might use yet another ClassMap, and so on), this method returns the last ClassMap in the chain. This is the ClassMap actually used to transfer data.

Parameters:
uri - Namespace URI of the element type. May be null.
localName - Local name of the element type.
Returns:
The ClassMap. Null if the element type is not mapped.
 o getClassMap
 public final ClassMap getClassMap(String universalName)
Gets the ClassMap used by an element type.

If the ClassMap for the element type uses another ClassMap (which might use yet another ClassMap, and so on), this method returns the last ClassMap in the chain. This is the ClassMap actually used to transfer data.

Parameters:
universalName - Universal name of the element type.
Returns:
The ClassMap. Null if the element type is not mapped.
 o getClassMaps
 public final Enumeration getClassMaps()
Gets an Enumeration of all class maps.

Returns:
The Enumeration. May be empty.
 o createClassMap
 public ClassMap createClassMap(String uri,
                                String localName)
Create a ClassMap for an element type and add it to the XMLDBMSMap.

If the element type has already been mapped, returns the existing ClassMap.

Parameters:
uri - Namespace URI of the element type. May be null.
localName - Local name of the element type.
Returns:
The ClassMap for the element type.
 o createClassMap
 public ClassMap createClassMap(XMLName elementTypeName)
Create a ClassMap for an element type and add it to the XMLDBMSMap.

If the element type has already been mapped, returns the existing ClassMap.

Parameters:
elementTypeName - The element type name.
Returns:
The ClassMap for the element type.
 o addClassMap
 public void addClassMap(ClassMap classMap) throws XMLMiddlewareException
Add a ClassMap for an element type.

Parameters:
classMap - ClassMap for the element type.
Throws: XMLMiddlewareException
Thrown if the element type has already been mapped.
 o removeClassMap
 public void removeClassMap(String uri,
                            String localName) throws XMLMiddlewareException
Remove the ClassMap for an element type.

Parameters:
uri - Namespace URI of the element type. May be null.
localName - Local name of the element type.
Throws: XMLMiddlewareException
Thrown if the element type has not been mapped.
 o removeClassMap
 public void removeClassMap(String universalName) throws XMLMiddlewareException
Remove the ClassMap for an element type.

Parameters:
universalName - Universal name of the element type.
Throws: XMLMiddlewareException
Thrown if the element type has not been mapped.
 o removeAllClassMaps
 public void removeAllClassMaps()
Remove the ClassMaps for all element types.

 o getClassTableMap
 public final ClassTableMap getClassTableMap(String databaseName,
                                             String catalogName,
                                             String schemaName,
                                             String tableName)
Gets a ClassTableMap for a table.

Parameters:
databaseName - Name of the database. May be null.
catalogName - Name of the catalog. May be null.
schemaName - Name of the schema. May be null.
tableName - Name of the table.
Returns:
The ClassTableMap. Null if the table is not mapped as a class table.
 o getClassTableMap
 public final ClassTableMap getClassTableMap(Table table)
Gets a ClassTableMap for a table.

Parameters:
table - The Table
Returns:
The ClassTableMap. Null if the table is not mapped as a class table.
 o getClassTableMaps
 public final Enumeration getClassTableMaps()
Gets an Enumeration of all class table maps.

Returns:
The Enumeration. May be empty.
 o createClassTableMap
 public ClassTableMap createClassTableMap(Table table)
Create a ClassTableMap for a table and add it to the XMLDBMSMap.

If the table has already been mapped as a class table, returns the existing ClassTableMap.

Parameters:
table - The Table being mapped.
Returns:
The ClassTableMap for the table.
 o addClassTableMap
 public void addClassTableMap(ClassTableMap classTableMap) throws XMLMiddlewareException
Add a ClassTableMap for a table.

Parameters:
classTableMap - ClassTableMap for the table. Must not be null.
Throws: XMLMiddlewareException
Thrown if the table has already been mapped.
 o removeClassTableMap
 public void removeClassTableMap(String databaseName,
                                 String catalogName,
                                 String schemaName,
                                 String tableName) throws XMLMiddlewareException
Remove the ClassTableMap for a table.

Parameters:
databaseName - Name of the database. May be null.
catalogName - Name of the catalog. May be null.
schemaName - Name of the schema. May be null.
tableName - Name of the table.
Throws: XMLMiddlewareException
Thrown if the table has not been mapped as a class table.
 o removeClassTableMap
 public void removeClassTableMap(Table table) throws XMLMiddlewareException
Remove the ClassTableMap for a table.

Parameters:
table - The Table
Throws: XMLMiddlewareException
Thrown if the table has not been mapped as a class table.
 o removeAllClassTableMaps
 public void removeAllClassTableMaps()
Remove the ClassTablesMaps for all tables.

 o getTable
 public final Table getTable(String databaseName,
                             String catalogName,
                             String schemaName,
                             String tableName)
Gets a Table.

Parameters:
databaseName - Name of the database. May be null.
catalogName - Name of the catalog. May be null.
schemaName - Name of the schema. May be null.
tableName - Name of the table.
Returns:
The Table. Null if the table does not exist.
 o getTables
 public final Enumeration getTables()
Gets an Enumeration of all Tables.

Returns:
The Enumeration. May be empty.
 o createTable
 public Table createTable(String databaseName,
                          String catalogName,
                          String schemaName,
                          String tableName)
Create a Table and add it to the XMLDBMSMap.

If the table exists, returns the existing Table.

Parameters:
databaseName - Name of the database. May be null.
catalogName - Name of the catalog. May be null.
schemaName - Name of the schema. May be null.
tableName - Name of the table.
Returns:
The Table.
 o addTable
 public void addTable(Table table) throws XMLMiddlewareException
Add a Table.

Parameters:
table - The Table.
Throws: XMLMiddlewareException
Thrown if the table already exists.
 o removeTable
 public void removeTable(String databaseName,
                         String catalogName,
                         String schemaName,
                         String tableName) throws XMLMiddlewareException
Remove a Table.

This method should be used carefully, as numerous other map objects point to Tables. Those objects should be deleted before this method is called.

Parameters:
databaseName - Name of the database. May be null.
catalogName - Name of the catalog. May be null.
schemaName - Name of the schema. May be null.
tableName - Name of the table.
Throws: XMLMiddlewareException
Thrown if the table does not exist.
 o removeTable
 public void removeTable(Table table) throws XMLMiddlewareException
Remove a Table.

This method should be used carefully, as numerous other map objects point to Tables. Those objects should be deleted before this method is called.

Parameters:
table - The Table
Throws: XMLMiddlewareException
Thrown if the table does not exist.
 o removeAllTables
 public void removeAllTables()
Remove all Tables.

This method should be used carefully, as numerous other map objects point to Tables. Those objects should be deleted before this method is called.

 o checkMetadata
 public Table checkMetadata()
Checks whether metadata has been set for the columns in all tables.

If the returned value is non-null, it can be used to determine the column for which metadata has not been set.

Returns:
The first Table for which metadata has not been set or null if metadata has been set for all tables.

All Packages  Class Hierarchy  This Package  Previous  Next  Index